From dc62f077830210ce8971f18781bac18a50cbc6d8 Mon Sep 17 00:00:00 2001 From: "Andrea Grazioso (agr-odoo)" Date: Fri, 28 May 2021 11:22:30 +0000 Subject: [PATCH] [FIX] point_of_sale: perform stock operation only when necessary Fine tuning of https://github.com/odoo/odoo/commit/bdd36f7ce68999576dfc30298f4ddf2572b4c7ec to perform the assignment and related operation only when 'consignment' is enabled opw-2508371 closes odoo/odoo#71800 X-original-commit: 441ff95adf218534fb7f32aa16eac18023352d0f Signed-off-by: Nicolas Lempereur (nle) Signed-off-by: agr-odoo --- addons/point_of_sale/models/stock_picking.py | 17 +++++++++-------- .../tests/test_pos_stock_account.py | 3 +++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/addons/point_of_sale/models/stock_picking.py b/addons/point_of_sale/models/stock_picking.py index e6cbc095e0c..52e74f5bbd2 100644 --- a/addons/point_of_sale/models/stock_picking.py +++ b/addons/point_of_sale/models/stock_picking.py @@ -149,14 +149,15 @@ class StockPicking(models.Model): self.env['stock.move.line'].create(ml_vals) else: - move._action_assign() - for move_line in move.move_line_ids: - move_line.qty_done = move_line.product_uom_qty - if float_compare(move.product_uom_qty, move.quantity_done, precision_rounding=move.product_uom.rounding) > 0: - remaining_qty = move.product_uom_qty - move.quantity_done - ml_vals = move._prepare_move_line_vals() - ml_vals.update({'qty_done':remaining_qty}) - self.env['stock.move.line'].create(ml_vals) + if self.user_has_groups('stock.group_tracking_owner'): + move._action_assign() + for move_line in move.move_line_ids: + move_line.qty_done = move_line.product_uom_qty + if float_compare(move.product_uom_qty, move.quantity_done, precision_rounding=move.product_uom.rounding) > 0: + remaining_qty = move.product_uom_qty - move.quantity_done + ml_vals = move._prepare_move_line_vals() + ml_vals.update({'qty_done':remaining_qty}) + self.env['stock.move.line'].create(ml_vals) move.quantity_done = move.product_uom_qty def _send_confirmation_email(self): diff --git a/addons/point_of_sale/tests/test_pos_stock_account.py b/addons/point_of_sale/tests/test_pos_stock_account.py index c614e07df7a..8a73cf1aaa6 100644 --- a/addons/point_of_sale/tests/test_pos_stock_account.py +++ b/addons/point_of_sale/tests/test_pos_stock_account.py @@ -206,6 +206,9 @@ class TestPoSStock(TestPoSCommon): """ Test order via POS a product having stock owner. """ + + group_owner = self.env.ref('stock.group_tracking_owner') + self.env.user.write({'groups_id': [(4, group_owner.id)]}) self.product4 = self.create_product('Product 3', self.categ_basic, 30.0, 15.0) self.env['stock.quant'].with_context(inventory_mode=True).create({ 'product_id': self.product4.id,