Browse Source

[IMP] account_financial_report: Fix VAT Report and other improvements

pull/749/head
Joan Sisquella 5 years ago
committed by João Marques
parent
commit
51e11e6316
  1. 8
      account_financial_report/report/abstract_report_xlsx.py
  2. 1
      account_financial_report/report/aged_partner_balance.py
  3. 5
      account_financial_report/report/general_ledger.py
  4. 2
      account_financial_report/report/general_ledger_xlsx.py
  5. 237
      account_financial_report/report/trial_balance.py
  6. 148
      account_financial_report/report/vat_report.py
  7. 36
      account_financial_report/tests/test_vat_report.py
  8. 2
      account_financial_report/wizard/general_ledger_wizard.py
  9. 7
      account_financial_report/wizard/vat_report_wizard.py
  10. 9
      account_financial_report/wizard/vat_report_wizard_view.xml

8
account_financial_report/report/abstract_report_xlsx.py

@ -449,10 +449,10 @@ class AbstractReportXslx(models.AbstractModel):
def _get_currency_amt_format(self, line_object): def _get_currency_amt_format(self, line_object):
""" Return amount format specific for each currency. """ """ Return amount format specific for each currency. """
if "account_group_id" in line_object and line_object["account_group_id"]: if "account_group_id" in line_object and line_object["account_group_id"]:
format_amt = getattr(self, "format_amount_bold")
format_amt = self.format_amount_bold
field_prefix = "format_amount_bold" field_prefix = "format_amount_bold"
else: else:
format_amt = getattr(self, "format_amount")
format_amt = self.format_amount
field_prefix = "format_amount" field_prefix = "format_amount"
if "currency_id" in line_object and line_object.get("currency_id", False): if "currency_id" in line_object and line_object.get("currency_id", False):
field_name = "{}_{}".format(field_prefix, line_object["currency_id"].name) field_name = "{}_{}".format(field_prefix, line_object["currency_id"].name)
@ -460,7 +460,7 @@ class AbstractReportXslx(models.AbstractModel):
format_amt = getattr(self, field_name) format_amt = getattr(self, field_name)
else: else:
format_amt = self.workbook.add_format() format_amt = self.workbook.add_format()
setattr(self, "field_name", format_amt)
self.field_name = format_amt
format_amount = "#,##0." + ( format_amount = "#,##0." + (
"0" * line_object["currency_id"].decimal_places "0" * line_object["currency_id"].decimal_places
) )
@ -473,7 +473,7 @@ class AbstractReportXslx(models.AbstractModel):
format_amt = self.format_amount_bold format_amt = self.format_amount_bold
field_prefix = "format_amount_bold" field_prefix = "format_amount_bold"
else: else:
format_amt = getattr(self, "format_amount")
format_amt = self.format_amount
field_prefix = "format_amount" field_prefix = "format_amount"
if line_dict.get("currency_id", False) and line_dict["currency_id"]: if line_dict.get("currency_id", False) and line_dict["currency_id"]:
if isinstance(line_dict["currency_id"], int): if isinstance(line_dict["currency_id"], int):

1
account_financial_report/report/aged_partner_balance.py

@ -386,6 +386,7 @@ class AgedPartnerBalanceReport(models.AbstractModel):
) )
self._compute_maturity_date(ml, date_at_oject) self._compute_maturity_date(ml, date_at_oject)
move_lines.append(ml) move_lines.append(ml)
move_lines = sorted(move_lines, key=lambda k: (k["date"]))
partner.update({"move_lines": move_lines}) partner.update({"move_lines": move_lines})
account["partners"].append(partner) account["partners"].append(partner)
aged_partner_data.append(account) aged_partner_data.append(account)

5
account_financial_report/report/general_ledger.py

