Skip to content
Snippets Groups Projects
Commit 4be586ce authored by Daniil Digtyar Vasilieva's avatar Daniil Digtyar Vasilieva :call_me:
Browse files

[FIX] energy_selfconsumption: next_period not computing correctly when...

[FIX] energy_selfconsumption: next_period not computing correctly when applying a different start_date
parent 1c4b34c1
No related branches found
No related tags found
3 merge requests!277[REL] Release Sprint 27/11/23,!268C2/ Implementation energy_selfconsumption: next_period not computing correctly when...,!262[IMP] energy_selfconsumption: contract generation improvment
Pipeline #68744 passed
This commit is part of merge request !262. Comments created here will be created in the context of that merge request.
......@@ -5,4 +5,5 @@ from . import distribution_table
from . import supply_point_assignation
from . import project
from . import contract
from . import contract_line
from . import product
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class ContractLine(models.Model):
_inherit = "contract.line"
# This validation is raised when writing date_start on the contract and recurring_next_date is yet not computed
# Fixed by just checking when the recurrence is at line level (line_recurrence)
# TODO create a PR to OCA fixing this
@api.constrains("recurring_next_date", "date_start")
def _check_recurring_next_date_start_date(self):
for line in self:
if line.display_type == "line_section" or not line.recurring_next_date:
continue
if (
line.contract_id.line_recurrence
and line.date_start
and line.recurring_next_date
):
if line.date_start > line.recurring_next_date:
raise ValidationError(
_(
"You can't have a date of next invoice anterior "
"to the start of the contract line '%s'"
)
% line.name
)
......@@ -44,6 +44,12 @@ class ContractGenerationWizard(models.TransientModel):
# Create contracts
for supply_point_assignation in distribution_id.supply_point_assignation_ids:
# We write the date_start on the template, so it is not overwrite from the template
self.selfconsumption_id.product_id.contract_template_id.write(
{
"date_start": self.start_date,
}
)
contract = self.env["contract.contract"].create(
{
"name": _("Contract - %s - %s")
......@@ -54,7 +60,6 @@ class ContractGenerationWizard(models.TransientModel):
"partner_id": supply_point_assignation.supply_point_id.partner_id.id,
"supply_point_assignation_id": supply_point_assignation.id,
"company_id": self.env.company.id,
"date_start": self.start_date,
"contract_template_id": self.selfconsumption_id.product_id.contract_template_id.id,
}
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment