Skip to content

Commit 4eedd51

Browse files
committed
[FIX] account: partner inconsistencies on invoices
How to reproduce: Have 2 different tabs open on the same draft invoice Tab 1: add a new invoice line Tab 2: change the partner Tab 1: save Tab 2: save Before the fix: The new invoice line from tab 1 has the partner from before the change, but the other lines have been updated to the new partner. Expected: All invoice lines have the same partner as the invoice itself This use case can be reproduced like this manually, but it can happen easily even on one tab because the OCR acts like the second tab if users start to edit the invoice before it is scanned. Note that in a perfect world, a warning would be raised to prevent any loss/mischief due to concurrent editions of the same record but that's beyond the scope of a bugfix made on a stable version. backport of odoo@2c5450a opw-2855816 closes odoo#93566 X-original-commit: 723ee4b Signed-off-by: William André (wan) <[email protected]>
1 parent 3e8259b commit 4eedd51

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

addons/account/models/account_move.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2659,6 +2659,14 @@ def _post(self, soft=True):
26592659
move.date = move._get_accounting_date(move.invoice_date or move.date, True)
26602660
move.with_context(check_move_validity=False)._onchange_currency()
26612661

2662+
2663+
for move in to_post:
2664+
# Fix inconsistencies that may occure if the OCR has been editing the invoice at the same time of a user. We force the
2665+
# partner on the lines to be the same as the one on the move, because that's the only one the user can see/edit.
2666+
wrong_lines = move.is_invoice() and move.line_ids.filtered(lambda aml: aml.partner_id != move.commercial_partner_id and not aml.display_type)
2667+
if wrong_lines:
2668+
wrong_lines.partner_id = move.commercial_partner_id.id
2669+
26622670
# Create the analytic lines in batch is faster as it leads to less cache invalidation.
26632671
to_post.mapped('line_ids').create_analytic_lines()
26642672
to_post.write({

0 commit comments

Comments
 (0)