diff --git a/contract/i18n/contract.pot b/contract/i18n/contract.pot
index 9c4e86e7bd..b9ba29b715 100644
--- a/contract/i18n/contract.pot
+++ b/contract/i18n/contract.pot
@@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2025-01-09 20:32+0000\n"
+"PO-Revision-Date: 2025-01-09 20:32+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
@@ -1739,11 +1741,6 @@ msgstr ""
msgid "Quarter(s)"
msgstr ""
-#. module: contract
-#: model:ir.model.fields,field_description:contract.field_contract_contract__rating_ids
-msgid "Ratings"
-msgstr ""
-
#. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_abstract_contract__recurring_rule_type
#: model:ir.model.fields,field_description:contract.field_contract_abstract_contract_line__recurring_rule_type
@@ -2078,6 +2075,18 @@ msgstr ""
msgid "Terminate Contract Wizard"
msgstr ""
+#. module: contract
+#: model:ir.model.fields,field_description:contract.field_contract_contract_terminate__terminate_with_last_date_invoiced
+msgid "Terminate lines with last date invoiced"
+msgstr ""
+
+#. module: contract
+#: model:ir.model.fields,help:contract.field_contract_contract_terminate__terminate_with_last_date_invoiced
+msgid ""
+"Terminate the contract lines with the last invoiced date if they cannot be "
+"terminated with the date reported in the wizard."
+msgstr ""
+
#. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_contract__is_terminated
msgid "Terminated"
diff --git a/contract/i18n/es.po b/contract/i18n/es.po
index a6dd569788..04684e3dd9 100644
--- a/contract/i18n/es.po
+++ b/contract/i18n/es.po
@@ -2271,6 +2271,20 @@ msgstr "Finalizar contrato"
msgid "Terminate Contract Wizard"
msgstr "Asistente de finalización de contrato"
+#. module: contract
+#: model:ir.model.fields,field_description:contract.field_contract_contract_terminate__terminate_with_last_date_invoiced
+msgid "Terminate lines with last date invoiced"
+msgstr "Finalizar líneas con la última fecha facturada"
+
+#. module: contract
+#: model:ir.model.fields,help:contract.field_contract_contract_terminate__terminate_with_last_date_invoiced
+msgid ""
+"Terminate the contract lines with the last invoiced date if they cannot be "
+"terminated with the date reported in the wizard."
+msgstr ""
+"Terminar las lineas de los contratos con la ultima fecha facturada si no se "
+"pueden terminar con la fecha informada en el asistente."
+
#. module: contract
#: model:ir.model.fields,field_description:contract.field_contract_contract__is_terminated
msgid "Terminated"
diff --git a/contract/models/contract.py b/contract/models/contract.py
index 510e4ff4ba..1ad85e4c68 100644
--- a/contract/models/contract.py
+++ b/contract/models/contract.py
@@ -685,12 +685,21 @@ def action_terminate_contract(self):
}
def _terminate_contract(
- self, terminate_reason_id, terminate_comment, terminate_date
+ self,
+ terminate_reason_id,
+ terminate_comment,
+ terminate_date,
+ terminate_lines_with_last_date_invoiced=False,
):
self.ensure_one()
if not self.env.user.has_group("contract.can_terminate_contract"):
raise UserError(_("You are not allowed to terminate contracts."))
- self.contract_line_ids.filtered("is_stop_allowed").stop(terminate_date)
+ for line in self.contract_line_ids.filtered("is_stop_allowed"):
+ line.stop(
+ max(terminate_date, line.last_date_invoiced)
+ if terminate_lines_with_last_date_invoiced and line.last_date_invoiced
+ else terminate_date
+ )
self.write(
{
"is_terminated": True,
diff --git a/contract/tests/test_contract.py b/contract/tests/test_contract.py
index 4a7ddb48b3..debd35b10d 100644
--- a/contract/tests/test_contract.py
+++ b/contract/tests/test_contract.py
@@ -2295,6 +2295,15 @@ def test_terminate_date_before_last_date_invoiced(self):
"terminate_comment",
to_date("2018-02-13"),
)
+ # Try terminate contract line with last_date_invoiced allowed
+ self.contract._terminate_contract(
+ self.terminate_reason,
+ "terminate_comment",
+ to_date("2018-02-13"),
+ terminate_lines_with_last_date_invoiced=True,
+ )
+ self.assertTrue(self.contract.is_terminated)
+ self.assertEqual(self.acct_line.date_end, to_date("2018-02-14"))
def test_recurrency_propagation(self):
# Existing contract
diff --git a/contract/wizards/contract_contract_terminate.py b/contract/wizards/contract_contract_terminate.py
index 2c26f478d1..a62a64cac0 100644
--- a/contract/wizards/contract_contract_terminate.py
+++ b/contract/wizards/contract_contract_terminate.py
@@ -25,6 +25,11 @@ class ContractContractTerminate(models.TransientModel):
terminate_comment_required = fields.Boolean(
related="terminate_reason_id.terminate_comment_required"
)
+ terminate_with_last_date_invoiced = fields.Boolean(
+ string="Terminate lines with last date invoiced",
+ help="Terminate the contract lines with the last invoiced date if they cannot "
+ "be terminated with the date reported in the wizard.",
+ )
def terminate_contract(self):
for wizard in self:
@@ -32,5 +37,6 @@ def terminate_contract(self):
wizard.terminate_reason_id,
wizard.terminate_comment,
wizard.terminate_date,
+ wizard.terminate_with_last_date_invoiced,
)
return True
diff --git a/contract/wizards/contract_contract_terminate.xml b/contract/wizards/contract_contract_terminate.xml
index 9fff84e8bf..66253b8841 100644
--- a/contract/wizards/contract_contract_terminate.xml
+++ b/contract/wizards/contract_contract_terminate.xml
@@ -15,6 +15,7 @@
name="terminate_comment"
required="terminate_comment_required"
/>
+