@ -6,7 +6,7 @@ import calendar
import datetime import datetime
import operator import operator
from odoo import api, models
from odoo import _, api, models
class GeneralLedgerReport(models.AbstractModel): class GeneralLedgerReport(models.AbstractModel):
@ -556,7 +556,7 @@ class GeneralLedgerReport(models.AbstractModel):
move_line["balance"] += last_cumul_balance move_line["balance"] += last_cumul_balance
last_cumul_balance = move_line["balance"] last_cumul_balance = move_line["balance"]
if move_line["rec_id"] in rec_after_date_to_ids: if move_line["rec_id"] in rec_after_date_to_ids:
move_line["rec_name"] = str("*") + move_line["rec_name"]
move_line["rec_name"] = "(" + _("future") + ") " + move_line["rec_name"]
return move_lines return move_lines
@api.model @api.model
@ -763,6 +763,7 @@ class GeneralLedgerReport(models.AbstractModel):
account["move_lines"] = self._recalculate_cumul_balance( account["move_lines"] = self._recalculate_cumul_balance(
account["move_lines"], account["move_lines"],
gen_ld_data[account["id"]]["init_bal"]["balance"], gen_ld_data[account["id"]]["init_bal"]["balance"],
rec_after_date_to_ids,
) )
if account["partners"]: if account["partners"]:
account["partners"] = False account["partners"] = False

2
account_financial_report/report/general_ledger_xlsx.py

