[IMP] account_payment_partner: Make payment mode editable on entry

Complement of 998f8df6aa254266c015fab144ba290e1a386cf0

Extend the editability to the journal entry (account.move), taking
as criteria if there's no reconciliation made, which is the definitory
one.

It includes test for this new feature, both the mode propagation and
the editability check.

TT39850
This commit is contained in:
Pedro M. Baeza
2023-01-18 10:02:31 +01:00
parent da8ca5bb62
commit c24ebfad61
3 changed files with 21 additions and 1 deletions

View File

@@ -33,6 +33,10 @@ class AccountMove(models.Model):
ondelete="restrict",
readonly=False,
)
has_reconciled_items = fields.Boolean(
help="Technical field for supporting the editability of the payment mode",
compute="_compute_has_reconciled_items",
)
@api.depends("move_type")
def _compute_payment_mode_filter_type_domain(self):
@@ -83,6 +87,17 @@ class AccountMove(models.Model):
partner.supplier_payment_mode_id.refund_payment_mode_id
)
@api.depends("line_ids.matched_credit_ids", "line_ids.matched_debit_ids")
def _compute_has_reconciled_items(self):
for record in self:
lines_to_consider = record.line_ids.filtered(
lambda x: x.account_id.internal_type in ("receivable", "payable")
)
record.has_reconciled_items = bool(
lines_to_consider.matched_credit_ids
+ lines_to_consider.matched_debit_ids
)
@api.onchange("partner_id")
def _onchange_partner_id(self):
"""Force compute because the onchange chain doesn't call

View File

@@ -298,6 +298,10 @@ class TestAccountPaymentPartner(SavepointCase):
mode = self.supplier_payment_mode.copy()
aml.payment_mode_id = mode
self.assertEqual(invoice.payment_mode_id, mode)
# Test payment mode editability on account move
self.assertFalse(invoice.has_reconciled_items)
invoice.payment_mode_id = self.supplier_payment_mode
self.assertEqual(aml.payment_mode_id, self.supplier_payment_mode)
def test_invoice_create_out_invoice(self):
invoice = self._create_invoice(

View File

@@ -28,8 +28,9 @@
name="payment_mode_id"
domain="[('payment_type', '=', payment_mode_filter_type_domain), ('company_id', '=', company_id)]"
widget="selection"
attrs="{'readonly': [('state', '!=', 'draft')], 'invisible': [('move_type', 'not in', ('out_invoice','out_refund','in_invoice','in_refund'))]}"
attrs="{'readonly': [('has_reconciled_items', '=', True)], 'invisible': [('move_type', 'not in', ('out_invoice','out_refund','in_invoice','in_refund'))]}"
/>
<field name="has_reconciled_items" invisible="1" />
<field name="commercial_partner_id" invisible="1" />
<field name="bank_account_required" invisible="1" />
<field name="payment_mode_filter_type_domain" invisible="1" />