From fb853753880d378b49756be6faae14afdc56a712 Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Mon, 4 Nov 2019 10:15:52 +0000 Subject: [PATCH] [FIX] point_of_sale: uninvoiced orders' state not set to 'done' Prior to this commit: b234e97f87c577a7cd85230c4f42277b39e8c842, uninvoiced orders' state is set to 'done' when the session is validated. However, this was not taken into consideration in the said commit such that even if the session is already validated, the uninvoiced orders' state remains 'paid'. Setting the orders state to 'done' is the correct behavior and is implemented in this commit. closes odoo/odoo#39735 X-original-commit: bb490301c22c84c86d2b1c2d27ecb96a4ff19ac5 Signed-off-by: pimodoo --- addons/point_of_sale/models/pos_session.py | 2 ++ .../point_of_sale/tests/test_pos_basic_config.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 6820ba3b679..2d802f45ffb 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -286,6 +286,8 @@ class PosSession(models.Model): self._create_account_move() if self.move_id.line_ids: self.move_id.post() + # Set the uninvoiced orders' state to 'done' + self.env['pos.order'].search([('session_id', '=', self.id), ('state', '=', 'paid')]).write({'state': 'done'}) else: # The cash register needs to be confirmed for cash diffs # made thru cash in/out when sesion is in cash_control. diff --git a/addons/point_of_sale/tests/test_pos_basic_config.py b/addons/point_of_sale/tests/test_pos_basic_config.py index bf34c1d25fb..7a55dde680c 100644 --- a/addons/point_of_sale/tests/test_pos_basic_config.py +++ b/addons/point_of_sale/tests/test_pos_basic_config.py @@ -228,9 +228,23 @@ class TestPoSBasicConfig(TestPoSCommon): self.assertAlmostEqual(invoice.amount_total, 130, msg='Amount total should be 130. Product is untaxed.') invoice_receivable_line = invoice.line_ids.filtered(lambda line: line.account_id == self.receivable_account) + # check state of orders before validating the session. + self.assertEqual('invoiced', invoiced_order.state, msg="state should be 'invoiced' for invoiced orders.") + uninvoiced_orders = self.pos_session.order_ids - invoiced_order + self.assertTrue( + all([order.state == 'paid' for order in uninvoiced_orders]), + msg="state should be 'paid' for uninvoiced orders before validating the session." + ) + # close the session self.pos_session.action_pos_session_validate() + # check state of orders after validating the session. + self.assertTrue( + all([order.state == 'done' for order in uninvoiced_orders]), + msg="State should be 'done' for uninvoiced orders after validating the session." + ) + # check values after the session is closed session_move = self.pos_session.move_id