From b37726aaf1303791661f9044c2a883b046718d19 Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Wed, 6 Nov 2019 10:05:12 +0000 Subject: [PATCH] [FIX] point_of_sale: pos order to invoice wrong value When a pos order is sent to the server, the field 'to_invoice' is never sent to the server which lead to always having a value to 'false'. We are now sending correctly this value to the server, and we can also base the fact to create an invoice on the value of each order. Because beeing offline could lead to create an order that should be invoiced as one that should not be. closes odoo/odoo#39880 X-original-commit: c8d5b4a0cfc070c05c3f86ae6cc2b7395532c353 Signed-off-by: pimodoo --- addons/point_of_sale/models/pos_order.py | 3 +-- addons/point_of_sale/static/src/js/models.js | 1 + addons/point_of_sale/tests/common.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index ce1e0af6db6..d3ba047c643 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -112,7 +112,6 @@ class PosOrder(models.Model): :type existing_order: pos.order. :returns number pos_order id """ - to_invoice = order['to_invoice'] if not draft else False order = order['data'] pos_session = self.env['pos.session'].browse(order['pos_session_id']) if pos_session.state == 'closing_control' or pos_session.state == 'closed': @@ -138,7 +137,7 @@ class PosOrder(models.Model): except Exception as e: _logger.error('Could not fully process the POS Order: %s', tools.ustr(e)) - if to_invoice: + if pos_order.to_invoice and pos_order.state == 'paid': pos_order.action_pos_order_invoice() pos_order.account_move.sudo().with_context(force_company=self.env.user.company_id.id).post() diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index b768633f296..ed9c92b1f3c 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -2402,6 +2402,7 @@ exports.Order = Backbone.Model.extend({ creation_date: this.validation_date || this.creation_date, // todo: rename creation_date in master fiscal_position_id: this.fiscal_position ? this.fiscal_position.id : false, server_id: this.server_id ? this.server_id : false, + to_invoice: this.to_invoice ? this.to_invoice : false, }; if (!this.is_paid && this.user_id) { json.user_id = this.user_id; diff --git a/addons/point_of_sale/tests/common.py b/addons/point_of_sale/tests/common.py index 98e5eda1125..38e4de65f6c 100644 --- a/addons/point_of_sale/tests/common.py +++ b/addons/point_of_sale/tests/common.py @@ -389,6 +389,7 @@ class TestPoSCommon(TransactionCase): 'statement_ids': payments, 'uid': uid, 'user_id': self.pos_manager.id, + 'to_invoice': is_invoiced, }, 'id': uid, 'to_invoice': is_invoiced,