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:
MapClientConfig.MAPPING__EXTERNAL_LINK__CONTACT__LINK_LABEL["es_ES"],
"es_ES",
)
if "es" in self.wp_landing_data["translations"].keys():
self._update_translation(
"cm.place.external.link,url",
external_link.id,
"{landing_link}/#contacte".format(
landing_link=self.wp_landing_data["link"]
),
"{landing_link}/#contacte".format(
landing_link=self.wp_landing_data["translations"]["es"]
),
"es_ES",
)
if self.wp_landing_data["translations"]:
if "es" in self.wp_landing_data["translations"].keys():
self._update_translation(
"cm.place.external.link,url",
external_link.id,
"{landing_link}/#contacte".format(
landing_link=self.wp_landing_data["link"]
),
"{landing_link}/#contacte".format(
landing_link=self.wp_landing_data["translations"]["es"]
),
"es_ES",
)
return external_link
def _landing_external_link(self, place_id):
......
......@@ -43,5 +43,6 @@
"wizards/define_invoicing_mode_wizard_view.xml",
"wizards/invoicing_wizard_views.xml",
"reports/selfconsumption_reports.xml",
"reports/energy_delivered_invoice_template.xml"
],
}
......@@ -5,4 +5,6 @@ from . import distribution_table
from . import supply_point_assignation
from . import project
from . import contract
from . import contract_line
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):
help="Select the associated Energy Reseller",
)
def get_distribution_tables(self):
self.ensure_one()
return {
......@@ -184,14 +185,16 @@ class Selfconsumption(models.Model):
raise ValidationError(
_("Project must have defined a invoicing mode before activation.")
)
# Create ContractGenerationWizard
contract_wizard = self.env[
"energy_selfconsumption.contract_generation.wizard"
].create({"selfconsumption_id": self.id})
# Generate Contracts
contract_wizard.generate_contracts_button()
return {
"name": _("Generate Contracts"),
"type": "ir.actions.act_window",
"view_mode": "form",
"res_model": "energy_selfconsumption.contract_generation.wizard",
"views": [(False, "form")],
"view_id": False,
"target": "new",
"context": {"default_selfconsumption_id": self.id},
}
def set_invoicing_mode(self):
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):
......@@ -7,6 +10,12 @@ class ContractGenerationWizard(models.TransientModel):
selfconsumption_id = fields.Many2one(
"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):
"""
......@@ -35,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")
......@@ -45,22 +60,33 @@ 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": fields.date.today(),
"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
contract._onchange_contract_template_id()
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(
{
"name": contract_line_id.name.format(
code=supply_point_assignation.supply_point_id.code,
owner_id=supply_point_assignation.supply_point_id.owner_id.display_name,
),
"name": contract_line_id.name.format(**data),
}
)
# Update selfconsumption and distribution_table state
self.selfconsumption_id.write({"state": "active"})
self.selfconsumption_id.distribution_table_state("process", "active")
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 @@
>energy_selfconsumption.contract_generation.wizard</field>
<field name="arch" type="xml">
<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>
<button
class="btn-primary"
type="object"
name="generate_contracts_button"
>Generate</button>
>Accept</button>
<button string="Cancel" special="cancel" />
</footer>
</form>
</field>
......