diff --git a/models/financial_contract_guarantee.py b/models/financial_contract_guarantee.py index 5bb111761b682f83424fe602262ce02348bf1efd..37c7c25fb559279e3bbbdc21e4ffa70b12b45c7d 100644 --- a/models/financial_contract_guarantee.py +++ b/models/financial_contract_guarantee.py @@ -25,6 +25,7 @@ class FinancialContractGuarantee(models.Model): # chaque contrat de garantie est associée à un identifiant titulaire # plusieurs contrats de garantie peuvent être associés au même identifiant titular_number = fields.Char("Identifiant Titulaire") + person_number = fields.Char("Identifiant Personne", related="partner_id.person_number") product_id = fields.Many2one( comodel_name="financial.product.template.guarantee", @@ -50,7 +51,7 @@ class FinancialContractGuarantee(models.Model): related="external_loan_id.number", store=True, ) - guarantee_rate = fields.Float("Quotité garantie", tracking=1) + guarantee_rate = fields.Float("Quotité garantie", tracking=1, aggregator="avg", digits=(5, 2)) initial_guarantee_amount = fields.Monetary( string="Montant initial garanti", compute="_compute_initial_guarantee_amount", @@ -95,10 +96,13 @@ class FinancialContractGuarantee(models.Model): # --- Social share --- social_share_number = fields.Integer( string="Nbre parts sociales", - compute="_compute_social_share", + compute="_compute_social_share_number", store=True ) social_share_amount = fields.Monetary( + string="Montant parts sociales décidé", + ) + social_share_amount_computed = fields.Monetary( string="Montant parts sociales calculé", compute="_compute_social_share", store=True @@ -246,22 +250,29 @@ class FinancialContractGuarantee(models.Model): @api.depends("initial_guarantee_amount", "partner_id") def _compute_social_share(self): """ - Calcule nombre et montant des parts sociales en fonction : + Calcule le montant des parts sociales en fonction : - du taux défini sur la société - du montant max défini sur la société - du prix unitaire de la part défini sur la société - des prises de parts existantes sur la société :return: affecte les valeurs de montant et nombre de parts + + Sert au moment de la décision pour automatiser le calcul """ social_share_rate = self.company_id.social_share_rate social_share_amount_max = self.company_id.social_share_amount_max - share_unit_price = self.company_id.share_unit_price for guarantee in self: max_amount = social_share_amount_max - guarantee.partner_id.company_share_total rate_amount = social_share_rate * guarantee.initial_guarantee_amount final_amount = rate_amount if rate_amount <= max_amount else max_amount - guarantee.social_share_number = (final_amount // share_unit_price) - guarantee.social_share_amount = guarantee.social_share_number * share_unit_price + guarantee.social_share_amount_computed = final_amount + + @api.depends("social_share_amount") + def _compute_social_share_number(self): + share_unit_price = self.company_id.share_unit_price + for guarantee in self: + guarantee.social_share_number = (guarantee.social_share_amount // share_unit_price) + @api.depends("social_share_ids", "social_share_ids.share_total_amount") def _compute_social_share_paid(self): @@ -310,6 +321,9 @@ class FinancialContractGuarantee(models.Model): # Actions # ------------------------------------------------------ + def action_set_social_share_amount(self): + self.write({'social_share_amount': self.social_share_amount_computed}) + # ------------------------------------------------------ # CRUD (Override ORM) # ------------------------------------------------------ diff --git a/views/financial_contract_guarantee.xml b/views/financial_contract_guarantee.xml index 4d3d6ebd4a0bbbe95a963ba9a8e14b812e8314a9..03d5e58f4ca93495edd86801c1424a2e701979a2 100644 --- a/views/financial_contract_guarantee.xml +++ b/views/financial_contract_guarantee.xml @@ -9,13 +9,14 @@ <field name="arch" type="xml"> <list multi_edit="1"> <field name="titular_number" optional="hide" /> + <field name="person_number" optional="hide" /> <field name="number" optional="show" /> <field name="currency_id" column_invisible="1" /> <field name="partner_id" /> <field name="state" /> <field name="expiration_date" /> <field name="amount_initial" /> - <field name="guarantee_rate" widget="percentage" optional="show" /> + <field name="guarantee_rate" widget="percentage" optional="show"/> <field name="amount_received" /> <field name="payment_date" optional="show" /> <field name="external_loan_id" /> @@ -54,7 +55,14 @@ <field name="amount_initial" /> <field name="guarantee_rate" widget="percentage" /> <field name="fmg_amount" /> - <field name="social_share_amount" /> + <field name="social_share_amount_computed" invisible="social_share_amount" /> + <button class="d-inline-block px-2 py-0 btn btn-link" name="action_set_social_share_amount" + type="object" invisible="social_share_amount == social_share_amount_computed"> + <i class="fa fa-gear" role="img"/> + Appliquer le montant calculé + </button> + <field name="social_share_amount" readonly="1"/> + <field name="social_share_number" /> <field name="is_counter_guarantee" /> <field @@ -184,6 +192,11 @@ <field name="mode">primary</field> <field name="arch" type="xml"> <xpath expr="//filter[@name='group_state']" position="after"> + <filter + name="group_guarantee_rate" + string="Quotité garantie" + context="{'group_by': 'guarantee_rate'}" + /> <filter name="group_product" string="Produit"