From 8fa9d1e971f522a480c00d7529dd4fd70732d9a8 Mon Sep 17 00:00:00 2001 From: benjamin <benjamin@le-filament.com> Date: Tue, 11 Mar 2025 17:20:58 +0100 Subject: [PATCH] [UPD] add FMG and social share --- __manifest__.py | 1 + models/__init__.py | 2 + models/company_share_line.py | 45 ++++++++++++++++ models/financial_contract_guarantee.py | 36 +++++++++++-- models/financial_contract_guarantee_line.py | 2 +- .../financial_contract_guarantee_partner.py | 2 +- ...contract_guarantee_suspensive_condition.py | 2 +- ..._product_guarantee_suspensive_condition.py | 2 +- .../financial_product_template_guarantee.py | 2 +- models/mutual_guarantee_fund_line.py | 54 +++++++++++++++++++ models/res_partner.py | 5 ++ security/ir.model.access.csv | 2 + security/security_rules.xml | 15 ++++++ views/financial_contract_guarantee.xml | 36 ++++++++++++- views/mutual_guarantee_fund_line.xml | 48 +++++++++++++++++ 15 files changed, 245 insertions(+), 9 deletions(-) create mode 100644 models/company_share_line.py create mode 100644 models/mutual_guarantee_fund_line.py create mode 100644 views/mutual_guarantee_fund_line.xml diff --git a/__manifest__.py b/__manifest__.py index ea204bb..5857735 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -20,6 +20,7 @@ "views/financial_contract_guarantee_line.xml", "views/financial_contract_guarantee_partner.xml", "views/financial_product_template_guarantee.xml", + "views/mutual_guarantee_fund_line.xml", "views/res_config_settings.xml", "views/res_partner.xml", # views menu diff --git a/models/__init__.py b/models/__init__.py index 4eda44c..f1c5687 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -1,9 +1,11 @@ +from . import company_share_line from . import financial_contract_guarantee from . import financial_contract_guarantee_partner from . import financial_contract_guarantee_line from . import financial_contract_guarantee_suspensive_condition from . import financial_product_guarantee_suspensive_condition from . import financial_product_template_guarantee +from . import mutual_guarantee_fund_line from . import res_company from . import res_config_settings from . import res_partner diff --git a/models/company_share_line.py b/models/company_share_line.py new file mode 100644 index 0000000..fd71ae0 --- /dev/null +++ b/models/company_share_line.py @@ -0,0 +1,45 @@ +# Copyright 2024- Le Filament (https://le-filament.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import fields, models + + +class CompanyShareLine(models.Model): + _inherit = "company.share.line" + + # ------------------------------------------------------ + # Fields declaration + # ------------------------------------------------------ + guarantee_id = fields.Many2one( + comodel_name="financial.contract.guarantee", + string="Contrat de garantie", + index=True, + ) + + # ------------------------------------------------------ + # SQL Constraints + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Default methods + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Computed fields / Search Fields + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Onchange / Constraints + # ------------------------------------------------------ + + # ------------------------------------------------------ + # CRUD methods (ORM overrides) + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Actions + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Business methods + # ------------------------------------------------------ diff --git a/models/financial_contract_guarantee.py b/models/financial_contract_guarantee.py index d63e07d..0ed2c61 100644 --- a/models/financial_contract_guarantee.py +++ b/models/financial_contract_guarantee.py @@ -12,7 +12,7 @@ class FinancialContractGuarantee(models.Model): "mail.thread", "mail.activity.mixin", ] - _description = "Financial contract guarantee" + _description = "Contrat de garantie" _check_company_auto = True _rec_names_search = [ "name", @@ -71,20 +71,40 @@ class FinancialContractGuarantee(models.Model): tracking=1, ) fmg_amount = fields.Monetary( - string="Montant FMG", + string="FMG calculé", compute="_compute_fmg_amount", store=True, ) + fmg_paid = fields.Monetary( + string="FMG payé", + compute="_compute_fmg_paid", + store=True, + ) + fmg_ids = fields.One2many( + comodel_name="mutual.guarantee.fund.line", + inverse_name="guarantee_id", + string="FMG", + ) social_share_number = fields.Integer( string="Nbre parts sociales", compute="_compute_social_share", store=True ) social_share_amount = fields.Monetary( - string="Montant parts sociales", + string="Montant parts sociales calculé", compute="_compute_social_share", store=True ) + social_share_ids = fields.One2many( + comodel_name="company.share.line", + inverse_name="guarantee_id", + string="FMG", + ) + social_share_paid = fields.Monetary( + string="Montant parts sociales payé", + compute="_compute_social_share_paid", + store=True + ) line_ids = fields.One2many( comodel_name="financial.contract.guarantee.line", inverse_name="guarantee_id", @@ -194,6 +214,11 @@ class FinancialContractGuarantee(models.Model): for guarantee in self: guarantee.fmg_amount = fmg_rate * guarantee.initial_guarantee_amount + @api.depends("fmg_ids", "fmg_ids.amount") + def _compute_fmg_paid(self): + for guarantee in self: + guarantee.fmg_paid = sum(guarantee.fmg_ids.mapped("amount")) + @api.depends("initial_guarantee_amount", "partner_id") def _compute_social_share(self): """ @@ -214,6 +239,11 @@ class FinancialContractGuarantee(models.Model): guarantee.social_share_number = (final_amount // share_unit_price) guarantee.social_share_amount = guarantee.social_share_number * share_unit_price + @api.depends("social_share_ids", "social_share_ids.share_total_amount") + def _compute_social_share_paid(self): + for guarantee in self: + guarantee.social_share_paid = sum(guarantee.social_share_ids.mapped("share_total_amount")) + @api.depends("product_id") def _compute_suspensive_condition_ids(self): for contract in self: diff --git a/models/financial_contract_guarantee_line.py b/models/financial_contract_guarantee_line.py index 6b7c17b..fa78d4e 100644 --- a/models/financial_contract_guarantee_line.py +++ b/models/financial_contract_guarantee_line.py @@ -6,7 +6,7 @@ from odoo import fields, models class FinancialContractGuaranteeLine(models.Model): _name = "financial.contract.guarantee.line" - _description = "Financial contract guarantee line" + _description = "Ligne de Contrat de garantie" _check_company_auto = True _rec_names_search = [ "partner_id.name", diff --git a/models/financial_contract_guarantee_partner.py b/models/financial_contract_guarantee_partner.py index 20f16db..7b8c9a3 100644 --- a/models/financial_contract_guarantee_partner.py +++ b/models/financial_contract_guarantee_partner.py @@ -6,7 +6,7 @@ from odoo import fields, models class FinancialContractGuaranteePartner(models.Model): _name = "financial.contract.guarantee.partner" - _description = "External partner contractor" + _description = "Contact de garantie externe" _order = "name" name = fields.Char(string="Nom", required=True) diff --git a/models/financial_contract_guarantee_suspensive_condition.py b/models/financial_contract_guarantee_suspensive_condition.py index 36a28f8..3978efd 100644 --- a/models/financial_contract_guarantee_suspensive_condition.py +++ b/models/financial_contract_guarantee_suspensive_condition.py @@ -7,7 +7,7 @@ from odoo import fields, models class FinancialContractGuaranteeSuspensiveCondition(models.Model): _name = "financial.contract.guarantee.suspensive.condition" _inherit = ["financial.contract.suspensive.condition"] - _description = "Financial contract suspensive condition" + _description = "Condition suspensive de garantie" contract_id = fields.Many2one( comodel_name="financial.contract.guarantee", diff --git a/models/financial_product_guarantee_suspensive_condition.py b/models/financial_product_guarantee_suspensive_condition.py index 51c67d7..7c8e3ac 100644 --- a/models/financial_product_guarantee_suspensive_condition.py +++ b/models/financial_product_guarantee_suspensive_condition.py @@ -7,7 +7,7 @@ from odoo import fields, models class FinancialProductGuaranteeSuspensiveCondition(models.Model): _name = "financial.product.guarantee.suspensive.condition" _inherit = ["financial.product.suspensive.condition"] - _description = "Financial product guarantee suspensive condition" + _description = "Condition suspensive de produit de garantie" product_id = fields.Many2one( comodel_name="financial.product.template.guarantee", diff --git a/models/financial_product_template_guarantee.py b/models/financial_product_template_guarantee.py index 92c61e3..a334050 100644 --- a/models/financial_product_template_guarantee.py +++ b/models/financial_product_template_guarantee.py @@ -11,7 +11,7 @@ class FinancialProductTemplateGuarantee(models.Model): "mail.thread", "mail.activity.mixin", ] - _description = "Financial product template guarantee" + _description = "Produit de garantie" guarantee_rate = fields.Float("Quotité garantie") suspensive_condition_ids = fields.One2many( diff --git a/models/mutual_guarantee_fund_line.py b/models/mutual_guarantee_fund_line.py new file mode 100644 index 0000000..02c3f3b --- /dev/null +++ b/models/mutual_guarantee_fund_line.py @@ -0,0 +1,54 @@ +# © 2024 Le Filament (<http://www.le-filament.com>) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class MutualGuaranteeFundLine(models.Model): + _name = "mutual.guarantee.fund.line" + _description = "Ligne Fonds Mutuel de garantie" + _check_company_auto = True + _order = "date desc, id desc" + + guarantee_id = fields.Many2one( + comodel_name="financial.contract.guarantee", + string="Contrat de garantie", + required=True, + index=True, + ) + partner_id = fields.Many2one( + comodel_name="res.partner", + related="guarantee_id.partner_id", + string="Contact", + store=True, + index=True, + ) + company_id = fields.Many2one( + comodel_name="res.company", + related="guarantee_id.company_id", + string="Société", + store=True, + index=True, + ) + currency_id = fields.Many2one( + comodel_name="res.currency", + related="guarantee_id.currency_id", + ) + amount = fields.Monetary("Montant") + date = fields.Date(required=True) + + # ------------------------------------------------------ + # Constrains functions + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Computed fields / Search Fields + # ------------------------------------------------------ + + # ------------------------------------------------------ + # Actions + # ------------------------------------------------------ + + # ------------------------------------------------------ + # CRUD (Override ORM) + # ------------------------------------------------------ diff --git a/models/res_partner.py b/models/res_partner.py index 1ba5f9c..59498df 100644 --- a/models/res_partner.py +++ b/models/res_partner.py @@ -28,6 +28,11 @@ class ResPartner(models.Model): string="Plafond de garantie dépassé", compute="_compute_ongoing_guarantee" ) guarantee_by_company = fields.Json(compute="_compute_ongoing_guarantee") + fmg_ids = fields.One2many( + comodel_name="mutual.guarantee.fund.line", + inverse_name="partner_id", + string="FMG", + ) # ------------------------------------------------------ # SQL Constraints diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv index f2106df..6ccdd5a 100644 --- a/security/ir.model.access.csv +++ b/security/ir.model.access.csv @@ -7,3 +7,5 @@ access_financial_product_template_guarantee_admin,access_financial_product_templ access_financial_contract_guarantee_suspensive_condition,access_financial_contract_guarantee_suspensive_condition,model_financial_contract_guarantee_suspensive_condition,financial_contract.group_financial_user,1,1,1,1 access_financial_product_guarantee_suspensive_condition,access_financial_product_guarantee_suspensive_condition,model_financial_product_guarantee_suspensive_condition,financial_contract.group_financial_user,1,0,0,0 access_financial_product_guarantee_suspensive_condition_admin,access_financial_product_guarantee_suspensive_condition_admin,model_financial_product_guarantee_suspensive_condition,financial_contract.group_financial_admin,1,1,1,1 +access_mutual_guarantee_fund_line,access_mutual_guarantee_fund_line,model_mutual_guarantee_fund_line,financial_contract.group_financial_user,1,0,0,0 +access_mutual_guarantee_fund_line_admin,access_mutual_guarantee_fund_line_admin,model_mutual_guarantee_fund_line,financial_contract.group_financial_admin,1,1,1,1 diff --git a/security/security_rules.xml b/security/security_rules.xml index 62bc8c5..68e2595 100644 --- a/security/security_rules.xml +++ b/security/security_rules.xml @@ -48,5 +48,20 @@ <field name="perm_create" eval="True" /> <field name="perm_unlink" eval="True" /> </record> + <record id="mutual_guarantee_fund_line_multi_company_rule" model="ir.rule"> + <field name="name">FMG Line Multi Company</field> + <field name="model_id" ref="model_mutual_guarantee_fund_line" /> + <field + name="domain_force" + >[('company_id', 'in', company_ids + [False])]</field> + <field + name="groups" + eval="[(6, 0, [ref('financial_contract.group_financial_user')])]" + /> + <field name="perm_read" eval="False" /> + <field name="perm_write" eval="True" /> + <field name="perm_create" eval="True" /> + <field name="perm_unlink" eval="True" /> + </record> </odoo> diff --git a/views/financial_contract_guarantee.xml b/views/financial_contract_guarantee.xml index 1b1f7c7..7ab7799 100644 --- a/views/financial_contract_guarantee.xml +++ b/views/financial_contract_guarantee.xml @@ -78,10 +78,11 @@ </group> </xpath> <xpath expr="//page[@name='comment']" position="before"> + <!-- lignes de crédit --> <page name="lines" string="État du crédit" - invisible="state not in ['contract', 'done', 'cancel']" + invisible="state in ['init', 'offer', 'cancel']" > <field name="line_ids" @@ -118,6 +119,39 @@ </group> </group> </page> + <page + name="Commissions" + string="Commissions" + invisible="state in ['init', 'offer', 'cancel']" + > + </page> + <page + name="fmg" + string="FMG" + invisible="state in ['init', 'offer', 'cancel']" + > + <field name="fmg_ids"> + <list create="0" edit="0" delete="0"> + <field name="date" /> + <field name="amount" /> + </list> + </field> + </page> + <page + name="social_share" + string="Parts Sociales" + invisible="state in ['init', 'offer', 'cancel']" + > + <field name="social_share_ids"> + <list create="0" edit="0" delete="0"> + <field name="payment_date" /> + <field name="share_number" /> + <field name="share_unit_price" /> + <field name="share_action" /> + <field name="share_total_amount" /> + </list> + </field> + </page> </xpath> <xpath expr="//sheet" position="after"> <chatter /> diff --git a/views/mutual_guarantee_fund_line.xml b/views/mutual_guarantee_fund_line.xml new file mode 100644 index 0000000..3944034 --- /dev/null +++ b/views/mutual_guarantee_fund_line.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="utf-8" ?> +<odoo> + <!-- Tree --> + <record id="mutual_guarantee_fund_line_list_view" model="ir.ui.view"> + <field name="name">mutual.guarantee.fund.line.list</field> + <field name="model">mutual.guarantee.fund.line</field> + <field name="arch" type="xml"> + <list> + <field name="date" /> + <field name="partner_id" /> + <field name="guarantee_id" /> + <field name="amount" /> + <field name="company_id" optional="show" /> + </list> + </field> + </record> + + <!-- Form --> + <record id="mutual_guarantee_fund_line_form_view" model="ir.ui.view"> + <field name="name">mutual.guarantee.fund.line.form</field> + <field name="model">mutual.guarantee.fund.line</field> + <field name="arch" type="xml"> + <form> + <sheet> + <group> + <group> + <field name="date" /> + <field name="partner_id" /> + <field name="guarantee_id" /> + </group> + <group> + <field name="amount" /> + <field name="company_id" /> + </group> + </group> + </sheet> + </form> + </field> + </record> + + <!-- Action --> + <record model="ir.actions.act_window" id="mutual_guarantee_fund_line_action"> + <field name="name">FMG</field> + <field name="res_model">mutual.guarantee.fund.line</field> + <field name="path">fmg</field> + <field name="view_mode">list,form</field> + </record> +</odoo> -- GitLab