From 2b4bc079c2342b254c357069636b3a7404d80a1e Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Wed, 18 Jan 2023 10:02:31 +0100 Subject: [PATCH] [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 --- account_payment_partner/models/account_move.py | 16 ++++++++++++++++ .../tests/test_account_payment_partner.py | 4 ++++ .../views/account_move_view.xml | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/account_payment_partner/models/account_move.py b/account_payment_partner/models/account_move.py index 70ec9e8ea..c6b4ac2e1 100644 --- a/account_payment_partner/models/account_move.py +++ b/account_payment_partner/models/account_move.py @@ -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): @@ -94,6 +98,18 @@ class AccountMove(models.Model): continue return res + @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.account_type + in ("asset_receivable", "liability_payable") + ) + record.has_reconciled_items = bool( + lines_to_consider.matched_credit_ids + + lines_to_consider.matched_debit_ids + ) + def _reverse_moves(self, default_values_list=None, cancel=False): if not default_values_list: default_values_list = [{} for _ in self] diff --git a/account_payment_partner/tests/test_account_payment_partner.py b/account_payment_partner/tests/test_account_payment_partner.py index 19ccb1ee2..517746b27 100644 --- a/account_payment_partner/tests/test_account_payment_partner.py +++ b/account_payment_partner/tests/test_account_payment_partner.py @@ -258,6 +258,10 @@ class TestAccountPaymentPartner(TransactionCase): 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( diff --git a/account_payment_partner/views/account_move_view.xml b/account_payment_partner/views/account_move_view.xml index 65dd32214..f4e60fc01 100644 --- a/account_payment_partner/views/account_move_view.xml +++ b/account_payment_partner/views/account_move_view.xml @@ -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'))]}" /> +