[MIG] account_loan: Migration to 14.0
This commit is contained in:
parent
765935a105
commit
c07ae64afc
@ -2,7 +2,7 @@
|
|||||||
# 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).
|
||||||
{
|
{
|
||||||
"name": "Account Loan management",
|
"name": "Account Loan management",
|
||||||
"version": "13.0.1.1.0",
|
"version": "14.0.1.0.0",
|
||||||
"author": "Creu Blanca,Odoo Community Association (OCA)",
|
"author": "Creu Blanca,Odoo Community Association (OCA)",
|
||||||
"website": "https://github.com/OCA/account-financial-tools",
|
"website": "https://github.com/OCA/account-financial-tools",
|
||||||
"license": "AGPL-3",
|
"license": "AGPL-3",
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
# Copyright 2021 Creu Blanca - Alba Riera
|
|
||||||
|
|
||||||
from openupgradelib import openupgrade
|
|
||||||
|
|
||||||
|
|
||||||
@openupgrade.migrate()
|
|
||||||
def migrate(env, version):
|
|
||||||
openupgrade.logged_query(
|
|
||||||
env.cr,
|
|
||||||
"""
|
|
||||||
UPDATE account_move am
|
|
||||||
SET loan_line_id = ai.loan_line_id,
|
|
||||||
loan_id = ai.loan_id
|
|
||||||
FROM account_invoice ai
|
|
||||||
WHERE ai.id = am.old_invoice_id and ai.loan_id is not null""",
|
|
||||||
)
|
|
@ -22,10 +22,7 @@ class AccountLoan(models.Model):
|
|||||||
_inherit = ["mail.thread", "mail.activity.mixin"]
|
_inherit = ["mail.thread", "mail.activity.mixin"]
|
||||||
|
|
||||||
def _default_company(self):
|
def _default_company(self):
|
||||||
force_company = self._context.get("force_company")
|
return self.env.company
|
||||||
if not force_company:
|
|
||||||
return self.env.user.company_id.id
|
|
||||||
return force_company
|
|
||||||
|
|
||||||
name = fields.Char(
|
name = fields.Char(
|
||||||
copy=False,
|
copy=False,
|
||||||
@ -61,7 +58,10 @@ class AccountLoan(models.Model):
|
|||||||
default="draft",
|
default="draft",
|
||||||
)
|
)
|
||||||
line_ids = fields.One2many(
|
line_ids = fields.One2many(
|
||||||
"account.loan.line", readonly=True, inverse_name="loan_id", copy=False,
|
"account.loan.line",
|
||||||
|
readonly=True,
|
||||||
|
inverse_name="loan_id",
|
||||||
|
copy=False,
|
||||||
)
|
)
|
||||||
periods = fields.Integer(
|
periods = fields.Integer(
|
||||||
required=True,
|
required=True,
|
||||||
@ -88,7 +88,7 @@ class AccountLoan(models.Model):
|
|||||||
default=0.0,
|
default=0.0,
|
||||||
digits=(8, 6),
|
digits=(8, 6),
|
||||||
help="Currently applied rate",
|
help="Currently applied rate",
|
||||||
track_visibility="always",
|
tracking=True,
|
||||||
)
|
)
|
||||||
rate_period = fields.Float(
|
rate_period = fields.Float(
|
||||||
compute="_compute_rate_period",
|
compute="_compute_rate_period",
|
||||||
@ -117,12 +117,20 @@ class AccountLoan(models.Model):
|
|||||||
default="fixed-annuity",
|
default="fixed-annuity",
|
||||||
)
|
)
|
||||||
fixed_amount = fields.Monetary(
|
fixed_amount = fields.Monetary(
|
||||||
currency_field="currency_id", compute="_compute_fixed_amount",
|
currency_field="currency_id",
|
||||||
|
compute="_compute_fixed_amount",
|
||||||
)
|
)
|
||||||
fixed_loan_amount = fields.Monetary(
|
fixed_loan_amount = fields.Monetary(
|
||||||
currency_field="currency_id", readonly=True, copy=False, default=0,
|
currency_field="currency_id",
|
||||||
|
readonly=True,
|
||||||
|
copy=False,
|
||||||
|
default=0,
|
||||||
|
)
|
||||||
|
fixed_periods = fields.Integer(
|
||||||
|
readonly=True,
|
||||||
|
copy=False,
|
||||||
|
default=0,
|
||||||
)
|
)
|
||||||
fixed_periods = fields.Integer(readonly=True, copy=False, default=0,)
|
|
||||||
loan_amount = fields.Monetary(
|
loan_amount = fields.Monetary(
|
||||||
currency_field="currency_id",
|
currency_field="currency_id",
|
||||||
required=True,
|
required=True,
|
||||||
@ -153,7 +161,9 @@ class AccountLoan(models.Model):
|
|||||||
help="When checked, the first payment will be on start date",
|
help="When checked, the first payment will be on start date",
|
||||||
)
|
)
|
||||||
currency_id = fields.Many2one(
|
currency_id = fields.Many2one(
|
||||||
"res.currency", compute="_compute_currency", readonly=True,
|
"res.currency",
|
||||||
|
compute="_compute_currency",
|
||||||
|
readonly=True,
|
||||||
)
|
)
|
||||||
journal_type = fields.Char(compute="_compute_journal_type")
|
journal_type = fields.Char(compute="_compute_journal_type")
|
||||||
journal_id = fields.Many2one(
|
journal_id = fields.Many2one(
|
||||||
@ -190,7 +200,9 @@ class AccountLoan(models.Model):
|
|||||||
states={"draft": [("readonly", False)]},
|
states={"draft": [("readonly", False)]},
|
||||||
)
|
)
|
||||||
is_leasing = fields.Boolean(
|
is_leasing = fields.Boolean(
|
||||||
default=False, readonly=True, states={"draft": [("readonly", False)]},
|
default=False,
|
||||||
|
readonly=True,
|
||||||
|
states={"draft": [("readonly", False)]},
|
||||||
)
|
)
|
||||||
leased_asset_account_id = fields.Many2one(
|
leased_asset_account_id = fields.Many2one(
|
||||||
"account.account",
|
"account.account",
|
||||||
@ -212,7 +224,8 @@ class AccountLoan(models.Model):
|
|||||||
)
|
)
|
||||||
move_ids = fields.One2many("account.move", copy=False, inverse_name="loan_id")
|
move_ids = fields.One2many("account.move", copy=False, inverse_name="loan_id")
|
||||||
pending_principal_amount = fields.Monetary(
|
pending_principal_amount = fields.Monetary(
|
||||||
currency_field="currency_id", compute="_compute_total_amounts",
|
currency_field="currency_id",
|
||||||
|
compute="_compute_total_amounts",
|
||||||
)
|
)
|
||||||
payment_amount = fields.Monetary(
|
payment_amount = fields.Monetary(
|
||||||
currency_field="currency_id",
|
currency_field="currency_id",
|
||||||
@ -438,7 +451,7 @@ class AccountLoan(models.Model):
|
|||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
action = self.env.ref("account.action_move_out_invoice_type")
|
action = self.env.ref("account.action_move_out_invoice_type")
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
result["domain"] = [("loan_id", "=", self.id), ("type", "=", "in_invoice")]
|
result["domain"] = [("loan_id", "=", self.id), ("move_type", "=", "in_invoice")]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
|
@ -20,38 +20,44 @@ class AccountLoanLine(models.Model):
|
|||||||
|
|
||||||
name = fields.Char(compute="_compute_name")
|
name = fields.Char(compute="_compute_name")
|
||||||
loan_id = fields.Many2one(
|
loan_id = fields.Many2one(
|
||||||
"account.loan", required=True, readonly=True, ondelete="cascade",
|
"account.loan",
|
||||||
|
required=True,
|
||||||
|
readonly=True,
|
||||||
|
ondelete="cascade",
|
||||||
|
)
|
||||||
|
is_leasing = fields.Boolean(
|
||||||
|
related="loan_id.is_leasing",
|
||||||
|
readonly=True,
|
||||||
)
|
)
|
||||||
is_leasing = fields.Boolean(related="loan_id.is_leasing", readonly=True,)
|
|
||||||
loan_type = fields.Selection(
|
loan_type = fields.Selection(
|
||||||
[
|
|
||||||
("fixed-annuity", "Fixed Annuity"),
|
|
||||||
("fixed-principal", "Fixed Principal"),
|
|
||||||
("interest", "Only interest"),
|
|
||||||
],
|
|
||||||
related="loan_id.loan_type",
|
related="loan_id.loan_type",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
)
|
)
|
||||||
loan_state = fields.Selection(
|
loan_state = fields.Selection(
|
||||||
[
|
|
||||||
("draft", "Draft"),
|
|
||||||
("posted", "Posted"),
|
|
||||||
("cancelled", "Cancelled"),
|
|
||||||
("closed", "Closed"),
|
|
||||||
],
|
|
||||||
related="loan_id.state",
|
related="loan_id.state",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
store=True,
|
store=True,
|
||||||
)
|
)
|
||||||
sequence = fields.Integer(required=True, readonly=True)
|
sequence = fields.Integer(required=True, readonly=True)
|
||||||
date = fields.Date(
|
date = fields.Date(
|
||||||
required=True, readonly=True, help="Date when the payment will be accounted",
|
required=True,
|
||||||
|
readonly=True,
|
||||||
|
help="Date when the payment will be accounted",
|
||||||
)
|
)
|
||||||
long_term_loan_account_id = fields.Many2one(
|
long_term_loan_account_id = fields.Many2one(
|
||||||
"account.account", readony=True, related="loan_id.long_term_loan_account_id",
|
"account.account",
|
||||||
|
readonly=True,
|
||||||
|
related="loan_id.long_term_loan_account_id",
|
||||||
|
)
|
||||||
|
currency_id = fields.Many2one(
|
||||||
|
"res.currency",
|
||||||
|
related="loan_id.currency_id",
|
||||||
|
)
|
||||||
|
rate = fields.Float(
|
||||||
|
required=True,
|
||||||
|
readonly=True,
|
||||||
|
digits=(8, 6),
|
||||||
)
|
)
|
||||||
currency_id = fields.Many2one("res.currency", related="loan_id.currency_id",)
|
|
||||||
rate = fields.Float(required=True, readonly=True, digits=(8, 6),)
|
|
||||||
pending_principal_amount = fields.Monetary(
|
pending_principal_amount = fields.Monetary(
|
||||||
currency_field="currency_id",
|
currency_field="currency_id",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
@ -88,7 +94,10 @@ class AccountLoanLine(models.Model):
|
|||||||
compute="_compute_amounts",
|
compute="_compute_amounts",
|
||||||
help="Pending amount of the loan after the payment",
|
help="Pending amount of the loan after the payment",
|
||||||
)
|
)
|
||||||
move_ids = fields.One2many("account.move", inverse_name="loan_line_id",)
|
move_ids = fields.One2many(
|
||||||
|
"account.move",
|
||||||
|
inverse_name="loan_line_id",
|
||||||
|
)
|
||||||
has_moves = fields.Boolean(compute="_compute_has_moves")
|
has_moves = fields.Boolean(compute="_compute_has_moves")
|
||||||
has_invoices = fields.Boolean(compute="_compute_has_invoices")
|
has_invoices = fields.Boolean(compute="_compute_has_invoices")
|
||||||
_sql_constraints = [
|
_sql_constraints = [
|
||||||
@ -241,9 +250,7 @@ class AccountLoanLine(models.Model):
|
|||||||
|
|
||||||
def move_line_vals(self):
|
def move_line_vals(self):
|
||||||
vals = []
|
vals = []
|
||||||
partner = self.loan_id.partner_id.with_context(
|
partner = self.loan_id.partner_id.with_company(self.loan_id.company_id)
|
||||||
force_company=self.loan_id.company_id.id
|
|
||||||
)
|
|
||||||
vals.append(
|
vals.append(
|
||||||
{
|
{
|
||||||
"account_id": partner.property_account_payable_id.id,
|
"account_id": partner.property_account_payable_id.id,
|
||||||
@ -287,7 +294,7 @@ class AccountLoanLine(models.Model):
|
|||||||
return {
|
return {
|
||||||
"loan_line_id": self.id,
|
"loan_line_id": self.id,
|
||||||
"loan_id": self.loan_id.id,
|
"loan_id": self.loan_id.id,
|
||||||
"type": "in_invoice",
|
"move_type": "in_invoice",
|
||||||
"partner_id": self.loan_id.partner_id.id,
|
"partner_id": self.loan_id.partner_id.id,
|
||||||
"invoice_date": self.date,
|
"invoice_date": self.date,
|
||||||
"journal_id": self.loan_id.journal_id.id,
|
"journal_id": self.loan_id.journal_id.id,
|
||||||
@ -426,7 +433,10 @@ class AccountLoanLine(models.Model):
|
|||||||
"default_loan_line_id": self.id,
|
"default_loan_line_id": self.id,
|
||||||
"default_loan_id": self.loan_id.id,
|
"default_loan_id": self.loan_id.id,
|
||||||
}
|
}
|
||||||
result["domain"] = [("loan_line_id", "=", self.id), ("type", "=", "in_invoice")]
|
result["domain"] = [
|
||||||
|
("loan_line_id", "=", self.id),
|
||||||
|
("move_type", "=", "in_invoice"),
|
||||||
|
]
|
||||||
if len(self.move_ids) == 1:
|
if len(self.move_ids) == 1:
|
||||||
res = self.env.ref("account.view_move_form", False)
|
res = self.env.ref("account.view_move_form", False)
|
||||||
result["views"] = [(res and res.id or False, "form")]
|
result["views"] = [(res and res.id or False, "form")]
|
||||||
|
@ -8,10 +8,15 @@ class AccountMove(models.Model):
|
|||||||
_inherit = "account.move"
|
_inherit = "account.move"
|
||||||
|
|
||||||
loan_line_id = fields.Many2one(
|
loan_line_id = fields.Many2one(
|
||||||
"account.loan.line", readonly=True, ondelete="restrict",
|
"account.loan.line",
|
||||||
|
readonly=True,
|
||||||
|
ondelete="restrict",
|
||||||
)
|
)
|
||||||
loan_id = fields.Many2one(
|
loan_id = fields.Many2one(
|
||||||
"account.loan", readonly=True, store=True, ondelete="restrict",
|
"account.loan",
|
||||||
|
readonly=True,
|
||||||
|
store=True,
|
||||||
|
ondelete="restrict",
|
||||||
)
|
)
|
||||||
|
|
||||||
def post(self):
|
def post(self):
|
||||||
|
@ -3,3 +3,6 @@ access_account_loan,account.loan,model_account_loan,account.group_account_user,1
|
|||||||
access_account_loan_manager,account.loan,model_account_loan,account.group_account_manager,1,1,1,1
|
access_account_loan_manager,account.loan,model_account_loan,account.group_account_manager,1,1,1,1
|
||||||
access_account_loan_line,account.loan.line,model_account_loan_line,account.group_account_user,1,0,0,0
|
access_account_loan_line,account.loan.line,model_account_loan_line,account.group_account_user,1,0,0,0
|
||||||
access_account_loan_line_manager,account.loan.line,model_account_loan_line,account.group_account_manager,1,1,1,1
|
access_account_loan_line_manager,account.loan.line,model_account_loan_line,account.group_account_manager,1,1,1,1
|
||||||
|
access_account_loan_generate_wizard,access_account_loan_generate_wizard,model_account_loan_generate_wizard,account.group_account_user,1,0,0,0
|
||||||
|
access_account_loan_pay_amount,access_account_loan_pay_amount,model_account_loan_pay_amount,account.group_account_user,1,0,0,0
|
||||||
|
access_account_loan_post,access_account_loan_post,model_account_loan_post,account.group_account_user,1,0,0,0
|
||||||
|
|
@ -215,7 +215,10 @@
|
|||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
<act_window id="account_loan_action" name="Loans" res_model="account.loan" />
|
<record id="account_loan_action" model="ir.actions.act_window">
|
||||||
|
<field name="name">Loans</field>
|
||||||
|
<field name="res_model">account.loan</field>
|
||||||
|
</record>
|
||||||
<menuitem
|
<menuitem
|
||||||
id="account_loan_menu"
|
id="account_loan_menu"
|
||||||
parent="account.menu_finance_entries"
|
parent="account.menu_finance_entries"
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<field name="model">account.move</field>
|
<field name="model">account.move</field>
|
||||||
<field name="inherit_id" ref="account.view_move_form" />
|
<field name="inherit_id" ref="account.view_move_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<field name="company_id" position="after">
|
<field name="date" position="after">
|
||||||
<field
|
<field
|
||||||
name="loan_line_id"
|
name="loan_line_id"
|
||||||
attrs="{'invisible': [('loan_line_id', '=', False)]}"
|
attrs="{'invisible': [('loan_line_id', '=', False)]}"
|
||||||
|
@ -9,14 +9,21 @@ class AccountLoan(models.TransientModel):
|
|||||||
_name = "account.loan.pay.amount"
|
_name = "account.loan.pay.amount"
|
||||||
_description = "Loan pay amount"
|
_description = "Loan pay amount"
|
||||||
|
|
||||||
loan_id = fields.Many2one("account.loan", required=True, readonly=True,)
|
loan_id = fields.Many2one(
|
||||||
|
"account.loan",
|
||||||
|
required=True,
|
||||||
|
readonly=True,
|
||||||
|
)
|
||||||
currency_id = fields.Many2one(
|
currency_id = fields.Many2one(
|
||||||
"res.currency", related="loan_id.currency_id", readonly=True
|
"res.currency", related="loan_id.currency_id", readonly=True
|
||||||
)
|
)
|
||||||
cancel_loan = fields.Boolean(default=False,)
|
cancel_loan = fields.Boolean(
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
date = fields.Date(required=True, default=fields.Date.today())
|
date = fields.Date(required=True, default=fields.Date.today())
|
||||||
amount = fields.Monetary(
|
amount = fields.Monetary(
|
||||||
currency_field="currency_id", string="Amount to reduce from Principal",
|
currency_field="currency_id",
|
||||||
|
string="Amount to reduce from Principal",
|
||||||
)
|
)
|
||||||
fees = fields.Monetary(currency_field="currency_id", string="Bank fees")
|
fees = fields.Monetary(currency_field="currency_id", string="Bank fees")
|
||||||
|
|
||||||
|
@ -22,11 +22,15 @@ class AccountLoanPost(models.TransientModel):
|
|||||||
if loan.is_leasing:
|
if loan.is_leasing:
|
||||||
return loan.leased_asset_account_id.id
|
return loan.leased_asset_account_id.id
|
||||||
else:
|
else:
|
||||||
return loan.partner_id.with_context(
|
return loan.partner_id.with_company(
|
||||||
force_company=loan.company_id.id
|
loan.company_id
|
||||||
).property_account_receivable_id.id
|
).property_account_receivable_id.id
|
||||||
|
|
||||||
loan_id = fields.Many2one("account.loan", required=True, readonly=True,)
|
loan_id = fields.Many2one(
|
||||||
|
"account.loan",
|
||||||
|
required=True,
|
||||||
|
readonly=True,
|
||||||
|
)
|
||||||
journal_id = fields.Many2one(
|
journal_id = fields.Many2one(
|
||||||
"account.journal", required=True, default=lambda r: r._default_journal_id()
|
"account.journal", required=True, default=lambda r: r._default_journal_id()
|
||||||
)
|
)
|
||||||
@ -36,9 +40,7 @@ class AccountLoanPost(models.TransientModel):
|
|||||||
|
|
||||||
def move_line_vals(self):
|
def move_line_vals(self):
|
||||||
res = list()
|
res = list()
|
||||||
partner = self.loan_id.partner_id.with_context(
|
partner = self.loan_id.partner_id.with_company(self.loan_id.company_id)
|
||||||
force_company=self.loan_id.company_id.id
|
|
||||||
)
|
|
||||||
line = self.loan_id.line_ids.filtered(lambda r: r.sequence == 1)
|
line = self.loan_id.line_ids.filtered(lambda r: r.sequence == 1)
|
||||||
res.append(
|
res.append(
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user