[MIG] account_tax_balance: Migration to 14.0

This commit is contained in:
Francisco Ivan Anton Prieto
2020-10-23 15:30:27 +02:00
committed by Borruso
parent 54339092f3
commit 9fbb756b87
13 changed files with 115 additions and 65 deletions

View File

@@ -8,7 +8,7 @@ class AccountMove(models.Model):
_inherit = "account.move"
@api.model
def _selection_move_type(self):
def _selection_financial_type(self):
return [
("other", "Other"),
("liquidity", "Liquidity"),
@@ -18,9 +18,9 @@ class AccountMove(models.Model):
("payable_refund", "Payable refund"),
]
move_type = fields.Selection(
selection="_selection_move_type",
compute="_compute_move_type",
financial_type = fields.Selection(
selection="_selection_financial_type",
compute="_compute_financial_type",
store=True,
readonly=True,
)
@@ -30,7 +30,7 @@ class AccountMove(models.Model):
"line_ids.balance",
"line_ids.account_id.user_type_id.type",
)
def _compute_move_type(self):
def _compute_financial_type(self):
def _balance_get(line_ids, internal_type):
return sum(
line_ids.filtered(
@@ -41,12 +41,14 @@ class AccountMove(models.Model):
for move in self:
internal_types = move.line_ids.mapped("account_id.internal_type")
if "liquidity" in internal_types:
move.move_type = "liquidity"
move.financial_type = "liquidity"
elif "payable" in internal_types:
balance = _balance_get(move.line_ids, "payable")
move.move_type = "payable" if balance < 0 else "payable_refund"
move.financial_type = "payable" if balance < 0 else "payable_refund"
elif "receivable" in internal_types:
balance = _balance_get(move.line_ids, "receivable")
move.move_type = "receivable" if balance > 0 else "receivable_refund"
move.financial_type = (
"receivable" if balance > 0 else "receivable_refund"
)
else:
move.move_type = "other"
move.financial_type = "other"

View File

@@ -86,24 +86,24 @@ class AccountTax(models.Model):
def _compute_balance(self):
for tax in self:
tax.balance_regular = tax.compute_balance(
tax_or_base="tax", move_type="regular"
tax_or_base="tax", financial_type="regular"
)
tax.base_balance_regular = tax.compute_balance(
tax_or_base="base", move_type="regular"
tax_or_base="base", financial_type="regular"
)
tax.balance_refund = tax.compute_balance(
tax_or_base="tax", move_type="refund"
tax_or_base="tax", financial_type="refund"
)
tax.base_balance_refund = tax.compute_balance(
tax_or_base="base", move_type="refund"
tax_or_base="base", financial_type="refund"
)
tax.balance = tax.balance_regular + tax.balance_refund
tax.base_balance = tax.base_balance_regular + tax.base_balance_refund
def get_target_type_list(self, move_type=None):
if move_type == "refund":
def get_target_type_list(self, financial_type=None):
if financial_type == "refund":
return ["receivable_refund", "payable_refund"]
elif move_type == "regular":
elif financial_type == "regular":
return ["receivable", "payable", "liquidity", "other"]
return []
@@ -123,10 +123,10 @@ class AccountTax(models.Model):
("company_id", "in", company_ids),
]
def compute_balance(self, tax_or_base="tax", move_type=None):
def compute_balance(self, tax_or_base="tax", financial_type=None):
self.ensure_one()
domain = self.get_move_lines_domain(
tax_or_base=tax_or_base, move_type=move_type
tax_or_base=tax_or_base, financial_type=financial_type
)
# balance is debit - credit whereas on tax return you want to see what
# vat has to be paid so:
@@ -144,7 +144,7 @@ class AccountTax(models.Model):
("tax_exigible", "=", True),
]
if type_list:
domain.append(("move_id.move_type", "in", type_list))
domain.append(("move_id.financial_type", "in", type_list))
return domain
def get_base_balance_domain(self, state_list, type_list):
@@ -154,13 +154,13 @@ class AccountTax(models.Model):
("tax_exigible", "=", True),
]
if type_list:
domain.append(("move_id.move_type", "in", type_list))
domain.append(("move_id.financial_type", "in", type_list))
return domain
def get_move_lines_domain(self, tax_or_base="tax", move_type=None):
def get_move_lines_domain(self, tax_or_base="tax", financial_type=None):
from_date, to_date, company_ids, target_move = self.get_context_values()
state_list = self.get_target_state_list(target_move)
type_list = self.get_target_type_list(move_type)
type_list = self.get_target_type_list(financial_type)
domain = self.get_move_line_partial_domain(from_date, to_date, company_ids)
balance_domain = []
if tax_or_base == "tax":
@@ -170,12 +170,12 @@ class AccountTax(models.Model):
domain.extend(balance_domain)
return domain
def get_lines_action(self, tax_or_base="tax", move_type=None):
def get_lines_action(self, tax_or_base="tax", financial_type=None):
domain = self.get_move_lines_domain(
tax_or_base=tax_or_base, move_type=move_type
tax_or_base=tax_or_base, financial_type=financial_type
)
action = self.env.ref("account.action_account_moves_all_tree")
vals = action.read()[0]
vals = action.sudo().read()[0]
vals["context"] = {}
vals["domain"] = domain
return vals
@@ -190,16 +190,16 @@ class AccountTax(models.Model):
def view_tax_regular_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base="tax", move_type="regular")
return self.get_lines_action(tax_or_base="tax", financial_type="regular")
def view_base_regular_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base="base", move_type="regular")
return self.get_lines_action(tax_or_base="base", financial_type="regular")
def view_tax_refund_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base="tax", move_type="refund")
return self.get_lines_action(tax_or_base="tax", financial_type="refund")
def view_base_refund_lines(self):
self.ensure_one()
return self.get_lines_action(tax_or_base="base", move_type="refund")
return self.get_lines_action(tax_or_base="base", financial_type="refund")