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

[IMP] energy_selfconsumption: added contract_line_qty_formula_data

parent cd9ba62a
No related branches found
No related tags found
2 merge requests!253[REL] Release 06/11/23,!211[IMP] energy_selfconsumption: invoicing acquired power
Pipeline #64130 passed
......@@ -28,6 +28,7 @@
"data/ir_sequence_data.xml",
"data/ir_attactment_data.xml",
"data/custom_paper_format_views.xml",
"data/contract_line_qty_formula_data.xml",
"views/selfconsumption_views.xml",
"views/supply_point_views.xml",
"views/res_partner_views.xml",
......
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record id="power_acquired_formula" model="contract.line.qty.formula">
<field name="name">Power Acquired Formula</field>
<field name="code">
days_timedelta = contract.next_period_date_end - contract.next_period_date_start
if days_timedelta:
# Add one so it counts the same day too (month = 29 + 1)
days_between = days_timedelta.days + 1
else:
days_between = 0
result = contract.supply_point_assignation_id.distribution_table_id.selfconsumption_project_id.power * contract.supply_point_assignation_id.coefficient * days_between
</field>
</record>
<record id="energy_delivered_formula" model="contract.line.qty.formula">
<field name="name">Energy Delivered Formula</field>
<field name="code">
days_timedelta = contract.next_period_date_end - contract.next_period_date_start
energy_delivered = 0
if days_timedelta:
# Add one so it counts the same day too (month = 29 + 1)
days_between = days_timedelta.days + 1
else:
days_between = 0
if 'energy_delivered' in context:
energy_delivered = context['energy_delivered']
result = energy_delivered * contract.supply_point_assignation_id.coefficient * days_between
</field>
</record>
<record
id="energy_delivered_variable_formula"
model="contract.line.qty.formula"
>
<field name="name">Energy Delivered Variable Formula</field>
<field name="code">
result = 0
</field>
</record>
</data>
</odoo>
......@@ -51,12 +51,6 @@ class ContractGenerationWizard(models.TransientModel):
"uom_po_id": uom_kw_id.id,
}
def _prepare_formula_values(self, code):
return {
"name": _("Formula - %s") % (self.selfconsumption_id.name),
"code": code,
}
def _prepare_contract_template_values(self, journal_id, contract_line):
return {
"name": self.selfconsumption_id.name,
......@@ -87,49 +81,19 @@ class ContractGenerationWizard(models.TransientModel):
# Create product
product_id = self.env["product.product"].create(self._prepare_product_values())
# Create contract formula
# TODO:Update formula energy_delivered and energy_delivered_variable.
# TODO:Update formula energy_delivered_variable.
formula_contract_id = None
if self.invoicing_mode == "power_acquired":
code = f"""
days_timedelta = line.next_period_date_end - line.next_period_date_start
if days_timedelta:
# Add one so it counts the same day too (month = 29 + 1)
days_between = days_timedelta.days + 1
else:
days_between = 0
result = line.supply_point_assignation_id.distribution_table_id.selfconsumption_project_id.power * line.supply_point_assignation_id.coefficient * days_between
"""
formula_contract_id = self.env["contract.line.qty.formula"].create(
self._prepare_formula_values(code)
formula_contract_id = self.env.ref(
"energy_selfconsumption.power_acquired_formula"
)
elif self.invoicing_mode == "energy_delivered":
code = f"""
days_timedelta = line.next_period_date_end - line.next_period_date_start
if days_timedelta:
# Add one so it counts the same day too (month = 29 + 1)
days_between = days_timedelta.days + 1
else:
days_between = 0
result = line.supply_point_assignation_id.distribution_table_id.selfconsumption_project_id.power * line.supply_point_assignation_id.coefficient * days_between
"""
formula_contract_id = self.env["contract.line.qty.formula"].create(
self._prepare_formula_values(code)
formula_contract_id = self.env.ref(
"energy_selfconsumption.energy_delivered_formula"
)
elif self.invoicing_mode == "energy_delivered_variable":
code = (
f"""
days_timedelta = line.next_period_date_end - line.next_period_date_start
if days_timedelta:
# Add one so it counts the same day too (month = 29 + 1)
days_between = days_timedelta.days + 1
else:
days_between = 0
result = line.supply_point_assignation_id.distribution_table_id.selfconsumption_project_id.power * line.supply_point_assignation_id.coefficient * days_between
""",
)
formula_contract_id = self.env["contract.line.qty.formula"].create(
self._prepare_formula_values(code)
formula_contract_id = self.env.ref(
"energy_selfconsumption.energy_delivered_variable_formula"
)
# Search accounting journal
......
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