[FIX] account: keep receivable account on duplicate invoice

Steps to reproduce:
* create an invoice with a line
* change the receivable account
* duplicate the invoice

Result: the receivable account is recomputed to the default one.
Expected: we should keep it.

task-3504443

closes odoo/odoo#135723

X-original-commit: 1043d2b790a625590ca21f8e0d6560ceba3d6a84
Signed-off-by: Brice Bartoletti (bib) <bib@odoo.com>
This commit is contained in:
william-andre
2023-09-19 08:48:32 +00:00
committed by Brice bib Bartoletti
parent 28b2915cdb
commit 59ccb80918
3 changed files with 25 additions and 2 deletions
-1
View File
@@ -2363,7 +2363,6 @@ class AccountMove(models.Model):
(command, _id, line_vals)
for command, _id, line_vals in data['line_ids']
if command == Command.CREATE
and line_vals.get('display_type') not in ('payment_term', 'tax', 'rounding')
]
elif move.move_type == 'entry':
if 'partner_id' not in data:
@@ -496,7 +496,6 @@ class AccountMoveLine(models.Model):
values.append(product.description_purchase)
line.name = '\n'.join(values)
@api.depends('display_type', 'company_id')
def _compute_account_id(self):
term_lines = self.filtered(lambda line: line.display_type == 'payment_term')
if term_lines:
@@ -3746,3 +3746,28 @@ class TestAccountMoveOutInvoiceOnchanges(AccountTestInvoicingCommon):
'credit': 0.0,
},
])
def test_keep_receivable(self):
"""Duplicating an invoice with a different receivable account should keep the account."""
receivable_account = self.partner_a.property_account_receivable_id
other_receivable_account = receivable_account.copy()
invoice = self.env['account.move'].create({
'move_type': 'out_invoice',
'partner_id': self.partner_a.id,
'invoice_line_ids': [
Command.create({
'name': 'test line',
'quantity': 1,
'price_unit': 100,
})
],
})
invoice.line_ids.filtered(lambda l: l.display_type == 'payment_term').account_id = other_receivable_account
duplicate_invoice = invoice.copy()
self.assertEqual(
duplicate_invoice.line_ids.filtered(lambda l: l.display_type == 'payment_term').account_id,
other_receivable_account
)