diff --git a/account_payment_order/i18n/account_payment_order.pot b/account_payment_order/i18n/account_payment_order.pot index 1820f293a..bf5f02631 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" @@ -1193,6 +1200,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 b4652ac79..a976da4dc 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" @@ -1249,6 +1254,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 6380eb048..a28a08409 100644 --- a/account_payment_order/models/account_payment_order.py +++ b/account_payment_order/models/account_payment_order.py @@ -145,6 +145,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): @@ -187,7 +196,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 " @@ -304,8 +313,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 8710e5618..87056e464 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_invoice_communication_01(self): self.assertEqual( diff --git a/account_payment_order/tests/test_payment_order_outbound.py b/account_payment_order/tests/test_payment_order_outbound.py index bd5be8885..03d1b5841 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_invoice_communication_01(self): self.assertEqual("F1242", self.invoice._get_payment_order_communication()) diff --git a/account_payment_order/views/account_payment_order.xml b/account_payment_order/views/account_payment_order.xml index 4e2e71405..6b3c1e1ae 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')]}" /> +