[FIX] account: aml's partner_id modified after the move has been posted when using the hash

Steps to reproduce:
1. Activate the hash mode on a journal
2. Create an account move
3. Choose a customer who is not a commercial partner (e.g. Brandon Freeman from Azure Interior)
4. Post the move
5. Error saying that we cannot modify the `partner_id` because the move has already been posted

This is because currently we first post the move and then we modify the `partner_id` of the lines whose `partner_id` is different from the account's `commercial_partner_id`. We can easily fix this by posting the move after the lines'`partner_id` have been modified.

closes odoo/odoo#108177

X-original-commit: 1036134a2f0d921fd6a659b4951e5fa63975b78d
Signed-off-by: William André (wan) <wan@odoo.com>
Signed-off-by: Ricardo Gomes Rodrigues (rigr) <rigr@odoo.com>
This commit is contained in:
Ricardo Gomes Rodrigues (rigr)
2022-12-16 17:20:03 +01:00
parent 9ed8db4f6e
commit 987ffe4f69
+6 -4
View File
@@ -3278,10 +3278,6 @@ class AccountMove(models.Model):
# Create the analytic lines in batch is faster as it leads to less cache invalidation.
to_post.line_ids._create_analytic_lines()
to_post.write({
'state': 'posted',
'posted_before': True,
})
# Trigger copying for recurring invoices
to_post.filtered(lambda m: m.auto_post not in ('no', 'at_date'))._copy_recurring_entries()
@@ -3296,6 +3292,12 @@ class AccountMove(models.Model):
if wrong_lines:
wrong_lines.write({'partner_id': invoice.commercial_partner_id.id})
to_post.write({
'state': 'posted',
'posted_before': True,
})
for invoice in to_post:
invoice.message_subscribe([
p.id
for p in [invoice.partner_id]