Sélectionner une révision Git
requirements-ci.txt
-
remi-filament a rédigéremi-filament a rédigé
financial_contract.py 3,46 Kio
# Copyright 2024- Le Filament (https://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
class FinancialContract(models.Model):
_inherit = "financial.contract"
# ------------------------------------------------------
# Fields declaration
# ------------------------------------------------------
deal_tool_model = fields.Selection(
related="deal_tool_id.type", store=True, readonly=True
)
deal_tool_model_reference_id = fields.Integer(
readonly=True, help="Id of the financial tool for this contract"
)
intervention_type = fields.Selection(
[("It must change", "For a Many 2 one field"), ("another", "one")],
string="intervention",
)
payment_date = fields.Date()
amount = fields.Monetary()
duration_or_count = fields.Integer(
help="The duration of a loan, or the number of pieces for a title"
)
rate = fields.Float()
periodicity = fields.Selection([("6", "Semester"), ("12", "Year")])
bank_account = fields.Char()
currency_id = fields.Many2one(
comodel_name="res.currency",
string="Company Currency",
compute="_compute_currency_id",
)
partner_id = fields.Many2one(
comodel_name="res.partner",
string="Créancier",
required=True,
domain=[("is_company", "=", True)],
)
# TODO compute ?
loan_id = fields.Many2one("loan.manager.loan")
# FIXME to be implemented
warrant_id = fields.Integer()
# FIXME to be implemented
title_id = fields.Integer()
# ------------------------------------------------------
# Computed fields / Search Fields
# ------------------------------------------------------
@api.model
def _compute_currency_id(self):
"""
Calcul la devise
"""
for rec in self:
rec.currency_id = self.env.user.company_id.currency_id.id
# ------------------------------------------------------
# Onchange / Constraints
# ------------------------------------------------------
# ------------------------------------------------------
# CRUD methods (ORM overrides)
# ------------------------------------------------------
# ------------------------------------------------------
# Actions
# ------------------------------------------------------
def btn_init_product(self):
# "duration_or_count": 15,
# "bank_account": "FR15 984 5351 864",
creation_dict = {
"description": self.name,
"amount": self.deal_tool_id.amount,
"payment_date": datetime.now(),
"periodicity": "6",
"rate": 1.60,
"partner_id": self.deal_id.partner_id.id,
"contract_id": self.id,
}
# Create financial tool associated
financial_tool_record = self.env[self.deal_tool_model].create(creation_dict)
self.deal_tool_model_reference_id = financial_tool_record.id
def btn_open_tool_form(self):
return {
"name": _("Financial tool"),
"type": "ir.actions.act_window",
"res_model": self.deal_tool_model,
"res_id": self.deal_tool_model_reference_id,
"view_mode": "form",
}
# ------------------------------------------------------
# Business methods
# ------------------------------------------------------