-
-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[16.0][IMP] account-financial-tools: ADD account_loan_analytic_account
This module allows to add analytic distributions on loans and propagate them to moves when the loan is posted
- Loading branch information
1 parent
3247de9
commit daa9e53
Showing
12 changed files
with
286 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
|
||
============================= | ||
Account Loan Analytic Account | ||
============================= | ||
|
||
Add analytic distributions on account loan | ||
|
||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues | ||
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please | ||
check there if your issue has already been reported. If you spotted it first, | ||
help us smash it by providing detailed and welcomed feedback. | ||
|
||
Credits | ||
======= | ||
|
||
Images | ||
------ | ||
|
||
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. | ||
|
||
Contributors | ||
------------ | ||
|
||
* Lindsay Marion <[email protected]> | ||
|
||
|
||
Maintainer | ||
---------- | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
This module is maintained by the OCA. | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
To contribute to this module, please visit https://odoo-community.org. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Account Loan Analytic Account", | ||
"summary": """ | ||
Add analytic distributions on account loan""", | ||
"version": "16.0.1.0.0", | ||
"website": "https://github.com/OCA/account-financial-tools", | ||
"license": "AGPL-3", | ||
"author": "ACSONE SA/NV,Odoo Community Association (OCA)", | ||
"depends": ["account_loan", "analytic"], | ||
"data": [ | ||
"views/account_loan.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import account_loan | ||
from . import account_move_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import models | ||
|
||
|
||
class AccountLoan(models.Model): | ||
_name = "account.loan" | ||
_inherit = ["account.loan", "analytic.mixin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class AccountMoveLine(models.Model): | ||
|
||
_inherit = "account.move.line" | ||
|
||
loan_id = fields.Many2one( | ||
related="move_id.loan_id", | ||
store=True, | ||
) | ||
|
||
@api.depends("loan_id", "loan_id.analytic_distribution") | ||
def _compute_analytic_distribution(self): | ||
res = super()._compute_analytic_distribution() | ||
for rec in self: | ||
if rec.loan_id and rec.loan_id.analytic_distribution: | ||
if rec.account_id.id == rec.loan_id.interest_expenses_account_id.id: | ||
rec.analytic_distribution = rec.loan_id.analytic_distribution | ||
return res |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_account_loan_analytic_account |
161 changes: 161 additions & 0 deletions
161
account_loan_analytic_account/tests/test_account_loan_analytic_account.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
# Copyright 2024 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestAccountLoanAnalyticAccount(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.company = cls.env.ref("base.main_company") | ||
cls.company_02 = cls.env["res.company"].create({"name": "Auxiliar company"}) | ||
cls.journal = cls.env["account.journal"].create( | ||
{ | ||
"company_id": cls.company.id, | ||
"type": "purchase", | ||
"name": "Debts", | ||
"code": "DBT", | ||
} | ||
) | ||
cls.loan_account = cls.create_account( | ||
"DEP", | ||
"depreciation", | ||
"liability_current", | ||
) | ||
cls.payable_account = cls.create_account("PAY", "payable", "liability_payable") | ||
cls.asset_account = cls.create_account("ASSET", "asset", "liability_payable") | ||
cls.interests_account = cls.create_account("FEE", "Fees", "expense") | ||
cls.lt_loan_account = cls.create_account( | ||
"LTD", | ||
"Long term depreciation", | ||
"liability_non_current", | ||
) | ||
cls.partner = cls.env["res.partner"].create({"name": "Bank"}) | ||
cls.product = cls.env["product.product"].create( | ||
{"name": "Payment", "type": "service"} | ||
) | ||
cls.interests_product = cls.env["product.product"].create( | ||
{"name": "Bank fee", "type": "service"} | ||
) | ||
cls.env.user.groups_id += cls.env.ref("analytic.group_analytic_accounting") | ||
|
||
cls.default_plan = cls.env["account.analytic.plan"].create( | ||
{"name": "Default", "company_id": False} | ||
) | ||
cls.analytic_account_a = cls.env["account.analytic.account"].create( | ||
{ | ||
"name": "analytic_account_a", | ||
"plan_id": cls.default_plan.id, | ||
"company_id": False, | ||
} | ||
) | ||
cls.analytic_account_b = cls.env["account.analytic.account"].create( | ||
{ | ||
"name": "analytic_account_b", | ||
"plan_id": cls.default_plan.id, | ||
"company_id": False, | ||
} | ||
) | ||
cls.analytic_account_c = cls.env["account.analytic.account"].create( | ||
{ | ||
"name": "analytic_account_c", | ||
"plan_id": cls.default_plan.id, | ||
"company_id": False, | ||
} | ||
) | ||
|
||
cls.loan = cls.create_loan("fixed-annuity", 500000, 1, 60) | ||
|
||
@classmethod | ||
def create_account(cls, code, name, account_type): | ||
return cls.env["account.account"].create( | ||
{ | ||
"company_id": cls.company.id, | ||
"name": name, | ||
"code": code, | ||
"account_type": account_type, | ||
"reconcile": True, | ||
} | ||
) | ||
|
||
@classmethod | ||
def create_loan(cls, type_loan, amount, rate, periods): | ||
loan = cls.env["account.loan"].create( | ||
{ | ||
"journal_id": cls.journal.id, | ||
"rate_type": "napr", | ||
"loan_type": type_loan, | ||
"loan_amount": amount, | ||
"payment_on_first_period": True, | ||
"rate": rate, | ||
"periods": periods, | ||
"leased_asset_account_id": cls.asset_account.id, | ||
"short_term_loan_account_id": cls.loan_account.id, | ||
"interest_expenses_account_id": cls.interests_account.id, | ||
"product_id": cls.product.id, | ||
"interests_product_id": cls.interests_product.id, | ||
"partner_id": cls.partner.id, | ||
"analytic_distribution": { | ||
cls.analytic_account_a.id: 50, | ||
cls.analytic_account_b.id: 50, | ||
}, | ||
} | ||
) | ||
loan.compute_lines() | ||
return loan | ||
|
||
def test_analytic_account_propagates_to_moves(self): | ||
post = ( | ||
self.env["account.loan.post"] | ||
.with_context(default_loan_id=self.loan.id) | ||
.create({}) | ||
) | ||
post.run() | ||
|
||
self.assertTrue(self.loan.move_ids) | ||
|
||
loan_line = self.loan.line_ids.filtered(lambda r: r.sequence == 1) | ||
loan_line.view_process_values() | ||
move_lines = loan_line.move_ids.mapped("line_ids") | ||
self.assertTrue(loan_line.move_ids) | ||
for line in move_lines: | ||
if line.account_id == self.loan.interest_expenses_account_id: | ||
self.assertEqual( | ||
line.analytic_distribution, self.loan.analytic_distribution | ||
) | ||
|
||
def test_analytic_account_propagates_to_moves_after_validation(self): | ||
post = ( | ||
self.env["account.loan.post"] | ||
.with_context(default_loan_id=self.loan.id) | ||
.create({}) | ||
) | ||
post.run() | ||
|
||
self.assertTrue(self.loan.move_ids) | ||
|
||
loan_line = self.loan.line_ids.filtered(lambda r: r.sequence == 1) | ||
loan_line.view_process_values() | ||
move_lines = loan_line.move_ids.mapped("line_ids") | ||
self.assertTrue(loan_line.move_ids) | ||
self.loan.write( | ||
{ | ||
"analytic_distribution": { | ||
self.analytic_account_a.id: 50, | ||
self.analytic_account_c.id: 50, | ||
}, | ||
} | ||
) | ||
for line in move_lines: | ||
if line.account_id == self.loan.interest_expenses_account_id: | ||
self.assertEqual( | ||
line.analytic_distribution, self.loan.analytic_distribution | ||
) | ||
self.assertEqual( | ||
line.analytic_distribution, | ||
{ | ||
str(self.analytic_account_a.id): 50, | ||
str(self.analytic_account_c.id): 50, | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<!-- Copyright 2024 ACSONE SA/NV | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
<record model="ir.ui.view" id="account_loan_form_view"> | ||
<field name="name">account.loan.form (in account_loan_analytic_account)</field> | ||
<field name="model">account.loan</field> | ||
<field name="inherit_id" ref="account_loan.account_loan_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="payment_on_first_period" position="after"> | ||
<field | ||
name="analytic_distribution" | ||
widget="analytic_distribution" | ||
groups="analytic.group_analytic_accounting" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |
1 change: 1 addition & 0 deletions
1
setup/account_loan_analytic_account/odoo/addons/account_loan_analytic_account
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../account_loan_analytic_account |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |