Skip to content
Snippets Groups Projects

[IMP] energy_selfconsumption: invoicing acquired power

1 file
+ 1
47
Compare changes
  • Side-by-side
  • Inline
@@ -4,27 +4,6 @@ from odoo import _, fields, models
class ContractGenerationWizard(models.TransientModel):
_name = "energy_selfconsumption.contract_generation.wizard"
price_energy = fields.Float(string="Price (€/kWn/day)")
recurring_interval = fields.Integer(
default=1,
string="Invoice Every",
help="Invoice every (Days/Week/Month/Year)",
)
recurring_rule_type = fields.Selection(
[
("daily", "Day(s)"),
("weekly", "Week(s)"),
("monthly", "Month(s)"),
("monthlylastday", "Month(s) last day"),
("quarterly", "Quarter(s)"),
("semesterly", "Semester(s)"),
("yearly", "Year(s)"),
],
default="monthly",
string="Recurrence",
help="Specify Interval for automatic invoice generation.",
)
selfconsumption_id = fields.Many2one(
"energy_selfconsumption.selfconsumption", readonly=True
)
@@ -46,29 +25,6 @@ class ContractGenerationWizard(models.TransientModel):
SomeException: When no distribution table in process of activation is found.
"""
# Create product
product_id = self.env["product.product"].create(
{
"name": _("Energy Acquired - %s") % (self.selfconsumption_id.name),
"lst_price": self.price_energy,
"company_id": self.env.company.id,
}
)
# Create contract formula
formula_contract_id = self.env["contract.line.qty.formula"].create(
{
"name": _("Formula - %s") % (self.selfconsumption_id.name),
"code": """
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
""",
}
product_id = self.selfconsumption_id.product_id
formula_contract_id = (
self.selfconsumption_id.contract_template_id.contract_line_ids.qty_formula_id
@@ -125,14 +81,12 @@ result = line.supply_point_assignation_id.distribution_table_id.selfconsumption_
),
"partner_id": supply_point_assignation.supply_point_id.partner_id.id,
"invoice_partner_id": supply_point_assignation.supply_point_id.partner_id.id,
"journal_id": journal_id.id,
"recurring_interval": self.recurring_interval,
"recurring_rule_type": self.recurring_rule_type,
"recurring_invoicing_type": "post-paid",
"date_start": fields.date.today(),
"company_id": self.env.company.id,
"contract_line_ids": contract_lines,
"project_id": self.selfconsumption_id.project_id.id,
"contract_template_id": self.selfconsumption_id.contract_template_id.id,
}
)
Loading