From 3bd787a4bbedd0bb8e1f0c6dcce24bef3b5b6690 Mon Sep 17 00:00:00 2001 From: Ahmad Khanalizadeh Date: Tue, 28 Feb 2023 10:09:42 +0000 Subject: [PATCH] [FIX] point_of_sale: prevent adding extra rounding line Steps to reproduce: 1. Make a cash rounding method, make it specific to cash 2. Add a product line with non-rounded price 3. Enable invoice, and add a customer 4. Make a payment with a combination of cash and bank 5. Validate, an error appears that "the move is not balanced". The issue is there is a rounding line added, that should be removed. However, here `unlink` and `write` methods, trigger a dynamic sync operation that re-generates the rounding line, making the move unbalanced. To fix the issue, we can prevent the sync operation, so that no extra rounding lines are added. opw-3180708 closes odoo/odoo#114020 X-original-commit: 3bd28525d9486e2f33b8d338c39675125fa22d7a Signed-off-by: Heinz Robin (rhe) Signed-off-by: Khanalizadeh Ahmad (khah) --- addons/point_of_sale/models/pos_order.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index aa1a7323290..cafc05df673 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -543,7 +543,7 @@ class PosOrder(models.Model): }) else: if rounding_line: - rounding_line.with_context(check_move_validity=False).unlink() + rounding_line.with_context(skip_invoice_sync=True, check_move_validity=False).unlink() if rounding_line_difference: existing_terms_line = new_move.line_ids.filtered( lambda line: line.account_id.account_type in ('asset_receivable', 'liability_payable')) @@ -555,12 +555,10 @@ class PosOrder(models.Model): existing_terms_line_new_val = float_round( -existing_terms_line.credit + rounding_line_difference, precision_rounding=new_move.currency_id.rounding) - existing_terms_line.write({ + existing_terms_line.with_context(skip_invoice_sync=True).write({ 'debit': existing_terms_line_new_val > 0.0 and existing_terms_line_new_val or 0.0, 'credit': existing_terms_line_new_val < 0.0 and -existing_terms_line_new_val or 0.0, }) - - new_move._recompute_payment_terms_lines() return new_move def action_pos_order_paid(self):