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

This commit is contained in:
sergio-teruel
2025-01-09 21:40:29 +01:00
parent b4b3517161
commit 35852ea3b9
6 changed files with 55 additions and 7 deletions

View File

@@ -685,12 +685,21 @@ class ContractContract(models.Model):
}
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,