Skip to content

Commit

Permalink
Merge PR OCA#2823 into 15.0
Browse files Browse the repository at this point in the history
Signed-off-by marcelsavegnago
  • Loading branch information
OCA-git-bot committed Dec 6, 2023
2 parents 6045e13 + f3131ae commit 8fd61b7
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions l10n_br_coa/models/account_chart_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ def _load_template(
if self.parent_id and self.parent_id == self.env.ref(
"l10n_br_coa.l10n_br_coa_template"
):

# for some reason, account_ref keys can be either account ids
# either account records. In order to match them later we ensure
# here keys are ids:
account_ref = {
k.id if hasattr(k, "id") else k: v for k, v in account_ref.items()
}

acc_names = {
"sale": {
"account_id": "account_id",
Expand All @@ -67,19 +75,30 @@ def _load_template(
"l10n_br_coa.account.tax.group.account.template"
].search(domain)
if group_tax_account_template:

if tax.deductible:
account_id = group_tax_account_template.ded_account_id
refund_account_id = (
account = group_tax_account_template.ded_account_id
refund_account = (
group_tax_account_template.ded_refund_account_id
)
else:
account_id = group_tax_account_template[
account = group_tax_account_template[
acc_names.get(tax.type_tax_use, {}).get("account_id")
]
refund_account_id = group_tax_account_template[
refund_account = group_tax_account_template[
acc_names.get(tax.type_tax_use, {}).get("refund_account_id")
]

if account_ref.get(account.id):
account_id = account_ref[account.id].id
else:
account_id = False

if account_ref.get(refund_account.id):
refund_account_id = account_ref[refund_account.id].id
else:
refund_account_id = False

tax.write(
{
"invoice_repartition_line_ids": [
Expand All @@ -100,9 +119,7 @@ def _load_template(
if not tax.deductible
else -100,
"repartition_type": "tax",
"account_id": account_ref.get(
account_id.id, False
),
"account_id": account_id,
},
),
],
Expand All @@ -124,9 +141,7 @@ def _load_template(
if not tax.deductible
else -100,
"repartition_type": "tax",
"account_id": account_ref.get(
refund_account_id.id, False
),
"account_id": refund_account_id,
},
),
],
Expand Down

0 comments on commit 8fd61b7

Please sign in to comment.