diff options
| author | Joseph Caburnay <jcb@odoo.com> | 2020-06-15 09:59:37 +0000 |
|---|---|---|
| committer | Joseph Caburnay <jcb@odoo.com> | 2020-07-17 10:00:04 +0000 |
| commit | b2f8170d88239b5eaf04f1e3c0dcef613b78fedc (patch) | |
| tree | ae1a178dab9afd382cd9e45e8db5b28d6a6424e5 /addons/point_of_sale/static/src/js/models.js | |
| parent | 39ff9d95c2c2b09e7d6ec47051ca0bb3c9f6165a (diff) | |
[IMP] point_of_sale,pos_*: allow users to manage orders in the pos frontend
We now allow invoicing of finalized orders in an open session in this first
iteration of order management in the pos frontend. Additionally, receipt
reprinting is also introduced. With this feature, we can now reprint the
receipt of old orders.
closes odoo/odoo#51141
Task-id: 1981354
Related: odoo/enterprise#11690
Related: odoo/upgrade#1472
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Diffstat (limited to 'addons/point_of_sale/static/src/js/models.js')
| -rw-r--r-- | addons/point_of_sale/static/src/js/models.js | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 8f6e419f557..9875d3030ab 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -2312,10 +2312,12 @@ exports.Paymentline = Backbone.Model.extend({ init_from_JSON: function(json){ this.amount = json.amount; this.payment_method = this.pos.payment_methods_by_id[json.payment_method_id]; + this.name = this.payment_method.name; this.payment_status = json.payment_status; this.ticket = json.ticket; this.card_type = json.card_type; this.transaction_id = json.transaction_id; + this.is_change = json.is_change; }, //sets the amount of money on this payment line set_amount: function(value){ @@ -2391,7 +2393,8 @@ exports.Paymentline = Backbone.Model.extend({ return { cid: this.cid, amount: this.get_amount(), - payment_method: this.payment_method.name, + name: this.name, + ticket: this.ticket, }; }, }); @@ -2410,7 +2413,7 @@ exports.Order = Backbone.Model.extend({ var self = this; options = options || {}; - this.init_locked = true; + this.locked = false; this.pos = options.pos; this.selected_orderline = undefined; this.selected_paymentline = undefined; @@ -2453,13 +2456,12 @@ exports.Order = Backbone.Model.extend({ this.paymentlines.on('remove', this.pos.send_current_order_to_customer_facing_display, this.pos); } - this.init_locked = false; this.save_to_db(); return this; }, save_to_db: function(){ - if (!this.temporary && !this.init_locked) { + if (!this.temporary && !this.locked) { this.pos.db.save_unpaid_order(this); } }, @@ -2536,6 +2538,14 @@ exports.Order = Backbone.Model.extend({ this.select_paymentline(newpaymentline); } } + + // Tag this order as 'locked' if it is already paid. + this.locked = ['paid', 'done', 'invoiced'].includes(json.state); + this.state = json.state; + this.amount_return = json.amount_return; + this.account_move = json.account_move; + this.backendId = json.id; + this.isFromClosedSession = json.is_session_closed; }, export_as_JSON: function() { var orderLines, paymentLines; @@ -2552,7 +2562,7 @@ exports.Order = Backbone.Model.extend({ amount_paid: this.get_total_paid() - this.get_change(), amount_total: this.get_total_with_tax(), amount_tax: this.get_total_tax(), - amount_return: this.get_change(), + amount_return: this.amount_return ? this.amount_return : this.get_change(), lines: orderLines, statement_ids: paymentLines, pos_session_id: this.pos_session_id, @@ -2580,10 +2590,16 @@ exports.Order = Backbone.Model.extend({ orderlines.push(orderline.export_for_printing()); }); - var paymentlines = []; - this.paymentlines.each(function(paymentline){ - paymentlines.push(paymentline.export_for_printing()); - }); + // If order is locked (paid), the 'change' is saved as negative payment, + // and is flagged with is_change = true. A receipt that is printed first + // time doesn't show this negative payment so we filter it out. + var paymentlines = this.paymentlines.models + .filter(function (paymentline) { + return !paymentline.is_change; + }) + .map(function (paymentline) { + return paymentline.export_for_printing(); + }); var client = this.get('client'); var cashier = this.pos.get_cashier(); var company = this.pos.company; @@ -2619,7 +2635,7 @@ exports.Order = Backbone.Model.extend({ total_discount: this.get_total_discount(), rounding_applied: this.get_rounding_applied(), tax_details: this.get_tax_details(), - change: this.get_change(), + change: this.locked ? this.amount_return : this.get_change(), name : this.get_name(), client: client ? client : null , invoice_id: null, //TODO |
