Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • coopdevs/comunitats-energetiques/odoo-ce
1 result
Show changes
Commits on Source (21)
...@@ -344,18 +344,19 @@ class LandingCmPlace: ...@@ -344,18 +344,19 @@ class LandingCmPlace:
MapClientConfig.MAPPING__EXTERNAL_LINK__CONTACT__LINK_LABEL["es_ES"], MapClientConfig.MAPPING__EXTERNAL_LINK__CONTACT__LINK_LABEL["es_ES"],
"es_ES", "es_ES",
) )
if "es" in self.wp_landing_data["translations"].keys(): if self.wp_landing_data["translations"]:
self._update_translation( if "es" in self.wp_landing_data["translations"].keys():
"cm.place.external.link,url", self._update_translation(
external_link.id, "cm.place.external.link,url",
"{landing_link}/#contacte".format( external_link.id,
landing_link=self.wp_landing_data["link"] "{landing_link}/#contacte".format(
), landing_link=self.wp_landing_data["link"]
"{landing_link}/#contacte".format( ),
landing_link=self.wp_landing_data["translations"]["es"] "{landing_link}/#contacte".format(
), landing_link=self.wp_landing_data["translations"]["es"]
"es_ES", ),
) "es_ES",
)
return external_link return external_link
def _landing_external_link(self, place_id): def _landing_external_link(self, place_id):
......
...@@ -43,5 +43,6 @@ ...@@ -43,5 +43,6 @@
"wizards/define_invoicing_mode_wizard_view.xml", "wizards/define_invoicing_mode_wizard_view.xml",
"wizards/invoicing_wizard_views.xml", "wizards/invoicing_wizard_views.xml",
"reports/selfconsumption_reports.xml", "reports/selfconsumption_reports.xml",
"reports/energy_delivered_invoice_template.xml"
], ],
} }
...@@ -5,4 +5,6 @@ from . import distribution_table ...@@ -5,4 +5,6 @@ from . import distribution_table
from . import supply_point_assignation from . import supply_point_assignation
from . import project from . import project
from . import contract from . import contract
from . import contract_line
from . import product from . import product
from . import account_move
\ No newline at end of file
from odoo import models, fields
class AccountMoveLine(models.Model):
_inherit = "account.move.line"
selfconsumption_id = fields.One2many(
'energy_selfconsumption.selfconsumption',
related="contract_line_id.contract_id.project_id.selfconsumption_id"
)
class AccountMove(models.Model):
_inherit = "account.move"
def _get_name_invoice_report(self):
self.ensure_one()
if self.invoice_line_ids.selfconsumption_id.invoicing_mode == 'energy_delivered':
return 'energy_selfconsumption.energy_delivered_invoice_template'
return super()._get_name_invoice_report()
\ No newline at end of file
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
)
...@@ -98,6 +98,7 @@ class Selfconsumption(models.Model): ...@@ -98,6 +98,7 @@ class Selfconsumption(models.Model):
help="Select the associated Energy Reseller", help="Select the associated Energy Reseller",
) )
def get_distribution_tables(self): def get_distribution_tables(self):
self.ensure_one() self.ensure_one()
return { return {
...@@ -184,14 +185,16 @@ class Selfconsumption(models.Model): ...@@ -184,14 +185,16 @@ class Selfconsumption(models.Model):
raise ValidationError( raise ValidationError(
_("Project must have defined a invoicing mode before activation.") _("Project must have defined a invoicing mode before activation.")
) )
return {
# Create ContractGenerationWizard "name": _("Generate Contracts"),
contract_wizard = self.env[ "type": "ir.actions.act_window",
"energy_selfconsumption.contract_generation.wizard" "view_mode": "form",
].create({"selfconsumption_id": self.id}) "res_model": "energy_selfconsumption.contract_generation.wizard",
"views": [(False, "form")],
# Generate Contracts "view_id": False,
contract_wizard.generate_contracts_button() "target": "new",
"context": {"default_selfconsumption_id": self.id},
}
def set_invoicing_mode(self): def set_invoicing_mode(self):
return { return {
......
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template inherit_id="account.report_invoice_document" id="energy_delivered_invoice_template" primary="True">
<xpath expr="//th[@name='th_quantity']" position="replace">
<th name="th_total_installation_generation"><span>Total installation generation</span></th>
</xpath>
<xpath expr="//th[@name='th_total_installation_generation']" position="after">
<th name="th_partition_coefficient"><span>Partition coefficient</span></th>
</xpath>
<xpath expr="//th[@name='th_priceunit']" position="after">
<th name="th_import"><span>Import</span></th>
</xpath>
<xpath expr="//th[@name='th_taxes']" position="replace"></xpath>
<xpath expr="//th[@name='th_subtotal']" position="replace"></xpath>
<xpath expr="//th[@name='th_partition_coefficient']" position="after">
<th name="th_total_amount_invoiced"><span>Total amount invoiced</span></th>
</xpath>
<xpath expr="//td[@name='account_invoice_line_name']" position="after">
<td name="td_total_installation_generation">
<span t-field="line.selfconsumption_id.power"/><span> kWh</span>
</td>
</xpath>
<xpath expr="//td[@name='td_total_installation_generation']" position="after">
<td name="td_partition_coefficient">
<t t-if="line.contract_line_id.contract_id.supply_point_assignation_id.coefficient">
<span t-field="line.contract_line_id.contract_id.supply_point_assignation_id.coefficient"/>
</t>
</td>
</xpath>
<xpath expr="//span[@id='line_tax_ids']" position="replace"></xpath>
</template>
<template id="report_invoice_with_payments" inherit_id="account.report_invoice_with_payments">
<xpath expr='//t[@t-call="account.report_invoice_document"]' position="after">
<t t-if="o._get_name_invoice_report() == 'energy_selfconsumption.energy_delivered_invoice_template'"
t-call="energy_selfconsumption.energy_delivered_invoice_template" t-lang="lang"/>
</xpath>
</template>
</data>
</odoo>
from odoo import _, fields, models import datetime
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class ContractGenerationWizard(models.TransientModel): class ContractGenerationWizard(models.TransientModel):
...@@ -7,6 +10,12 @@ class ContractGenerationWizard(models.TransientModel): ...@@ -7,6 +10,12 @@ class ContractGenerationWizard(models.TransientModel):
selfconsumption_id = fields.Many2one( selfconsumption_id = fields.Many2one(
"energy_selfconsumption.selfconsumption", readonly=True "energy_selfconsumption.selfconsumption", readonly=True
) )
start_date = fields.Date(
string="Start date",
help="Starting date of the invoicing",
required=True,
default=fields.Date.today(),
)
def generate_contracts_button(self): def generate_contracts_button(self):
""" """
...@@ -35,6 +44,12 @@ class ContractGenerationWizard(models.TransientModel): ...@@ -35,6 +44,12 @@ class ContractGenerationWizard(models.TransientModel):
# Create contracts # Create contracts
for supply_point_assignation in distribution_id.supply_point_assignation_ids: 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( contract = self.env["contract.contract"].create(
{ {
"name": _("Contract - %s - %s") "name": _("Contract - %s - %s")
...@@ -45,22 +60,33 @@ class ContractGenerationWizard(models.TransientModel): ...@@ -45,22 +60,33 @@ class ContractGenerationWizard(models.TransientModel):
"partner_id": supply_point_assignation.supply_point_id.partner_id.id, "partner_id": supply_point_assignation.supply_point_id.partner_id.id,
"supply_point_assignation_id": supply_point_assignation.id, "supply_point_assignation_id": supply_point_assignation.id,
"company_id": self.env.company.id, "company_id": self.env.company.id,
"date_start": fields.date.today(),
"contract_template_id": self.selfconsumption_id.product_id.contract_template_id.id, "contract_template_id": self.selfconsumption_id.product_id.contract_template_id.id,
} }
) )
# We use the next method from the contract model to update the contract fields with contract template # We use the next method from the contract model to update the contract fields with contract template
contract._onchange_contract_template_id() contract._onchange_contract_template_id()
for contract_line_id in contract.contract_line_ids: for contract_line_id in contract.contract_line_ids:
data = {"code": supply_point_assignation.supply_point_id.code, "owner_id": supply_point_assignation.supply_point_id.owner_id.display_name,}
# Each invoicing type has different data in the description column, so we need to check and modify
if self.selfconsumption_id.invoicing_mode == 'energy_delivered':
contract_line_id.name += """\nCAU: {cau}\n"""
data["cau"] = self.selfconsumption_id.code
contract_line_id.write( contract_line_id.write(
{ {
"name": contract_line_id.name.format( "name": contract_line_id.name.format(**data),
code=supply_point_assignation.supply_point_id.code,
owner_id=supply_point_assignation.supply_point_id.owner_id.display_name,
),
} }
) )
# Update selfconsumption and distribution_table state # Update selfconsumption and distribution_table state
self.selfconsumption_id.write({"state": "active"}) self.selfconsumption_id.write({"state": "active"})
self.selfconsumption_id.distribution_table_state("process", "active") self.selfconsumption_id.distribution_table_state("process", "active")
return True return True
@api.constrains("start_date")
def constraint_date_start(self):
three_months_ago = fields.Date.today() - datetime.timedelta(days=90)
for record in self:
if record.start_date < three_months_ago:
raise ValidationError(
_("Start date can't be more that three months old")
)
...@@ -11,11 +11,26 @@ ...@@ -11,11 +11,26 @@
>energy_selfconsumption.contract_generation.wizard</field> >energy_selfconsumption.contract_generation.wizard</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Contract Generation"> <form string="Contract Generation">
<p>
<b
>Attention!</b> You are activating a project and thus activating its recurring billing.
</p>
<p>
To activate the recurring invoicing process, define the date from which you want
every supply point associated with this project to start invoicing according to the
established recurrence.
</p>
<group>
<field name="start_date" />
</group>
<footer> <footer>
<button <button
class="btn-primary"
type="object" type="object"
name="generate_contracts_button" name="generate_contracts_button"
>Generate</button> >Accept</button>
<button string="Cancel" special="cancel" />
</footer> </footer>
</form> </form>
</field> </field>
......