Skip to content

Commit 723ee4b

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#92623 Signed-off-by: William André (wan) <[email protected]>
1 parent 2743d8f commit 723ee4b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

addons/account/models/account_move.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,6 +2353,12 @@ def post(self):
23532353
if move.auto_post and move.date > fields.Date.today():
23542354
raise UserError(_("This move is configured to be auto-posted on {}".format(move.date.strftime(get_lang(self.env).date_format))))
23552355

2356+
# Fix inconsistencies that may occure if the OCR has been editing the invoice at the same time of a user. We force the
2357+
# 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.
2358+
wrong_lines = move.is_invoice() and move.line_ids.filtered(lambda aml: aml.partner_id != move.commercial_partner_id and not aml.display_type)
2359+
if wrong_lines:
2360+
wrong_lines.partner_id = move.commercial_partner_id.id
2361+
23562362
move.message_subscribe([p.id for p in [move.partner_id] if p not in move.sudo().message_partner_ids])
23572363

23582364
to_write = {'state': 'posted'}

0 commit comments

Comments
 (0)