Skip to content
Snippets Groups Projects
Commit 8f66ba95 authored by Emanuel Buzey's avatar Emanuel Buzey Committed by Daniil Digtyar Vasilieva
Browse files

[ADD] energy_selfconsumption: add contract stat button

parent cf5ba05e
No related branches found
No related tags found
2 merge requests!253[REL] Release 06/11/23,!211[IMP] energy_selfconsumption: invoicing acquired power
......@@ -20,6 +20,13 @@ class Selfconsumption(models.Model):
for record in self:
record.inscription_count = len(record.inscription_ids)
def _compute_contract_count(self):
for record in self:
related_contracts = self.env["contract.contract"].search(
[("name", "ilike", record.name)]
)
self.contracts_count = len(related_contracts)
def _compute_report_distribution_table(self):
"""
This compute field gets the distribution table needed to generate the reports.
......@@ -68,6 +75,7 @@ class Selfconsumption(models.Model):
"energy_project.inscription", "project_id", readonly=True
)
inscription_count = fields.Integer(compute=_compute_inscription_count)
contracts_count = fields.Integer(compute=_compute_contract_count)
def get_distribution_tables(self):
self.ensure_one()
......@@ -91,6 +99,17 @@ class Selfconsumption(models.Model):
"context": {"create": True, "default_project_id": self.id},
}
def get_contracts(self):
self.ensure_one()
return {
"type": "ir.actions.act_window",
"name": "Contracts",
"view_mode": "tree,form",
"res_model": "contract.contract",
"domain": [("name", "ilike", self.name)],
"context": {"create": True, "default_project_id": self.id},
}
def distribution_table_state(self, actual_state, new_state):
distribution_table_to_activate = self.distribution_table_ids.filtered(
lambda table: table.state == actual_state
......
......@@ -106,6 +106,22 @@
widget="statinfo"
/>
</button>
<button
class="oe_stat_button"
type="object"
name="get_contracts"
icon="fa-files-o"
attrs="{'invisible': [('state', '!=', 'active')]}"
>
<field
string="Contracts"
name="contracts_count"
widget="statinfo"
/>
</button>
</div>
<widget
name="web_ribbon"
......
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