-
-
Notifications
You must be signed in to change notification settings - Fork 369
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD]account_analytic_ap_ar and recompute_payment_terms_lines_hook
- Loading branch information
1 parent
dd095b9
commit b604b0c
Showing
26 changed files
with
1,525 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,84 @@ | ||
====================== | ||
Account Analytic AP AR | ||
====================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:fb63d2b7431710a81e8024d2ffeb62efa6b45e12efbacb39a7c050b229bbc007 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount_analytic-lightgray.png?logo=github | ||
:target: https://github.com/OCA/account_analytic/tree/15.0/account_analytic_ap_ar | ||
:alt: OCA/account_analytic | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/account_analytic-15-0/account_analytic-15-0-account_analytic_ap_ar | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/account_analytic&target_branch=15.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module split receivable and payable journal items by analytic account. | ||
This is required in companies managed by projects where the invoices involve | ||
different projects. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Known issues / Roadmap | ||
====================== | ||
|
||
The tax receivable line goes to the last invoice line. If required to | ||
be distributed among all the lines then you have to distribute it somehow | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/account_analytic/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/account_analytic/issues/new?body=module:%20account_analytic_ap_ar%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* ForgeFLow | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* Aaron Henriquez <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
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. | ||
|
||
This module is part of the `OCA/account_analytic <https://github.com/OCA/account_analytic/tree/15.0/account_analytic_ap_ar>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 2023 ForgeFlow S.L. | ||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
||
{ | ||
"name": "Account Analytic AP AR", | ||
"version": "15.0.1.0.0", | ||
"category": "Analytic Accounting", | ||
"summary": "Adds the analytic account in the receivable and payable journal " | ||
"items", | ||
"author": "ForgeFLow," "Odoo Community Association (OCA)", | ||
"maintainer": "OCA", | ||
"website": "https://github.com/OCA/account-analytic", | ||
"license": "LGPL-3", | ||
"depends": ["account", "recompute_payment_terms_lines_hook"], | ||
"installable": True, | ||
} |
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 account_move |
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,158 @@ | ||
# Copyright 2021 Tecnativa Víctor Martínez | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
|
||
from odoo import models | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
def get_candidate_vals_update(self, date_maturity, amount_currency, balance): | ||
res = super().get_candidate_vals_update(date_maturity, amount_currency, balance) | ||
analytic_account = self.env.context.get("analytic_account", False) | ||
if analytic_account: | ||
res.update(analytic_account_id=analytic_account.id) | ||
else: | ||
res.update(analytic_account_id=False) | ||
return res | ||
|
||
def get_payment_term_candidate_vals( | ||
self, balance, amount_currency, date_maturity, account | ||
): | ||
candidate = super().get_payment_term_candidate_vals( | ||
balance, amount_currency, date_maturity, account | ||
) | ||
analytic_account = self.env.context.get("analytic_account", False) | ||
if analytic_account: | ||
candidate.update(analytic_account_id=analytic_account.id) | ||
else: | ||
candidate.update(analytic_account_id=False) | ||
return candidate | ||
|
||
def post_process_term_lines( | ||
self, | ||
_get_payment_terms_computation_date, | ||
_get_payment_terms_account, | ||
_compute_payment_terms, | ||
_compute_diff_payment_terms_lines, | ||
): | ||
analytic_model = self.env["account.analytic.account"] | ||
new_terms_lines = False | ||
if self: | ||
all_analytic_ids = self.invoice_line_ids.mapped("analytic_account_id").ids | ||
if not all_analytic_ids: | ||
return super().post_process_term_lines( | ||
_get_payment_terms_computation_date, | ||
_get_payment_terms_account, | ||
_compute_payment_terms, | ||
_compute_diff_payment_terms_lines, | ||
) | ||
else: | ||
all_analytic_accounts = [ | ||
analytic_model.browse(aid) for aid in all_analytic_ids | ||
] | ||
if len( | ||
self.invoice_line_ids.filtered( | ||
lambda l: l.analytic_account_id == analytic_model | ||
) | ||
): | ||
all_analytic_accounts.insert(0, analytic_model) | ||
else: | ||
return super().post_process_term_lines( | ||
_get_payment_terms_computation_date, | ||
_get_payment_terms_account, | ||
_compute_payment_terms, | ||
_compute_diff_payment_terms_lines, | ||
) | ||
for aa in all_analytic_accounts: | ||
existing_terms_lines = self.line_ids.filtered( | ||
lambda line: line.account_id.user_type_id.type | ||
in ("receivable", "payable") | ||
and ( | ||
line.analytic_account_id == aa | ||
or line.analytic_account_id not in all_analytic_accounts | ||
) | ||
) # last condition is corner case for removed analytic accounts | ||
others_lines = ( | ||
self.line_ids.filtered( | ||
lambda line: line.account_id.user_type_id.type | ||
not in ("receivable", "payable") | ||
and line.analytic_account_id == aa | ||
).filtered(lambda l: l.analytic_account_id in all_analytic_accounts) | ||
- existing_terms_lines | ||
) | ||
company_currency_id = (self.company_id or self.env.company).currency_id | ||
total_balance = sum( | ||
others_lines.mapped(lambda l: company_currency_id.round(l.balance)) | ||
) | ||
total_amount_currency = sum(others_lines.mapped("amount_currency")) | ||
|
||
if not others_lines: | ||
self.line_ids -= existing_terms_lines | ||
existing_terms_lines = self.line_ids.filtered( | ||
lambda line: line.account_id.user_type_id.type | ||
in ("receivable", "payable") | ||
) | ||
others_lines = self.line_ids.filtered( | ||
lambda line: line.account_id.user_type_id.type | ||
not in ("receivable", "payable") | ||
) | ||
company_currency_id = (self.company_id or self.env.company).currency_id | ||
total_balance = sum( | ||
others_lines.mapped(lambda l: company_currency_id.round(l.balance)) | ||
) | ||
total_amount_currency = sum(others_lines.mapped("amount_currency")) | ||
|
||
if not others_lines: | ||
self.line_ids -= existing_terms_lines | ||
return | ||
|
||
computation_date = _get_payment_terms_computation_date(self) | ||
account = _get_payment_terms_account(self, existing_terms_lines) | ||
to_compute = _compute_payment_terms( | ||
self, computation_date, total_balance, total_amount_currency | ||
) | ||
new_terms_lines = _compute_diff_payment_terms_lines( | ||
self.with_context(analytic_account=aa), | ||
existing_terms_lines, | ||
account, | ||
to_compute, | ||
) | ||
|
||
# Remove old terms lines that are no longer needed. | ||
self.line_ids -= existing_terms_lines - new_terms_lines | ||
|
||
if new_terms_lines: | ||
self.payment_reference = new_terms_lines[-1].name or "" | ||
self.invoice_date_due = new_terms_lines[-1].date_maturity | ||
continue | ||
|
||
computation_date = _get_payment_terms_computation_date(self) | ||
account = _get_payment_terms_account(self, existing_terms_lines) | ||
to_compute = _compute_payment_terms( | ||
self, computation_date, total_balance, total_amount_currency | ||
) | ||
|
||
if new_terms_lines: | ||
new_terms_lines += _compute_diff_payment_terms_lines( | ||
self.with_context(analytic_account=aa), | ||
existing_terms_lines, | ||
account, | ||
to_compute, | ||
) | ||
else: | ||
new_terms_lines = _compute_diff_payment_terms_lines( | ||
self.with_context(analytic_account=aa), | ||
existing_terms_lines, | ||
account, | ||
to_compute, | ||
) | ||
|
||
# Remove old terms lines that are no longer needed. | ||
self.line_ids -= existing_terms_lines - new_terms_lines | ||
|
||
if new_terms_lines: | ||
self.payment_reference = new_terms_lines[-1].name or "" | ||
self.invoice_date_due = new_terms_lines[-1].date_maturity | ||
return True |
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 @@ | ||
* Aaron Henriquez <[email protected]> |
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,3 @@ | ||
This module split receivable and payable journal items by analytic account. | ||
This is required in companies managed by projects where the invoices involve | ||
different projects. |
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 @@ | ||
The tax receivable line goes to the last invoice line. If required to | ||
be distributed among all the lines then you have to distribute it somehow |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.