@ -31,7 +31,7 @@ class GeneralLedgerXslx(models.AbstractModel):
6: {"header": _("Ref - Label"), "field": "ref_label", "width": 40}, 6: {"header": _("Ref - Label"), "field": "ref_label", "width": 40},
7: {"header": _("Cost center"), "field": "cost_center", "width": 15}, 7: {"header": _("Cost center"), "field": "cost_center", "width": 15},
8: {"header": _("Tags"), "field": "tags", "width": 10}, 8: {"header": _("Tags"), "field": "tags", "width": 10},
9: {"header": _("Rec."), "field": "rec_name", "width": 5},
9: {"header": _("Rec."), "field": "rec_name", "width": 15},
10: { 10: {
"header": _("Debit"), "header": _("Debit"),
"field": "debit", "field": "debit",

237
account_financial_report/report/trial_balance.py

@ -207,6 +207,128 @@ class TrialBalanceReport(models.AbstractModel):
) )
return pl_initial_balance, pl_initial_currency_balance return pl_initial_balance, pl_initial_currency_balance
@api.model
def _compute_account_amount(
self, total_amount, tb_initial_acc, tb_period_acc, foreign_currency
):
for tb in tb_period_acc:
acc_id = tb["account_id"][0]
total_amount[acc_id] = {}
total_amount[acc_id]["credit"] = tb["credit"]
total_amount[acc_id]["debit"] = tb["debit"]
total_amount[acc_id]["balance"] = tb["balance"]
total_amount[acc_id]["initial_balance"] = 0.0
total_amount[acc_id]["ending_balance"] = tb["balance"]
if foreign_currency:
total_amount[acc_id]["initial_currency_balance"] = 0.0
total_amount[acc_id]["ending_currency_balance"] = round(
tb["amount_currency"], 2
)
for tb in tb_initial_acc:
acc_id = tb["account_id"]
if acc_id not in total_amount.keys():
total_amount[acc_id] = {}
total_amount[acc_id]["credit"] = 0.0
total_amount[acc_id]["debit"] = 0.0
total_amount[acc_id]["balance"] = 0.0
total_amount[acc_id]["initial_balance"] = tb["balance"]
total_amount[acc_id]["ending_balance"] = tb["balance"]
if foreign_currency:
total_amount[acc_id]["initial_currency_balance"] = round(
tb["amount_currency"], 2
)
total_amount[acc_id]["ending_currency_balance"] = round(
tb["amount_currency"], 2
)
else:
total_amount[acc_id]["initial_balance"] = tb["balance"]
total_amount[acc_id]["ending_balance"] += tb["balance"]
if foreign_currency:
total_amount[acc_id]["initial_currency_balance"] = round(
tb["amount_currency"], 2
)
total_amount[acc_id]["ending_currency_balance"] += round(
tb["amount_currency"], 2
)
return total_amount
@api.model
def _compute_partner_amount(
self, total_amount, tb_initial_prt, tb_period_prt, foreign_currency
):
partners_ids = set()
partners_data = {}
for tb in tb_period_prt:
acc_id = tb["account_id"][0]
if tb["partner_id"]:
prt_id = tb["partner_id"][0]
if tb["partner_id"] not in partners_ids:
partners_data.update(
{prt_id: {"id": prt_id, "name": tb["partner_id"][1]}}
)
total_amount[acc_id][prt_id] = {}
total_amount[acc_id][prt_id]["credit"] = tb["credit"]
total_amount[acc_id][prt_id]["debit"] = tb["debit"]
total_amount[acc_id][prt_id]["balance"] = tb["balance"]
total_amount[acc_id][prt_id]["initial_balance"] = 0.0
total_amount[acc_id][prt_id]["ending_balance"] = tb["balance"]
if foreign_currency:
total_amount[acc_id][prt_id]["initial_currency_balance"] = 0.0
total_amount[acc_id][prt_id]["ending_currency_balance"] = round(
tb["amount_currency"], 2
)
partners_ids.add(tb["partner_id"])
for tb in tb_initial_prt:
acc_id = tb["account_id"][0]
if tb["partner_id"]:
prt_id = tb["partner_id"][0]
if tb["partner_id"] not in partners_ids:
partners_data.update(
{prt_id: {"id": prt_id, "name": tb["partner_id"][1]}}
)
if acc_id not in total_amount.keys():
total_amount[acc_id][prt_id] = {}
total_amount[acc_id][prt_id]["credit"] = 0.0
total_amount[acc_id][prt_id]["debit"] = 0.0
total_amount[acc_id][prt_id]["balance"] = 0.0
total_amount[acc_id][prt_id]["initial_balance"] = tb["balance"]
total_amount[acc_id][prt_id]["ending_balance"] = tb["balance"]
if foreign_currency:
total_amount[acc_id][prt_id][
"initial_currency_balance"
] = round(tb["amount_currency"], 2)
total_amount[acc_id][prt_id]["ending_currency_balance"] = round(
tb["amount_currency"], 2
)
partners_ids.add(tb["partner_id"])
elif prt_id not in total_amount[acc_id].keys():
total_amount[acc_id][prt_id] = {}
total_amount[acc_id][prt_id]["credit"] = 0.0
total_amount[acc_id][prt_id]["debit"] = 0.0
total_amount[acc_id][prt_id]["balance"] = 0.0
total_amount[acc_id][prt_id]["initial_balance"] = tb["balance"]
total_amount[acc_id][prt_id]["ending_balance"] = tb["balance"]
if foreign_currency:
total_amount[acc_id][prt_id][
"initial_currency_balance"
] = round(tb["amount_currency"], 2)
total_amount[acc_id][prt_id]["ending_currency_balance"] = round(
tb["amount_currency"], 2
)
partners_ids.add(tb["partner_id"])
else:
total_amount[acc_id][prt_id]["initial_balance"] += tb["balance"]
total_amount[acc_id][prt_id]["ending_balance"] += tb["balance"]
if foreign_currency:
total_amount[acc_id][prt_id][
"initial_currency_balance"
] += round(tb["amount_currency"], 2)
total_amount[acc_id][prt_id][
"ending_currency_balance"
] += round(tb["amount_currency"], 2)
return total_amount, partners_data
@api.model
def _get_data( def _get_data(
self, self,
account_ids, account_ids,
@ -321,116 +443,13 @@ class TrialBalanceReport(models.AbstractModel):
) )
total_amount = {} total_amount = {}
partners_data = [] partners_data = []
for tb in tb_period_acc:
acc_id = tb["account_id"][0]
total_amount[acc_id] = {}
total_amount[acc_id]["credit"] = tb["credit"]
total_amount[acc_id]["debit"] = tb["debit"]
total_amount[acc_id]["balance"] = tb["balance"]
total_amount[acc_id]["initial_balance"] = 0.0
total_amount[acc_id]["ending_balance"] = tb["balance"]
if foreign_currency:
total_amount[acc_id]["initial_currency_balance"] = 0.0
total_amount[acc_id]["ending_currency_balance"] = round(
tb["amount_currency"], 2
)
for tb in tb_initial_acc:
acc_id = tb["account_id"]
if acc_id not in total_amount.keys():
total_amount[acc_id] = {}
total_amount[acc_id]["credit"] = 0.0
total_amount[acc_id]["debit"] = 0.0
total_amount[acc_id]["balance"] = 0.0
total_amount[acc_id]["initial_balance"] = tb["balance"]
total_amount[acc_id]["ending_balance"] = tb["balance"]
if foreign_currency:
total_amount[acc_id]["initial_currency_balance"] = round(
tb["amount_currency"], 2
)
total_amount[acc_id]["ending_currency_balance"] = round(
tb["amount_currency"], 2
)
else:
total_amount[acc_id]["initial_balance"] = tb["balance"]
total_amount[acc_id]["ending_balance"] += tb["balance"]
if foreign_currency:
total_amount[acc_id]["initial_currency_balance"] = round(
tb["amount_currency"], 2
)
total_amount[acc_id]["ending_currency_balance"] += round(
tb["amount_currency"], 2
)
total_amount = self._compute_account_amount(
total_amount, tb_initial_acc, tb_period_acc, foreign_currency
)
if show_partner_details: if show_partner_details:
partners_ids = set()
partners_data = {}
for tb in tb_period_prt:
acc_id = tb["account_id"][0]
if tb["partner_id"]:
prt_id = tb["partner_id"][0]
if tb["partner_id"] not in partners_ids:
partners_data.update(
{prt_id: {"id": prt_id, "name": tb["partner_id"][1]}}
)
total_amount[acc_id][prt_id] = {}
total_amount[acc_id][prt_id]["credit"] = tb["credit"]
total_amount[acc_id][prt_id]["debit"] = tb["debit"]
total_amount[acc_id][prt_id]["balance"] = tb["balance"]
total_amount[acc_id][prt_id]["initial_balance"] = 0.0
total_amount[acc_id][prt_id]["ending_balance"] = tb["balance"]
if foreign_currency:
total_amount[acc_id][prt_id]["initial_currency_balance"] = 0.0
total_amount[acc_id][prt_id]["ending_currency_balance"] = round(
tb["amount_currency"], 2
)
partners_ids.add(tb["partner_id"])
for tb in tb_initial_prt:
acc_id = tb["account_id"][0]
if tb["partner_id"]:
prt_id = tb["partner_id"][0]
if tb["partner_id"] not in partners_ids:
partners_data.update(
{prt_id: {"id": prt_id, "name": tb["partner_id"][1]}}
)
if acc_id not in total_amount.keys():
total_amount[acc_id][prt_id] = {}
total_amount[acc_id][prt_id]["credit"] = 0.0
total_amount[acc_id][prt_id]["debit"] = 0.0
total_amount[acc_id][prt_id]["balance"] = 0.0
total_amount[acc_id][prt_id]["initial_balance"] = tb["balance"]
total_amount[acc_id][prt_id]["ending_balance"] = tb["balance"]
if foreign_currency:
total_amount[acc_id][prt_id][
"initial_currency_balance"
] = round(tb["amount_currency"], 2)
total_amount[acc_id][prt_id][
"ending_currency_balance"
] = round(tb["amount_currency"], 2)
partners_ids.add(tb["partner_id"])
elif prt_id not in total_amount[acc_id].keys():
total_amount[acc_id][prt_id] = {}
total_amount[acc_id][prt_id]["credit"] = 0.0
total_amount[acc_id][prt_id]["debit"] = 0.0
total_amount[acc_id][prt_id]["balance"] = 0.0
total_amount[acc_id][prt_id]["initial_balance"] = tb["balance"]
total_amount[acc_id][prt_id]["ending_balance"] = tb["balance"]
if foreign_currency:
total_amount[acc_id][prt_id][
"initial_currency_balance"
] = round(tb["amount_currency"], 2)
total_amount[acc_id][prt_id][
"ending_currency_balance"
] = round(tb["amount_currency"], 2)
partners_ids.add(tb["partner_id"])
else:
total_amount[acc_id][prt_id]["initial_balance"] += tb["balance"]
total_amount[acc_id][prt_id]["ending_balance"] += tb["balance"]
if foreign_currency:
total_amount[acc_id][prt_id][
"initial_currency_balance"
] += round(tb["amount_currency"], 2)
total_amount[acc_id][prt_id][
"ending_currency_balance"
] += round(tb["amount_currency"], 2)
total_amount, partners_data = self._compute_partner_amount(
total_amount, tb_initial_prt, tb_period_prt, foreign_currency
)
accounts_ids = list(total_amount.keys()) accounts_ids = list(total_amount.keys())
unaffected_id = unaffected_earnings_account unaffected_id = unaffected_earnings_account
if unaffected_id not in accounts_ids: if unaffected_id not in accounts_ids:

