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 (6)
......@@ -29,6 +29,8 @@
"data/ir_attactment_data.xml",
"data/custom_paper_format_views.xml",
"data/contract_line_qty_formula_data.xml",
"data/mail_template.xml",
"data/ir_cron.xml",
"views/contract_views.xml",
"views/selfconsumption_views.xml",
"views/supply_point_views.xml",
......
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record id="send_invoicing_reminder_to_admin" model="ir.cron">
<field name="name">Send Invoicing Reminder to Admin User</field>
<field
name="model_id"
ref="energy_selfconsumption.model_energy_selfconsumption_selfconsumption"
/>
<field name="code">model.send_invoicing_reminder()</field>
<field name="user_id" ref="base.user_root" />
<field name='interval_number'>1</field>
<field name='interval_type'>days</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
</record>
</data>
</odoo>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="selfconsumption_invoicing_reminder" model="mail.template">
<field name="name">Selfconsumption Invoicing Reminder</field>
<field name="email_from">${object.company_id.email}</field>
<field name="email_to">${object.email}</field>
<field name="subject">Selfconsumption - Invoicing Reminder</field>
<field
name="model_id"
ref="energy_selfconsumption.model_energy_selfconsumption_selfconsumption"
/>
<field name="body_html">
<![CDATA[
<p>Hi,</br>
Remember that the collective self-consumption project <b>${ ctx['project_name'] }</b> of the energy community <b>${ object.project_id.company_id.name }</b> must invoice on the day <b>${ ctx['next_invoicing'] }</b>.</br>
It is necessary, therefore, that you enter into Odoo the energy generated in kWh during the period <b>${ ctx['first_date'] }</b> - <b>${ ctx['last_date'] }</b>.</br>
To do so, go to the project file, enter the contracts view, select the contracts that must be invoiced and press the Invoice button.</br>
For any questions or incidents, contact the support team; support@somcomunitats.coop.</p>
]]>
</field>
</record>
</odoo>
from datetime import datetime
from datetime import date, datetime, timedelta
from odoo import _, fields, models
from odoo.exceptions import ValidationError
......@@ -269,6 +269,46 @@ class Selfconsumption(models.Model):
"target": "self",
}
def send_invoicing_reminder(self):
today = date.today()
date_validation = today + timedelta(days=3)
filtered_contracts = self.env["contract.contract"].search(
[
(
"project_id.selfconsumption_id.invoicing_mode",
"=",
"energy_delivered",
),
("recurring_next_date", "=", date_validation),
]
)
project_controller = []
for contract in filtered_contracts:
project_name = contract.project_id.name
if project_name in project_controller:
continue
project_controller.append(project_name)
first_date = contract.next_period_date_start
last_date = contract.next_period_date_end
next_invoicing = last_date + timedelta(days=1)
ctx = {
"project_name": project_name,
"next_invoicing": next_invoicing.strftime("%d-%m-%Y"),
"first_date": first_date.strftime("%d-%m-%Y"),
"last_date": last_date.strftime("%d-%m-%Y"),
}
template = (
self.env.ref(
"energy_selfconsumption.selfconsumption_invoicing_reminder", False
)
.with_context(ctx)
.send_mail(self.id, raise_exception=True)
)
class CoefficientReport(models.TransientModel):
_name = "energy_selfconsumption.coefficient_report"
......
from . import test_contract_generation_wizard
from . import test_invoicing_reminder
from datetime import date, datetime, timedelta
from odoo.tests import TransactionCase
class TestInvoicingReminder(TransactionCase):
def setUp(self):
super().setUp()
self.partner = self.env["res.partner"].create({"name": "test partner"})
self.selfconsumption = self.env[
"energy_selfconsumption.selfconsumption"
].create(
{
"name": "test Selfconsumption Project",
"type": self.env.ref(
"energy_selfconsumption.selfconsumption_project_type"
).id,
"code": "ES0397277816188340VL",
"cil": "001ES0397277816188340VL",
"state": "activation",
"power": 100,
"street": "Carrer de Sants, 79",
"zip": "08014",
"city": "Barcelona",
"state_id": self.env.ref("base.state_es_b").id,
"country_id": self.env.ref("base.es").id,
"invoicing_mode": "energy_delivered",
}
)
self.inscription = self.env["energy_project.inscription"].create(
{
"project_id": self.selfconsumption.project_id.id,
"partner_id": self.partner.id,
"effective_date": datetime.today(),
}
)
self.supply_point = self.env["energy_selfconsumption.supply_point"].create(
{
"code": "ES0029542181297829TM",
"street": "C. de Sta. Catalina",
"street2": "55º B",
"zip": "08014",
"city": "Barcelona",
"state_id": self.env.ref("base.state_es_b").id,
"country_id": self.env.ref("base.es").id,
"owner_id": self.partner.id,
"partner_id": self.partner.id,
}
)
self.distribution_table = self.env[
"energy_selfconsumption.distribution_table"
].create(
{
"name": "DT001",
"selfconsumption_project_id": self.selfconsumption.id,
"type": "fixed",
"state": "process",
}
)
self.supply_point_assignation = self.env[
"energy_selfconsumption.supply_point_assignation"
].create(
{
"distribution_table_id": self.distribution_table.id,
"supply_point_id": self.supply_point.id,
"coefficient": 1,
}
)
self.define_invoicing_mode_wizard = self.env[
"energy_selfconsumption.define_invoicing_mode.wizard"
].create(
{
"selfconsumption_id": self.selfconsumption.id,
"price": 0.1,
"recurring_interval": 1,
"recurring_rule_type": "monthly",
"invoicing_mode": "energy_delivered",
}
)
self.contract_generation_wizard = self.env[
"energy_selfconsumption.contract_generation.wizard"
].create(
{
"selfconsumption_id": self.selfconsumption.id,
}
)
def test_send_invoicing_reminder(self):
# Test using send_invoicing_reminder() method to send correctly email
validation_date = date.today() + timedelta(days=3)
self.define_invoicing_mode_wizard.save_data_to_selfconsumption()
self.contract_generation_wizard.generate_contracts_button()
contract = self.env["contract.contract"].search(
[("name", "=", "Contract - test Selfconsumption Project - test partner")]
)
contract.recurring_next_date = validation_date
self.env["energy_selfconsumption.selfconsumption"].send_invoicing_reminder()
reminder_mail = self.env["mail.mail"].search(
[("subject", "=", "Selfconsumption - Invoicing Reminder")]
)
self.assertTrue(reminder_mail, "El correo de recordatorio no se envió.")
# Delete sent email to make other test
reminder_mail.unlink()
# Test using the send_invoicing_reminder() method with a record with a date outside the parameter (3 days)
contract.recurring_next_date = validation_date + timedelta(days=1)
self.env["energy_selfconsumption.selfconsumption"].send_invoicing_reminder()
reminder_mail = self.env["mail.mail"].search(
[("subject", "=", "Selfconsumption - Invoicing Reminder")]
)
self.assertFalse(reminder_mail, "El correo de recordatorio no se envió.")