Skip to content

Commit

Permalink
[IMP] contract: Terminate contract lines with last_date_invoiced if i…
Browse files Browse the repository at this point in the history
…t is higher than terminate date from wizard
  • Loading branch information
sergio-teruel committed Jan 9, 2025
1 parent c1a26f5 commit 8378fff
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
19 changes: 14 additions & 5 deletions contract/i18n/contract.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
21 changes: 16 additions & 5 deletions contract/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-01-09 20:32+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: Sergio Teruel <sergio.teruel@tecnativa.com>\n"
"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n"
"Language: es\n"
Expand Down Expand Up @@ -1925,11 +1927,6 @@ msgstr "Cantidad"
msgid "Quarter(s)"
msgstr "Trimestre/s"

#. 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
Expand Down Expand Up @@ -2270,6 +2267,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"
Expand Down
13 changes: 11 additions & 2 deletions contract/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
else terminate_date
)
self.write(
{
"is_terminated": True,
Expand Down
6 changes: 6 additions & 0 deletions contract/wizards/contract_contract_terminate.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ 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:
wizard.contract_id._terminate_contract(
wizard.terminate_reason_id,
wizard.terminate_comment,
wizard.terminate_date,
wizard.terminate_with_last_date_invoiced,
)
return True
1 change: 1 addition & 0 deletions contract/wizards/contract_contract_terminate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
name="terminate_comment"
required="terminate_comment_required"
/>
<field name="terminate_with_last_date_invoiced" />
</group>
<footer>
<button
Expand Down

0 comments on commit 8378fff

Please sign in to comment.