From 41624fa80de40d2e99e394b890e0fe69e6392207 Mon Sep 17 00:00:00 2001 From: Ethan Hildick Date: Thu, 16 Feb 2023 13:35:54 +0100 Subject: [PATCH] [IMP] account_payment_order: Allow fixed date in the past --- .../i18n/account_payment_order.pot | 14 ++++++++++++++ account_payment_order/i18n/es.po | 13 +++++++++++++ .../models/account_payment_order.py | 16 +++++++++++++--- .../tests/test_payment_order_inbound.py | 7 +++++++ .../tests/test_payment_order_outbound.py | 7 +++++++ .../views/account_payment_order.xml | 4 ++++ 6 files changed, 58 insertions(+), 3 deletions(-) diff --git a/account_payment_order/i18n/account_payment_order.pot b/account_payment_order/i18n/account_payment_order.pot index b92beaff5..28422ba85 100644 --- a/account_payment_order/i18n/account_payment_order.pot +++ b/account_payment_order/i18n/account_payment_order.pot @@ -6,6 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 14.0\n" "Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-02-16 12:27+0000\n" +"PO-Revision-Date: 2023-02-16 12:27+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -148,6 +150,11 @@ msgstr "" msgid "Allow Litigation Move Lines" msgstr "" +#. module: account_payment_order +#: model:ir.model.fields,field_description:account_payment_order.field_account_payment_order__allow_past_date +msgid "Allow date in the past" +msgstr "" + #. module: account_payment_order #: model:ir.model.fields,field_description:account_payment_order.field_account_payment_order__allowed_journal_ids msgid "Allowed journals" @@ -1201,6 +1208,13 @@ msgstr "" msgid "Website communication history" msgstr "" +#. module: account_payment_order +#: model:ir.model.fields,help:account_payment_order.field_account_payment_order__allow_past_date +msgid "" +"When checked, the Payment Date won't fast-forward to today and will instead " +"remain the scheduled date" +msgstr "" + #. module: account_payment_order #: model:ir.model,name:account_payment_order.model_account_payment_line_create msgid "Wizard to create payment lines" diff --git a/account_payment_order/i18n/es.po b/account_payment_order/i18n/es.po index d4e23e0e8..f0781ffe2 100644 --- a/account_payment_order/i18n/es.po +++ b/account_payment_order/i18n/es.po @@ -163,6 +163,11 @@ msgstr "Todos los asientos asentados" msgid "Allow Litigation Move Lines" msgstr "Permitir apuntes en litigio" +#. module: account_payment_order +#: model:ir.model.fields,field_description:account_payment_order.field_account_payment_order__allow_past_date +msgid "Allow date in the past" +msgstr "Permitir fecha en el pasado" + #. module: account_payment_order #: model:ir.model.fields,field_description:account_payment_order.field_account_payment_order__allowed_journal_ids msgid "Allowed journals" @@ -1257,6 +1262,14 @@ msgstr "Mensajes del sitio web" msgid "Website communication history" msgstr "Historial de comunicaciones del sitio web" +#. module: account_payment_order +#: model:ir.model.fields,help:account_payment_order.field_account_payment_order__allow_past_date +msgid "" +"When checked, the Payment Date won't fast-forward to today and will instead " +"remain the scheduled date" +msgstr "" +"Al marcar esta casilla, la fecha contable no se pondrá al día actual y permanecerá con la fecha de ejecución del pago" + #. module: account_payment_order #: model:ir.model,name:account_payment_order.model_account_payment_line_create msgid "Wizard to create payment lines" diff --git a/account_payment_order/models/account_payment_order.py b/account_payment_order/models/account_payment_order.py index d99053eee..27b360682 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -144,6 +144,15 @@ class AccountPaymentOrder(models.Model): compute="_compute_move_count", string="Number of Journal Entries" ) description = fields.Char() + allow_past_date = fields.Boolean( + string="Allow date in the past", + help=( + "When checked, the Payment Date won't fast-forward to today " + "and will instead remain the scheduled date" + ), + readonly=True, + states={"draft": [("readonly", False)]}, + ) @api.depends("payment_mode_id") def _compute_allowed_journal_ids(self): @@ -186,7 +195,7 @@ class AccountPaymentOrder(models.Model): today = fields.Date.context_today(self) for order in self: if order.date_scheduled: - if order.date_scheduled < today: + if not order.allow_past_date and order.date_scheduled < today: raise ValidationError( _( "On payment order %s, the Payment Execution Date " @@ -303,8 +312,9 @@ class AccountPaymentOrder(models.Model): requested_date = order.date_scheduled or today else: requested_date = today - # No payment date in the past - requested_date = max(today, requested_date) + # No payment date in the past unless allowed + if not order.allow_past_date: + requested_date = max(today, requested_date) # inbound: check option no_debit_before_maturity if ( order.payment_type == "inbound" diff --git a/account_payment_order/tests/test_payment_order_inbound.py b/account_payment_order/tests/test_payment_order_inbound.py index 3903665f5..108f04d3f 100644 --- a/account_payment_order/tests/test_payment_order_inbound.py +++ b/account_payment_order/tests/test_payment_order_inbound.py @@ -89,6 +89,13 @@ class TestPaymentOrderInbound(TestPaymentOrderInboundBase): def test_constrains_date(self): with self.assertRaises(ValidationError): self.inbound_order.date_scheduled = date.today() - timedelta(days=1) + # No raise + self.inbound_order.write( + { + "allow_past_date": True, + "date_scheduled": date.today() - timedelta(days=2), + } + ) def test_creation(self): payment_order = self.inbound_order diff --git a/account_payment_order/tests/test_payment_order_outbound.py b/account_payment_order/tests/test_payment_order_outbound.py index f80379841..4119037ca 100644 --- a/account_payment_order/tests/test_payment_order_outbound.py +++ b/account_payment_order/tests/test_payment_order_outbound.py @@ -250,6 +250,13 @@ class TestPaymentOrderOutbound(TestPaymentOrderOutboundBase): ) with self.assertRaises(ValidationError): outbound_order.date_scheduled = date.today() - timedelta(days=2) + # No raise + outbound_order.write( + { + "allow_past_date": True, + "date_scheduled": date.today() - timedelta(days=2), + } + ) def test_manual_line_and_manual_date(self): # Create payment order diff --git a/account_payment_order/views/account_payment_order.xml b/account_payment_order/views/account_payment_order.xml index 40a163632..8714d3536 100644 --- a/account_payment_order/views/account_payment_order.xml +++ b/account_payment_order/views/account_payment_order.xml @@ -108,6 +108,10 @@ name="date_scheduled" attrs="{'invisible': [('date_prefered', '!=', 'fixed')], 'required': [('date_prefered', '=', 'fixed')]}" /> +