148
account_financial_report/report/vat_report.py

@ -22,57 +22,82 @@ class VATReport(models.AbstractModel):
"name": tax.name, "name": tax.name,
"tax_group_id": tax.tax_group_id.id, "tax_group_id": tax.tax_group_id.id,
"type_tax_use": tax.type_tax_use, "type_tax_use": tax.type_tax_use,
"amount_type": tax.amount_type,
"tags_ids": tax.invoice_repartition_line_ids.tag_ids.ids,
} }
} }
) )
return tax_data return tax_data
@api.model @api.model
def _get_vat_report_domain(self, company_id, date_from, date_to):
def _get_tax_report_domain(self, company_id, date_from, date_to, only_posted_moves):
domain = [ domain = [
("company_id", "=", company_id), ("company_id", "=", company_id),
("date", ">=", date_from), ("date", ">=", date_from),
("date", "<", date_to),
("date", "<=", date_to),
("tax_line_id", "!=", False), ("tax_line_id", "!=", False),
("tax_exigible", "=", True), ("tax_exigible", "=", True),
] ]
if only_posted_moves:
domain += [("move_id.state", "=", "posted")]
return domain return domain
def _get_vat_report_data(self, company_id, date_from, date_to):
domain = self._get_vat_report_domain(company_id, date_from, date_to)
@api.model
def _get_net_report_domain(self, company_id, date_from, date_to, only_posted_moves):
domain = [
("company_id", "=", company_id),
("date", ">=", date_from),
("date", "<=", date_to),
("tax_ids", "!=", False),
("tax_exigible", "=", True),
]
if only_posted_moves:
domain += [("move_id.state", "=", "posted")]
return domain
def _get_vat_report_data(self, company_id, date_from, date_to, only_posted_moves):
tax_domain = self._get_tax_report_domain(
company_id, date_from, date_to, only_posted_moves
)
ml_fields = [ ml_fields = [
"id", "id",
"tax_base_amount", "tax_base_amount",
"balance", "balance",
"tax_line_id", "tax_line_id",
"tax_repartition_line_id",
"tax_ids",
"analytic_tag_ids", "analytic_tag_ids",
"tag_ids",
] ]
tax_move_lines = self.env["account.move.line"].search_read( tax_move_lines = self.env["account.move.line"].search_read(
domain=domain, fields=ml_fields
domain=tax_domain, fields=ml_fields,
) )
vat_data = {}
tax_ids = list(map(operator.itemgetter("tax_line_id"), tax_move_lines))
tax_ids = [i[0] for i in tax_ids]
tax_data = self._get_tax_data(tax_ids)
net_domain = self._get_net_report_domain(
company_id, date_from, date_to, only_posted_moves
)
taxed_move_lines = self.env["account.move.line"].search_read(
domain=net_domain, fields=ml_fields,
)
vat_data = []
for tax_move_line in tax_move_lines: for tax_move_line in tax_move_lines:
tax_ml_id = tax_move_line["id"]
repartition = self.env["account.tax.repartition.line"].browse(
tax_move_line["tax_repartition_line_id"][0]
)
tax_id = tax_move_line["tax_line_id"][0]
vat_data[tax_ml_id] = {}
vat_data[tax_ml_id].update(
vat_data.append(
{ {
"id": tax_ml_id,
"net": tax_move_line["tax_base_amount"],
"tax": (-1) * tax_move_line["balance"]
if tax_data[tax_id]["type_tax_use"] == "sale"
else tax_move_line["balance"],
"tax_line_id": tax_move_line["tax_line_id"],
"tags_ids": repartition.tag_ids.ids,
"net": 0.0,
"tax": tax_move_line["balance"],
"tax_line_id": tax_move_line["tax_line_id"][0],
} }
) )
for taxed_move_line in taxed_move_lines:
for tax_id in taxed_move_line["tax_ids"]:
vat_data.append(
{
"net": taxed_move_line["balance"],
"tax": 0.0,
"tax_line_id": tax_id,
}
)
tax_ids = list(map(operator.itemgetter("tax_line_id"), vat_data))
tax_ids = list(set(tax_ids))
tax_data = self._get_tax_data(tax_ids)
return vat_data, tax_data return vat_data, tax_data
def _get_tax_group_data(self, tax_group_ids): def _get_tax_group_data(self, tax_group_ids):
@ -92,23 +117,28 @@ class VATReport(models.AbstractModel):
def _get_vat_report_group_data(self, vat_report_data, tax_data, tax_detail): def _get_vat_report_group_data(self, vat_report_data, tax_data, tax_detail):
vat_report = {} vat_report = {}
for tax_move_line in vat_report_data.values():
tax_id = tax_move_line["tax_line_id"][0]
tax_group_id = tax_data[tax_id]["tax_group_id"]
if tax_group_id not in vat_report.keys():
vat_report[tax_group_id] = {}
vat_report[tax_group_id]["net"] = 0.0
vat_report[tax_group_id]["tax"] = 0.0
vat_report[tax_group_id][tax_id] = dict(tax_data[tax_id])
vat_report[tax_group_id][tax_id].update({"net": 0.0, "tax": 0.0})
for tax_move_line in vat_report_data:
tax_id = tax_move_line["tax_line_id"]
if tax_data[tax_id]["amount_type"] == "group":
pass
else: else:
if tax_id not in vat_report[tax_group_id].keys():
tax_group_id = tax_data[tax_id]["tax_group_id"]
if tax_group_id not in vat_report.keys():
vat_report[tax_group_id] = {}
vat_report[tax_group_id]["net"] = 0.0
vat_report[tax_group_id]["tax"] = 0.0
vat_report[tax_group_id][tax_id] = dict(tax_data[tax_id]) vat_report[tax_group_id][tax_id] = dict(tax_data[tax_id])
vat_report[tax_group_id][tax_id].update({"net": 0.0, "tax": 0.0}) vat_report[tax_group_id][tax_id].update({"net": 0.0, "tax": 0.0})
vat_report[tax_group_id]["net"] += tax_move_line["net"]
vat_report[tax_group_id]["tax"] += tax_move_line["tax"]
vat_report[tax_group_id][tax_id]["net"] += tax_move_line["net"]
vat_report[tax_group_id][tax_id]["tax"] += tax_move_line["tax"]
else:
if tax_id not in vat_report[tax_group_id].keys():
vat_report[tax_group_id][tax_id] = dict(tax_data[tax_id])
vat_report[tax_group_id][tax_id].update(
{"net": 0.0, "tax": 0.0}
)
vat_report[tax_group_id]["net"] += tax_move_line["net"]
vat_report[tax_group_id]["tax"] += tax_move_line["tax"]
vat_report[tax_group_id][tax_id]["net"] += tax_move_line["net"]
vat_report[tax_group_id][tax_id]["tax"] += tax_move_line["tax"]
tax_group_data = self._get_tax_group_data(vat_report.keys()) tax_group_data = self._get_tax_group_data(vat_report.keys())
vat_report_list = [] vat_report_list = []
for tax_group_id in vat_report.keys(): for tax_group_id in vat_report.keys():
@ -133,25 +163,30 @@ class VATReport(models.AbstractModel):
def _get_vat_report_tag_data(self, vat_report_data, tax_data, tax_detail): def _get_vat_report_tag_data(self, vat_report_data, tax_data, tax_detail):
vat_report = {} vat_report = {}
for tax_move_line in vat_report_data.values():
tax_id = tax_move_line["tax_line_id"][0]
tags_ids = tax_move_line["tags_ids"]
if tags_ids:
for tag_id in tags_ids:
if tag_id not in vat_report.keys():
vat_report[tag_id] = {}
vat_report[tag_id]["net"] = 0.0
vat_report[tag_id]["tax"] = 0.0
vat_report[tag_id][tax_id] = dict(tax_data[tax_id])
vat_report[tag_id][tax_id].update({"net": 0.0, "tax": 0.0})
else:
if tax_id not in vat_report[tag_id].keys():
for tax_move_line in vat_report_data:
tax_id = tax_move_line["tax_line_id"]
tags_ids = tax_data[tax_id]["tags_ids"]
if tax_data[tax_id]["amount_type"] == "group":
continue
else:
if tags_ids:
for tag_id in tags_ids:
if tag_id not in vat_report.keys():
vat_report[tag_id] = {}
vat_report[tag_id]["net"] = 0.0
vat_report[tag_id]["tax"] = 0.0
vat_report[tag_id][tax_id] = dict(tax_data[tax_id]) vat_report[tag_id][tax_id] = dict(tax_data[tax_id])
vat_report[tag_id][tax_id].update({"net": 0.0, "tax": 0.0}) vat_report[tag_id][tax_id].update({"net": 0.0, "tax": 0.0})
vat_report[tag_id][tax_id]["net"] += tax_move_line["net"]
vat_report[tag_id][tax_id]["tax"] += tax_move_line["tax"]
vat_report[tag_id]["net"] += tax_move_line["net"]
vat_report[tag_id]["tax"] += tax_move_line["tax"]
else:
if tax_id not in vat_report[tag_id].keys():
vat_report[tag_id][tax_id] = dict(tax_data[tax_id])
vat_report[tag_id][tax_id].update(
{"net": 0.0, "tax": 0.0}
)
vat_report[tag_id][tax_id]["net"] += tax_move_line["net"]
vat_report[tag_id][tax_id]["tax"] += tax_move_line["tax"]
vat_report[tag_id]["net"] += tax_move_line["net"]
vat_report[tag_id]["tax"] += tax_move_line["tax"]
tags_data = self._get_tags_data(vat_report.keys()) tags_data = self._get_tags_data(vat_report.keys())
vat_report_list = [] vat_report_list = []
for tag_id in vat_report.keys(): for tag_id in vat_report.keys():
@ -173,8 +208,9 @@ class VATReport(models.AbstractModel):
date_to = data["date_to"] date_to = data["date_to"]
based_on = data["based_on"] based_on = data["based_on"]
tax_detail = data["tax_detail"] tax_detail = data["tax_detail"]
only_posted_moves = data["only_posted_moves"]
vat_report_data, tax_data = self._get_vat_report_data( vat_report_data, tax_data = self._get_vat_report_data(
company_id, date_from, date_to
company_id, date_from, date_to, only_posted_moves
) )
if based_on == "taxgroups": if based_on == "taxgroups":
vat_report = self._get_vat_report_group_data( vat_report = self._get_vat_report_group_data(

36
account_financial_report/tests/test_vat_report.py

@ -267,16 +267,16 @@ class TestVATReport(common.TransactionCase):
tax_10_net, tax_10_tax = self._get_tax_line(self.tax_10.name, vat_report) tax_10_net, tax_10_tax = self._get_tax_line(self.tax_10.name, vat_report)
tax_20_net, tax_20_tax = self._get_tax_line(self.tax_20.name, vat_report) tax_20_net, tax_20_tax = self._get_tax_line(self.tax_20.name, vat_report)
self.assertEqual(tag_01_net, 100)
self.assertEqual(tag_01_tax, 10)
self.assertEqual(tag_02_net, 350)
self.assertEqual(tag_02_tax, 60)
self.assertEqual(tag_03_net, 250)
self.assertEqual(tag_03_tax, 50)
self.assertEqual(tax_10_net, 100)
self.assertEqual(tax_10_tax, 10)
self.assertEqual(tax_20_net, 250)
self.assertEqual(tax_20_tax, 50)
self.assertEqual(tag_01_net, -100)
self.assertEqual(tag_01_tax, -10)
self.assertEqual(tag_02_net, -350)
self.assertEqual(tag_02_tax, -60)
self.assertEqual(tag_03_net, -250)
self.assertEqual(tag_03_tax, -50)
self.assertEqual(tax_10_net, -100)
self.assertEqual(tax_10_tax, -10)
self.assertEqual(tax_20_net, -250)
self.assertEqual(tax_20_tax, -50)
# Check report based on taxgroups # Check report based on taxgroups
res_data = self._get_report_lines(taxgroups=True) res_data = self._get_report_lines(taxgroups=True)
@ -304,14 +304,14 @@ class TestVATReport(common.TransactionCase):
tax_10_net, tax_10_tax = self._get_tax_line(self.tax_10.name, vat_report) tax_10_net, tax_10_tax = self._get_tax_line(self.tax_10.name, vat_report)
tax_20_net, tax_20_tax = self._get_tax_line(self.tax_20.name, vat_report) tax_20_net, tax_20_tax = self._get_tax_line(self.tax_20.name, vat_report)
self.assertEqual(group_10_net, 100)
self.assertEqual(group_10_tax, 10)
self.assertEqual(group_20_net, 250)
self.assertEqual(group_20_tax, 50)
self.assertEqual(tax_10_net, 100)
self.assertEqual(tax_10_tax, 10)
self.assertEqual(tax_20_net, 250)
self.assertEqual(tax_20_tax, 50)
self.assertEqual(group_10_net, -100)
self.assertEqual(group_10_tax, -10)
self.assertEqual(group_20_net, -250)
self.assertEqual(group_20_tax, -50)
self.assertEqual(tax_10_net, -100)
self.assertEqual(tax_10_tax, -10)
self.assertEqual(tax_20_net, -250)
self.assertEqual(tax_20_tax, -50)
def test_wizard_date_range(self): def test_wizard_date_range(self):
vat_wizard = self.env["vat.report.wizard"] vat_wizard = self.env["vat.report.wizard"]

2
account_financial_report/wizard/general_ledger_wizard.py

@ -47,7 +47,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
"If partners are filtered, " "If partners are filtered, "
"debits and credits totals will not match the trial balance.", "debits and credits totals will not match the trial balance.",
) )
show_analytic_tags = fields.Boolean(string="Show analytic tags")
show_analytic_tags = fields.Boolean(string="Show analytic tags",)
receivable_accounts_only = fields.Boolean() receivable_accounts_only = fields.Boolean()
payable_accounts_only = fields.Boolean() payable_accounts_only = fields.Boolean()
partner_ids = fields.Many2many( partner_ids = fields.Many2many(

7
account_financial_report/wizard/vat_report_wizard.py

@ -25,6 +25,12 @@ class VATReportWizard(models.TransientModel):
default="taxtags", default="taxtags",
) )
tax_detail = fields.Boolean("Detail Taxes") tax_detail = fields.Boolean("Detail Taxes")
target_move = fields.Selection(
[("posted", "All Posted Entries"), ("all", "All Entries")],
string="Target Moves",
required=True,
default="posted",
)
@api.onchange("company_id") @api.onchange("company_id")
def onchange_company_id(self): def onchange_company_id(self):
@ -105,6 +111,7 @@ class VATReportWizard(models.TransientModel):
"date_from": self.date_from, "date_from": self.date_from,
"date_to": self.date_to, "date_to": self.date_to,
"based_on": self.based_on, "based_on": self.based_on,
"only_posted_moves": self.target_move == "posted",
"tax_detail": self.tax_detail, "tax_detail": self.tax_detail,
} }

9
account_financial_report/wizard/vat_report_wizard_view.xml

@ -18,10 +18,11 @@
<field name="date_from" /> <field name="date_from" />
<field name="date_to" /> <field name="date_to" />
</group> </group>
<group name="other_filters">
<field name="based_on" widget="radio" />
<field name="tax_detail" />
</group>
</group>
<group name="other_filters">
<field name="target_move" widget="radio" />
<field name="based_on" widget="radio" />
<field name="tax_detail" />
</group> </group>
<footer> <footer>
<button <button

Loading…
Cancel
Save