Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][IMP] contract: Terminate contract lines with last_date_invoiced if it is higher than terminate date from wizard #1177

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 14 additions & 0 deletions contract/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If any line does not have a date, I encounter this error
image

if terminate_lines_with_last_date_invoiced and line.last_date_invoiced
else terminate_date
)
self.write(
{
"is_terminated": True,
Expand Down
9 changes: 9 additions & 0 deletions contract/tests/test_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Loading