Skip to content
Extraits de code Groupes Projets
Valider fdd57cac rédigé par Thibaud - Le Filament's avatar Thibaud - Le Filament
Parcourir les fichiers

[IMP] Linked deal_flow_tool_type with corresponding tool (loan manager)

parent 166399e9
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!1Draft: Link deal_flow_tool_type with corresponding tool
{
"name": "Financial - Deal Contract",
"summary": "Du deal flow au contrat",
"author": "Le Filament",
"author": "Le Filament, Odoo Community Association (OCA)",
"website": "https://le-filament.com",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"depends": [
"financial_deal_flow",
"financial_contract",
],
"depends": ["financial_deal_flow", "financial_contract", "loan_manager"],
"data": [
# "security/ir.model.access.csv",
# datas
......
# © 2019 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import datetime
from ocb.odoo import api
from odoo import fields, models
MAP_DICT = {"loan": "loan.manager.loan", "invest": "", "warranty": ""}
class FinancialContract(models.Model):
_inherit = "financial.contract"
deal_tool_id = fields.Many2one(
comodel_name="financial.deal.tool",
string="Deal Tool",
......@@ -18,7 +22,58 @@ class FinancialContract(models.Model):
related="deal_tool_id.deal_id",
store=True,
)
deal_tool_model_id = fields.Many2one(
"ir.model", compute="_compute_deal_tool_model_id", store=True
)
deal_tool_model_id_referenced_id = fields.Integer(
readonly=True, help="Id of the financial tool for this contract"
)
# ------------------------------------------------------
# SQL Constraints
# ------------------------------------------------------
# ------------------------------------------------------
# Default methods
# ------------------------------------------------------
# ------------------------------------------------------
# Computed fields / Search Fields
# ------------------------------------------------------
@api.depends("deal_tool_id")
def _compute_deal_tool_model_id(self):
if self.deal_tool_id.type:
self.deal_tool_model_id = self.env["ir.model"].search(
[("model", "=", MAP_DICT[self.deal_tool_id.type])]
)
# ------------------------------------------------------
# Onchange / Constraints
# ------------------------------------------------------
# ------------------------------------------------------
# CRUD methods (ORM overrides)
# ------------------------------------------------------
@api.model
def create(self, values):
contract = super().create(values)
# Create financial tool associated
financial_tool_record = self.env[contract.deal_tool_model_id.model].create(
{
"description": contract.name,
"first_term_date": datetime.now,
"payment_date": datetime.now,
"amount": contract.deal_tool_id.amount,
"partner_id": contract.deal_id.partner_id,
}
)
self.deal_tool_model_id_referenced_id = financial_tool_record.id
return contract
# ------------------------------------------------------
# Actions
# ------------------------------------------------------
# ------------------------------------------------------
# Business methods
# ------------------------------------------------------
......@@ -12,7 +12,8 @@
/>
<field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="before">
<field name="deal_id" readonly="True" />
<field name="deal_tool_id" />
<field name="deal_tool_model_id" />
</xpath>
</field>
</record>
......
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