diff --git a/__manifest__.py b/__manifest__.py index ea204bb7cfe393e78be098f7f0610dd18c7a1d4d..58577351ebb457b4c0f9e466eeb575a4c3325ae8 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 4eda44ccf95dfe104f6c9e007ecae45ef301dc0d..f1c5687cbfd74b5624480c3ee98dd4d9f5760d08 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 0000000000000000000000000000000000000000..fd71ae030678cf19e81d0de85ef88f4981b44083 --- /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 d63e07d2eb1793ec721a2c00200c409ebe5b0883..0ed2c61cd84b199f450f6d06e004a49a338fbd52 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 6b7c17baf28e219f99f7216ed0891a2f2159fa24..fa78d4eea8d5f6de2d8568b6f9e63f1ba1fcae05 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 20f16db157838d139f84e356c1f4366f88150b4d..7b8c9a3dd68b051700e3ff04de01e63c2d4e7c0e 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 36a28f8ad65da5752910cb155d8339274577b232..3978efdc5db9c2cc654f89cf4c80b19b8a1631c4 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 51c67d7a010e95a93314fd090a56e51df5931b63..7c8e3ac65b6af4915f5fa72faf03799c80348369 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 92c61e34a1e8dba6459b822ace98ffebe2fc7304..a334050d129bdef56cd46af3c325b989bdd9849a 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 0000000000000000000000000000000000000000..02c3f3b16933c53a1ddde67b15f6fcb84cfc498f --- /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 1ba5f9cee7daa019a0edf0145cb65fcaaccfaf0b..59498df090e92521c6894435c7290641c8cc2931 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 f2106df94e06e8d38ff89e6a93d6ad07898158f3..6ccdd5af83a1990f37949d9a5ba3e41534feaf8e 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 62bc8c5677a7e4c92673c2b5b9ed3d58b65c0288..68e259590661ae429d7d6f30817dd7eed9e905fa 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 1b1f7c71448ab333f58acab160c6b9197a061d29..7ab779990be8757e3138951d9bd7d8382eca584f 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 0000000000000000000000000000000000000000..394403454998d50948dc3115dde9cdb37f25dd23 --- /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>