Skip to content
Extraits de code Groupes Projets
Valider 0e75b263 rédigé par Hugo Trentesaux's avatar Hugo Trentesaux
Parcourir les fichiers

add filter on active guarantee counter

parent 4ea506ff
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
# Copyright 2023- Le Filament (https://le-filament.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
from odoo import fields, models
from collections import Counter
from odoo import api, fields, models
class ResPartner(models.Model):
......@@ -16,8 +18,14 @@ class ResPartner(models.Model):
string="Contrats de garanties",
)
financial_contract_guarantee_count = fields.Integer(
string="Nombre de garanties actives",
compute="_compute_financial_contract_guarantee_count",
store=True,
)
financial_contract_guarantee_total_count = fields.Integer(
string="Nombre de garanties total (quel que soit l'état)",
compute="_compute_financial_contract_guarantee_count",
store=True
store=True,
)
guarantee_amount_ongoing = fields.Float(
string="En cours de garantie", compute="_compute_ongoing_guarantee"
......@@ -51,11 +59,14 @@ class ResPartner(models.Model):
# ------------------------------------------------------
# Computed fields / Search Fields
# ------------------------------------------------------
@api.depends("financial_contract_guarantee_ids")
def _compute_financial_contract_guarantee_count(self):
for partner in self:
partner.financial_contract_guarantee_count = (
partner.financial_contract_guarantee_ids.__len__()
partner.financial_contract_guarantee_total_count = len(
partner.financial_contract_guarantee_ids
)
c = Counter(partner.financial_contract_guarantee_ids.mapped("state"))
partner.financial_contract_guarantee_count = c["paid"] + c["litigation"]
def _compute_ongoing_guarantee(self):
for partner in self:
......
......@@ -62,4 +62,22 @@
</xpath>
</field>
</record>
<!-- Search View -->
<record id="res_partner_guarantee_search" model="ir.ui.view">
<field name="name">res.partner.guarantee.search</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="financial_partner.res_partner_financial_search" />
<field name="arch" type="xml">
<!-- Search -->
<!-- Filters -->
<xpath expr="//filter[@name='dead_coop']" position="after">
<separator />
<filter string="A des garanties en cours" name="has_active_guarantee" domain="[('financial_contract_guarantee_count', '>', 0)]" />
</xpath>
<!-- Group -->
</field>
</record>
</odoo>
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter