mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
[MIG] account_loan: Migration to 17.0
This commit is contained in:
committed by
Víctor Martínez
parent
0934587e07
commit
539827a322
@@ -2,7 +2,7 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
{
|
||||
"name": "Account Loan management",
|
||||
"version": "16.0.1.0.5",
|
||||
"version": "17.0.1.0.0",
|
||||
"author": "Creu Blanca,Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/account-financial-tools",
|
||||
"license": "AGPL-3",
|
||||
|
||||
@@ -29,7 +29,6 @@ class AccountLoan(models.Model):
|
||||
required=True,
|
||||
readonly=True,
|
||||
default="/",
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
partner_id = fields.Many2one(
|
||||
"res.partner",
|
||||
@@ -37,14 +36,12 @@ class AccountLoan(models.Model):
|
||||
string="Lender",
|
||||
help="Company or individual that lends the money at an interest rate.",
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
company_id = fields.Many2one(
|
||||
"res.company",
|
||||
required=True,
|
||||
default=_default_company,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
state = fields.Selection(
|
||||
[
|
||||
@@ -66,7 +63,6 @@ class AccountLoan(models.Model):
|
||||
periods = fields.Integer(
|
||||
required=True,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
help="Number of periods that the loan will last",
|
||||
)
|
||||
method_period = fields.Integer(
|
||||
@@ -75,12 +71,10 @@ class AccountLoan(models.Model):
|
||||
help="State here the time between 2 depreciations, in months",
|
||||
required=True,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
start_date = fields.Date(
|
||||
help="Start of the moves",
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
copy=False,
|
||||
)
|
||||
rate = fields.Float(
|
||||
@@ -101,7 +95,6 @@ class AccountLoan(models.Model):
|
||||
help="Method of computation of the applied rate",
|
||||
default="napr",
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
loan_type = fields.Selection(
|
||||
[
|
||||
@@ -113,7 +106,6 @@ class AccountLoan(models.Model):
|
||||
required=True,
|
||||
help="Method of computation of the period annuity",
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
default="fixed-annuity",
|
||||
)
|
||||
fixed_amount = fields.Monetary(
|
||||
@@ -135,14 +127,12 @@ class AccountLoan(models.Model):
|
||||
currency_field="currency_id",
|
||||
required=True,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
residual_amount = fields.Monetary(
|
||||
currency_field="currency_id",
|
||||
default=0.0,
|
||||
required=True,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
help="Residual amount of the lease that must be payed on the end in "
|
||||
"order to acquire the asset",
|
||||
)
|
||||
@@ -152,12 +142,10 @@ class AccountLoan(models.Model):
|
||||
", if it is unchecked, the annuity will be recalculated on each "
|
||||
"period.",
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
payment_on_first_period = fields.Boolean(
|
||||
default=False,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
help="When checked, the first payment will be on start date",
|
||||
)
|
||||
currency_id = fields.Many2one(
|
||||
@@ -171,7 +159,6 @@ class AccountLoan(models.Model):
|
||||
domain="[('company_id', '=', company_id),('type', '=', journal_type)]",
|
||||
required=True,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
short_term_loan_account_id = fields.Many2one(
|
||||
"account.account",
|
||||
@@ -180,7 +167,6 @@ class AccountLoan(models.Model):
|
||||
help="Account that will contain the pending amount on short term",
|
||||
required=True,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
long_term_loan_account_id = fields.Many2one(
|
||||
"account.account",
|
||||
@@ -188,7 +174,6 @@ class AccountLoan(models.Model):
|
||||
help="Account that will contain the pending amount on Long term",
|
||||
domain="[('company_id', '=', company_id)]",
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
interest_expenses_account_id = fields.Many2one(
|
||||
"account.account",
|
||||
@@ -197,18 +182,15 @@ class AccountLoan(models.Model):
|
||||
help="Account where the interests will be assigned to",
|
||||
required=True,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
is_leasing = fields.Boolean(
|
||||
default=False,
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
leased_asset_account_id = fields.Many2one(
|
||||
"account.account",
|
||||
domain="[('company_id', '=', company_id)]",
|
||||
readonly=True,
|
||||
states={"draft": [("readonly", False)]},
|
||||
)
|
||||
product_id = fields.Many2one(
|
||||
"product.product",
|
||||
@@ -400,7 +382,7 @@ class AccountLoan(models.Model):
|
||||
date = line.date + relativedelta(months=12)
|
||||
if self.state == "draft" or line.sequence != final_sequence:
|
||||
line.long_term_pending_principal_amount = sum(
|
||||
self.line_ids.filtered(lambda r: r.date >= date).mapped(
|
||||
self.line_ids.filtered(lambda r, date=date: r.date >= date).mapped(
|
||||
"principal_amount"
|
||||
)
|
||||
)
|
||||
@@ -452,7 +434,7 @@ class AccountLoan(models.Model):
|
||||
def view_account_invoices(self):
|
||||
self.ensure_one()
|
||||
result = self.env["ir.actions.act_window"]._for_xml_id(
|
||||
"account.action_move_out_invoice_type"
|
||||
"account.action_move_in_invoice_type"
|
||||
)
|
||||
result["domain"] = [("loan_id", "=", self.id), ("move_type", "=", "in_invoice")]
|
||||
return result
|
||||
|
||||
@@ -363,7 +363,7 @@ class AccountLoanLine(models.Model):
|
||||
for record in self:
|
||||
if not record.move_ids:
|
||||
if record.loan_id.line_ids.filtered(
|
||||
lambda r: r.date < record.date and not r.move_ids
|
||||
lambda r, record=record: r.date < record.date and not r.move_ids
|
||||
):
|
||||
raise UserError(_("Some moves must be created first"))
|
||||
move = self.env["account.move"].create(
|
||||
@@ -394,7 +394,7 @@ class AccountLoanLine(models.Model):
|
||||
for record in self:
|
||||
if not record.move_ids:
|
||||
if record.loan_id.line_ids.filtered(
|
||||
lambda r: r.date < record.date and not r.move_ids
|
||||
lambda r, record=record: r.date < record.date and not r.move_ids
|
||||
):
|
||||
raise UserError(_("Some invoices must be created first"))
|
||||
invoice = self.env["account.move"].create(record._invoice_vals())
|
||||
@@ -404,7 +404,7 @@ class AccountLoanLine(models.Model):
|
||||
invoice.flush_recordset()
|
||||
invoice.filtered(
|
||||
lambda m: m.currency_id.round(m.amount_total) < 0
|
||||
).action_switch_invoice_into_refund_credit_note()
|
||||
).action_switch_move_type()
|
||||
if record.loan_id.post_invoice:
|
||||
invoice.action_post()
|
||||
if (
|
||||
|
||||
@@ -16,31 +16,31 @@
|
||||
<field name="interests_amount" sum="Total interests" />
|
||||
<field
|
||||
name="long_term_pending_principal_amount"
|
||||
attrs="{'invisible': [('long_term_loan_account_id', '=', False)]}"
|
||||
column_invisible="not parent.long_term_loan_account_id"
|
||||
/>
|
||||
<field
|
||||
name="long_term_principal_amount"
|
||||
attrs="{'invisible': [('long_term_loan_account_id', '=', False)]}"
|
||||
column_invisible="not parent.long_term_loan_account_id"
|
||||
/>
|
||||
<field name="long_term_loan_account_id" invisible="1" />
|
||||
<field name="loan_state" invisible="1" />
|
||||
<field name="is_leasing" invisible="1" />
|
||||
<field name="has_invoices" invisible="1" />
|
||||
<field name="has_moves" invisible="1" />
|
||||
<field name="currency_id" invisible="1" />
|
||||
<field name="long_term_loan_account_id" column_invisible="True" />
|
||||
<field name="loan_state" column_invisible="True" />
|
||||
<field name="is_leasing" column_invisible="True" />
|
||||
<field name="has_invoices" column_invisible="True" />
|
||||
<field name="has_moves" column_invisible="True" />
|
||||
<field name="currency_id" column_invisible="True" />
|
||||
<button
|
||||
name="view_account_values"
|
||||
string="Values"
|
||||
type="object"
|
||||
icon="fa-eye"
|
||||
attrs="{'invisible': [('has_moves', '=', False), ('has_invoices', '=', False)]}"
|
||||
invisible="has_moves == False and has_invoices == False"
|
||||
/>
|
||||
<button
|
||||
name="view_process_values"
|
||||
string="Process"
|
||||
type="object"
|
||||
icon="fa-cogs"
|
||||
attrs="{'invisible': ['|', '|', ('has_moves', '=', True), ('has_invoices', '=', True), ('loan_state', '!=', 'posted')]}"
|
||||
invisible="has_moves == True or has_invoices == True or loan_state != 'posted'"
|
||||
/>
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
<button name="compute_lines" type="object" string="Compute items" />
|
||||
<button
|
||||
name="%(account_loan_post_action)d"
|
||||
states="draft"
|
||||
invisible="state != 'draft'"
|
||||
type="action"
|
||||
string="Post"
|
||||
groups="account.group_account_manager"
|
||||
@@ -54,7 +54,7 @@
|
||||
name="view_account_moves"
|
||||
class="oe_stat_button"
|
||||
icon="fa-bars"
|
||||
attrs="{'invisible': [('state', '=', 'draft')]}"
|
||||
invisible="state == 'draft'"
|
||||
type="object"
|
||||
string="Moves"
|
||||
/>
|
||||
@@ -62,7 +62,7 @@
|
||||
name="view_account_invoices"
|
||||
class="oe_stat_button"
|
||||
icon="fa-pencil-square-o"
|
||||
attrs="{'invisible': ['|', ('state', '=', 'draft'), ('is_leasing', '=', False)]}"
|
||||
invisible="state == 'draft' or is_leasing == False"
|
||||
type="object"
|
||||
string="Invoices"
|
||||
/>
|
||||
@@ -70,7 +70,7 @@
|
||||
name="%(account_loan_pay_amount_action)d"
|
||||
class="oe_stat_button"
|
||||
icon="fa-arrow-down"
|
||||
attrs="{'invisible': [('state', '!=', 'posted')]}"
|
||||
invisible="state != 'posted'"
|
||||
type="action"
|
||||
groups="account.group_account_manager"
|
||||
>
|
||||
@@ -83,7 +83,7 @@
|
||||
name="%(account_loan_increase_amount_act_window)d"
|
||||
class="oe_stat_button"
|
||||
icon="fa-arrow-up"
|
||||
attrs="{'invisible': [('state', '!=', 'posted')]}"
|
||||
invisible="state != 'posted'"
|
||||
type="action"
|
||||
groups="account.group_account_manager"
|
||||
>
|
||||
@@ -94,34 +94,41 @@
|
||||
</button>
|
||||
</div>
|
||||
<h1>
|
||||
<field name="name" />
|
||||
<field name="name" readonly="state != 'draft'" />
|
||||
</h1>
|
||||
<group>
|
||||
<group>
|
||||
<field name="company_id" options="{'no_create': True}" />
|
||||
<field name="loan_type" />
|
||||
<field name="loan_amount" />
|
||||
<field
|
||||
name="company_id"
|
||||
options="{'no_create': True}"
|
||||
readonly="state != 'draft'"
|
||||
/>
|
||||
<field name="loan_type" readonly="state != 'draft'" />
|
||||
<field name="loan_amount" readonly="state != 'draft'" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="rate_type" />
|
||||
<field name="rate_type" readonly="state != 'draft'" />
|
||||
<field name="rate" />
|
||||
<field name="rate_period" />
|
||||
</group>
|
||||
</group>
|
||||
<group>
|
||||
<group>
|
||||
<field name="partner_id" />
|
||||
<field name="start_date" />
|
||||
<field name="periods" />
|
||||
<field name="method_period" />
|
||||
<field name="partner_id" readonly="state != 'draft'" />
|
||||
<field name="start_date" readonly="state != 'draft'" />
|
||||
<field name="periods" readonly="state != 'draft'" />
|
||||
<field name="method_period" readonly="state != 'draft'" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="is_leasing" />
|
||||
<field name="round_on_end" />
|
||||
<field name="payment_on_first_period" />
|
||||
<field name="is_leasing" readonly="state != 'draft'" />
|
||||
<field name="round_on_end" readonly="state != 'draft'" />
|
||||
<field
|
||||
name="payment_on_first_period"
|
||||
readonly="state != 'draft'"
|
||||
/>
|
||||
</group>
|
||||
</group>
|
||||
<group attrs="{'invisible':[('state', '=', 'draft')]}">
|
||||
<group invisible="state == 'draft'">
|
||||
<group>
|
||||
<field name="pending_principal_amount" />
|
||||
<field name="payment_amount" />
|
||||
@@ -138,13 +145,25 @@
|
||||
<page string="Accounts" id="accounting">
|
||||
<group>
|
||||
<group>
|
||||
<field name="journal_id" />
|
||||
<field name="short_term_loan_account_id" />
|
||||
<field
|
||||
name="journal_id"
|
||||
readonly="state != 'draft'"
|
||||
/>
|
||||
<field
|
||||
name="short_term_loan_account_id"
|
||||
readonly="state != 'draft'"
|
||||
/>
|
||||
<field name="journal_type" invisible="1" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="long_term_loan_account_id" />
|
||||
<field name="interest_expenses_account_id" />
|
||||
<field
|
||||
name="long_term_loan_account_id"
|
||||
readonly="state != 'draft'"
|
||||
/>
|
||||
<field
|
||||
name="interest_expenses_account_id"
|
||||
readonly="state != 'draft'"
|
||||
/>
|
||||
<field name="currency_id" invisible="1" />
|
||||
</group>
|
||||
</group>
|
||||
@@ -152,24 +171,28 @@
|
||||
<page
|
||||
string="Leasing"
|
||||
id="leasing"
|
||||
attrs="{'invisible': [('is_leasing', '=', False)]}"
|
||||
invisible="is_leasing == False"
|
||||
>
|
||||
<group>
|
||||
<group>
|
||||
<field
|
||||
name="leased_asset_account_id"
|
||||
attrs="{'required': [('is_leasing', '=', True)]}"
|
||||
required="is_leasing == True"
|
||||
readonly="state != 'draft'"
|
||||
/>
|
||||
<field
|
||||
name="residual_amount"
|
||||
readonly="state != 'draft'"
|
||||
/>
|
||||
<field name="residual_amount" />
|
||||
</group>
|
||||
<group>
|
||||
<field
|
||||
name="product_id"
|
||||
attrs="{'required': [('is_leasing', '=', True)]}"
|
||||
required="is_leasing == True"
|
||||
/>
|
||||
<field
|
||||
name="interests_product_id"
|
||||
attrs="{'required': [('is_leasing', '=', True)]}"
|
||||
required="is_leasing == True"
|
||||
/>
|
||||
<field name="post_invoice" />
|
||||
</group>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<field name="date" position="after">
|
||||
<field
|
||||
name="loan_line_id"
|
||||
attrs="{'invisible': [('loan_line_id', '=', False)]}"
|
||||
invisible="loan_line_id == False"
|
||||
readonly="True"
|
||||
/>
|
||||
</field>
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
icon="fa-money"
|
||||
name="action_view_partner_lended_loans"
|
||||
groups="account.group_account_user"
|
||||
context="{'default_partner_id': active_id}"
|
||||
attrs="{'invisible': [('lended_loan_count','=', 0)]}"
|
||||
context="{'default_partner_id': id}"
|
||||
invisible="lended_loan_count == 0"
|
||||
>
|
||||
<div class="o_form_field o_stat_info">
|
||||
<span class="o_stat_value">
|
||||
|
||||
Reference in New Issue
Block a user