account-financial-reporting/account_tax_balance/models/account_move.py

55 lines
1.9 KiB
Python
Raw Permalink Normal View History

2021-03-12 16:20:48 +00:00
# Copyright 2016 Antonio Espinosa <antonio.espinosa@tecnativa.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
2021-10-31 03:10:22 +00:00
from flectra import _, api, fields, models
2021-03-12 16:20:48 +00:00
class AccountMove(models.Model):
_inherit = "account.move"
@api.model
def _selection_financial_type(self):
return [
2021-10-31 03:10:22 +00:00
("other", _("Other")),
("liquidity", _("Liquidity")),
("receivable", _("Receivable")),
("receivable_refund", _("Receivable refund")),
("payable", _("Payable")),
("payable_refund", _("Payable refund")),
2021-03-12 16:20:48 +00:00
]
financial_type = fields.Selection(
selection="_selection_financial_type",
compute="_compute_financial_type",
store=True,
readonly=True,
)
@api.depends(
"line_ids.account_id.internal_type",
"line_ids.balance",
"line_ids.account_id.user_type_id.type",
)
def _compute_financial_type(self):
def _balance_get(line_ids, internal_type):
return sum(
line_ids.filtered(
lambda x: x.account_id.internal_type == internal_type
).mapped("balance")
)
for move in self:
internal_types = move.line_ids.mapped("account_id.internal_type")
if "liquidity" in internal_types:
move.financial_type = "liquidity"
elif "payable" in internal_types:
balance = _balance_get(move.line_ids, "payable")
2023-05-19 08:19:18 +00:00
move.financial_type = "payable" if balance <= 0 else "payable_refund"
2021-03-12 16:20:48 +00:00
elif "receivable" in internal_types:
balance = _balance_get(move.line_ids, "receivable")
move.financial_type = (
2023-05-19 08:19:18 +00:00
"receivable" if balance >= 0 else "receivable_refund"
2021-03-12 16:20:48 +00:00
)
else:
move.financial_type = "other"