Skip to content
Snippets Groups Projects
Commit fdd57cac authored by Thibaud - Le Filament's avatar Thibaud - Le Filament
Browse files

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

parent 166399e9
Branches
No related tags found
1 merge request!1Draft: Link deal_flow_tool_type with corresponding tool
{ {
"name": "Financial - Deal Contract", "name": "Financial - Deal Contract",
"summary": "Du deal flow au contrat", "summary": "Du deal flow au contrat",
"author": "Le Filament", "author": "Le Filament, Odoo Community Association (OCA)",
"website": "https://le-filament.com", "website": "https://le-filament.com",
"version": "16.0.1.0.0", "version": "16.0.1.0.0",
"license": "AGPL-3", "license": "AGPL-3",
"depends": [ "depends": ["financial_deal_flow", "financial_contract", "loan_manager"],
"financial_deal_flow",
"financial_contract",
],
"data": [ "data": [
# "security/ir.model.access.csv", # "security/ir.model.access.csv",
# datas # datas
......
# © 2019 Le Filament (<http://www.le-filament.com>) # © 2019 Le Filament (<http://www.le-filament.com>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # 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 from odoo import fields, models
MAP_DICT = {"loan": "loan.manager.loan", "invest": "", "warranty": ""}
class FinancialContract(models.Model): class FinancialContract(models.Model):
_inherit = "financial.contract" _inherit = "financial.contract"
deal_tool_id = fields.Many2one( deal_tool_id = fields.Many2one(
comodel_name="financial.deal.tool", comodel_name="financial.deal.tool",
string="Deal Tool", string="Deal Tool",
...@@ -18,7 +22,58 @@ class FinancialContract(models.Model): ...@@ -18,7 +22,58 @@ class FinancialContract(models.Model):
related="deal_tool_id.deal_id", related="deal_tool_id.deal_id",
store=True, 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 # 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 @@ ...@@ -12,7 +12,8 @@
/> />
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//field[@name='partner_id']" position="before"> <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> </xpath>
</field> </field>
</record> </record>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment