[FIX] account: Fix shared fields between payments/journal entries
Fields that are shared between account.payment & account.move models are badly set when creating the records. For example, 'partner_bank_id' in vals will be set on account.payment but not on the account.move. closes odoo/odoo#53832 X-original-commit: a23c1e30c5b6b28f25c5f76d9fb85f075433b18f Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com> Signed-off-by: Laurent Smet <smetl@users.noreply.github.com>
This commit is contained in:
@@ -534,7 +534,16 @@ class AccountPayment(models.Model):
|
||||
for i, pay in enumerate(payments):
|
||||
write_off_line_vals = write_off_line_vals_list[i]
|
||||
|
||||
# Write payment_id on the journal entry plus the fields being stored in both models but having the same
|
||||
# name, e.g. partner_bank_id. The ORM is currently not able to perform such synchronization and make things
|
||||
# more difficult by creating related fields on the fly to handle the _inherits.
|
||||
# Then, when partner_bank_id is in vals, the key is consumed by account.payment but is never written on
|
||||
# account.move.
|
||||
to_write = {'payment_id': pay.id}
|
||||
for k, v in vals_list[i].items():
|
||||
if k in self._fields and self._fields[k].store and k in pay.move_id._fields and pay.move_id._fields[k].store:
|
||||
to_write[k] = v
|
||||
|
||||
if 'line_ids' not in vals_list[i]:
|
||||
to_write['line_ids'] = [(0, 0, line_vals) for line_vals in pay._prepare_move_line_default_vals(write_off_line_vals=write_off_line_vals)]
|
||||
|
||||
@@ -643,7 +652,7 @@ class AccountPayment(models.Model):
|
||||
|
||||
if not any(field_name in changed_fields for field_name in (
|
||||
'date', 'amount', 'payment_type', 'partner_type', 'payment_reference', 'is_internal_transfer',
|
||||
'currency_id', 'partner_id', 'destination_account_id',
|
||||
'currency_id', 'partner_id', 'destination_account_id', 'partner_bank_id',
|
||||
)):
|
||||
return
|
||||
|
||||
@@ -689,6 +698,7 @@ class AccountPayment(models.Model):
|
||||
pay.move_id.write({
|
||||
'partner_id': pay.partner_id.id,
|
||||
'currency_id': pay.currency_id.id,
|
||||
'partner_bank_id': pay.partner_bank_id.id,
|
||||
'line_ids': line_ids_commands,
|
||||
})
|
||||
|
||||
|
||||
@@ -14,6 +14,12 @@ class TestAccountPayment(AccountTestInvoicingCommon):
|
||||
cls.payment_debit_account_id = cls.copy_account(cls.company_data['default_journal_bank'].payment_debit_account_id)
|
||||
cls.payment_credit_account_id = cls.copy_account(cls.company_data['default_journal_bank'].payment_credit_account_id)
|
||||
|
||||
cls.partner_bank_account = cls.env['res.partner.bank'].create({
|
||||
'acc_number': 'BE32707171912447',
|
||||
'partner_id': cls.partner_a.id,
|
||||
'acc_type': 'bank',
|
||||
})
|
||||
|
||||
cls.company_data['default_journal_bank'].write({
|
||||
'payment_debit_account_id': cls.payment_debit_account_id.id,
|
||||
'payment_credit_account_id': cls.payment_credit_account_id.id,
|
||||
@@ -21,6 +27,10 @@ class TestAccountPayment(AccountTestInvoicingCommon):
|
||||
'outbound_payment_method_ids': [(6, 0, cls.env.ref('account.account_payment_method_manual_out').ids)],
|
||||
})
|
||||
|
||||
cls.partner_a.write({
|
||||
'bank_ids': [(6, 0, cls.partner_bank_account.ids)],
|
||||
})
|
||||
|
||||
def test_payment_move_sync_create_write(self):
|
||||
copy_receivable = self.copy_account(self.company_data['default_account_receivable'])
|
||||
|
||||
@@ -41,10 +51,12 @@ class TestAccountPayment(AccountTestInvoicingCommon):
|
||||
'partner_id': False,
|
||||
'destination_account_id': copy_receivable.id,
|
||||
'payment_method_id': self.env.ref('account.account_payment_method_manual_in').id,
|
||||
'partner_bank_id': False,
|
||||
}
|
||||
expected_move_values = {
|
||||
'currency_id': self.company_data['currency'].id,
|
||||
'partner_id': False,
|
||||
'partner_bank_id': False,
|
||||
}
|
||||
expected_liquidity_line = {
|
||||
'debit': 50.0,
|
||||
@@ -82,11 +94,13 @@ class TestAccountPayment(AccountTestInvoicingCommon):
|
||||
'destination_account_id': self.partner_a.property_account_payable_id.id,
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'partner_id': self.partner_a.id,
|
||||
'partner_bank_id': self.partner_bank_account.id,
|
||||
}])
|
||||
self.assertRecordValues(payment.move_id, [{
|
||||
**expected_move_values,
|
||||
'currency_id': self.currency_data['currency'].id,
|
||||
'partner_id': self.partner_a.id,
|
||||
'partner_bank_id': self.partner_bank_account.id,
|
||||
}])
|
||||
self.assertRecordValues(payment.line_ids.sorted('balance'), [
|
||||
{
|
||||
@@ -110,6 +124,7 @@ class TestAccountPayment(AccountTestInvoicingCommon):
|
||||
|
||||
liquidity_lines, counterpart_lines, writeoff_lines = payment._seek_for_lines()
|
||||
payment.move_id.write({
|
||||
'partner_bank_id': False,
|
||||
'line_ids': [
|
||||
(1, counterpart_lines.id, {
|
||||
'debit': 0.0,
|
||||
|
||||
Reference in New Issue
Block a user