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

add computed fields

parent 032fc447
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -143,6 +143,12 @@ class FinancialContractGuarantee(models.Model):
# --- Loan Data ---
payment_date = fields.Date("Date de versement")
payment_date_computed = fields.Date(
string="Date de paiement mise à jour",
help="Calculée sur la dernière valeur connue dans les lignes CRESERFI",
store=True,
compute="_compute_guarantee_data",
)
amount_initial = fields.Monetary(
string="Montant initial",
compute="_compute_amount_initial",
......@@ -150,16 +156,30 @@ class FinancialContractGuarantee(models.Model):
readonly=False,
)
amount_received = fields.Monetary("Montant reçu")
# if loan expiration date is updated, this field is set to a value
# which should be higher than expiration_date (from financial contract)
expiration_date_amended = fields.Date("Date de fin de prêt mise à jour")
remaining_capital = fields.Monetary("Capital restant dû", tracking=1)
expiration_date_computed = fields.Date(
string="Date d'expiration mise à jour",
help="Calculée sur la dernière valeur connue dans les lignes CRESERFI",
store=True,
compute="_compute_guarantee_data",
)
remaining_capital = fields.Monetary(
"Capital restant dû",
tracking=1,
store=True,
compute="_compute_guarantee_data",
)
loan_duration = fields.Integer(
string="Durée du crédit (mois)",
compute="_compute_loan_duration",
store=True,
readonly=False,
)
loan_duration_computed = fields.Integer(
string="Durée du crédit (mois) mise à jour",
help="Calculée sur la dernière valeur connue dans les lignes CRESERFI",
store=True,
compute="_compute_guarantee_data",
)
# --- Company Data ---
segment_code = fields.Char("Code Segment")
......@@ -204,6 +224,11 @@ class FinancialContractGuarantee(models.Model):
@api.depends(
"line_ids",
"line_ids.bdf_scoring",
"line_ids.end_date",
"line_ids.payment_date",
"line_ids.loan_duration",
"line_ids.remaining_capital",
"line_ids.amount_received",
)
def _compute_guarantee_data(self):
for guarantee in self:
......@@ -211,12 +236,18 @@ class FinancialContractGuarantee(models.Model):
ordered = with_date.sorted("line_date", reverse=True)
if ordered:
last_line = ordered[0]
guarantee.update({"bdf_scoring": last_line.bdf_scoring})
@api.depends(
"line_ids",
"line_ids.commission_amount",
guarantee.update(
{
"bdf_scoring": last_line.bdf_scoring,
"expiration_date_computed": last_line.end_date,
"payment_date_computed": last_line.payment_date,
"loan_duration_computed": last_line.loan_duration,
"remaining_capital": last_line.remaining_capital,
"amount_received": last_line.amount_received,
}
)
@api.depends("line_ids", "line_ids.commission_amount")
def _compute_commission_amount(self):
for guarantee in self:
guarantee.commission_amount = sum(
......
......@@ -72,11 +72,15 @@
name="action_set_social_share_amount"
type="object"
invisible="social_share_amount == social_share_amount_computed"
title="Appliquer le montant calculé aux parts sociales"
>
<i class="fa fa-gear" role="img" />
Appliquer le montant calculé
Appliquer le montant calculé de <field
name="social_share_amount_computed"
class="oe_inline"
/>
</button>
<field name="social_share_amount" readonly="1" />
<field name="social_share_amount" />
<field name="social_share_number" />
<field name="is_counter_guarantee" />
......@@ -97,11 +101,23 @@
<group name="loan" string="Prêt">
<field name="external_loan_id" options="{'no_create': 1}" />
<field name="payment_date" />
<!-- only show computed payment date when it is defined and different from known value -->
<field
name="payment_date_computed"
invisible="not payment_date_computed or payment_date_computed == payment_date"
/>
<field name="amount_initial" />
<field name="expiration_date" />
<!-- only show computed expiration date when it is defined and different from known value -->
<field
name="expiration_date_computed"
invisible="not expiration_date_computed or expiration_date_computed == expiration_date"
/>
<field name="loan_duration" />
<!-- only show computed loan duration when it is defined and different from known value -->
<field
name="expiration_date_amended"
invisible="not expiration_date_amended"
name="loan_duration_computed"
invisible="not loan_duration_computed or loan_duration_computed == loan_duration"
/>
<field name="amount_received" />
<field name="remaining_capital" />
......
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