Skip to content

Commit

Permalink
[16.0][IMP] l10n_es_vat_book: Add tax agency
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian-RB authored and almumu committed Feb 11, 2025
1 parent 035aacd commit 52edbcd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
20 changes: 20 additions & 0 deletions l10n_es_vat_book/data/aeat_vat_book_map_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
<field name="special_tax_group" eval="False" />
<field name="fee_type_xlsx_column">N</field>
<field name="fee_amount_xlsx_column">O</field>
<field
name="tax_agency_ids"
eval="[ Command.link(ref('l10n_es_aeat.aeat_tax_agency_spain')) ]"
/>
<field
name="tax_tmpl_ids"
eval="[
Expand Down Expand Up @@ -40,6 +44,10 @@
<field name="special_tax_group" eval="False" />
<field name="fee_type_xlsx_column">O</field>
<field name="fee_amount_xlsx_column">P</field>
<field
name="tax_agency_ids"
eval="[ Command.link(ref('l10n_es_aeat.aeat_tax_agency_spain')) ]"
/>
<field name="tax_account_id" ref="l10n_es.account_common_472" />
<field
name="tax_tmpl_ids"
Expand Down Expand Up @@ -112,6 +120,10 @@
<field name="name">IVA soportado no deducible</field>
<field name="book_type">received</field>
<field name="special_tax_group" eval="False" />
<field
name="tax_agency_ids"
eval="[ Command.link(ref('l10n_es_aeat.aeat_tax_agency_spain')) ]"
/>
<field
name="tax_tmpl_ids"
eval="[
Expand All @@ -130,6 +142,10 @@
<field name="special_tax_group">req</field>
<field name="fee_type_xlsx_column">P</field>
<field name="fee_amount_xlsx_column">Q</field>
<field
name="tax_agency_ids"
eval="[ Command.link(ref('l10n_es_aeat.aeat_tax_agency_spain')) ]"
/>
<field
name="tax_tmpl_ids"
eval="[
Expand All @@ -147,6 +163,10 @@
<field name="special_tax_group">req</field>
<field name="fee_type_xlsx_column">R</field>
<field name="fee_amount_xlsx_column">S</field>
<field
name="tax_agency_ids"
eval="[ Command.link(ref('l10n_es_aeat.aeat_tax_agency_spain')) ]"
/>
<field
name="tax_tmpl_ids"
eval="[
Expand Down
1 change: 1 addition & 0 deletions l10n_es_vat_book/models/aeat_vat_book_map_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def _selection_special_tax_group(self):
comodel_name="account.account.template",
string="Tax Account Restriction",
)
tax_agency_ids = fields.Many2many("aeat.tax.agency", string="Tax Agency")

def get_taxes(self, report):
self.ensure_one()
Expand Down
21 changes: 14 additions & 7 deletions l10n_es_vat_book/models/l10n_es_vat_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,12 @@ def get_pos_partner_ids(self):

@ormcache("self.id")
def get_special_taxes_dic(self):
map_lines = self.env["aeat.vat.book.map.line"].search(
[("special_tax_group", "!=", False)]
)
domain = [("special_tax_group", "!=", False)]
if self.tax_agency_ids:
domain += [
("tax_agency_ids", "in", [False] + self.tax_agency_ids.ids),
]
map_lines = self.env["aeat.vat.book.map.line"].search(domain)
special_dic = {}
for map_line in map_lines:
for tax in map_line.get_taxes(self):
Expand Down Expand Up @@ -451,9 +454,12 @@ def _calculate_vat_book(self):
# Searches for all possible usable lines to report
moves = rec._get_account_move_lines()
for book_type in ["issued", "received"]:
map_lines = self.env["aeat.vat.book.map.line"].search(
[("book_type", "=", book_type)]
)
domain = [("book_type", "=", book_type)]
if rec.tax_agency_ids:
domain += [
("tax_agency_ids", "in", [False] + rec.tax_agency_ids.ids),
]
map_lines = self.env["aeat.vat.book.map.line"].search(domain)
taxes = self.env["account.tax"]
accounts = {}
for map_line in map_lines:
Expand All @@ -476,7 +482,8 @@ def _calculate_vat_book(self):
lines = moves.filtered(
lambda line: (line.tax_ids | line.tax_line_id) & taxes
)
rec.create_vat_book_lines(lines, map_line.book_type, taxes)
if map_lines:
rec.create_vat_book_lines(lines, map_lines[:1].book_type, taxes)
# Issued
book_type = "issued"
issued_tax_lines = rec.issued_line_ids.mapped("tax_line_ids")
Expand Down
12 changes: 12 additions & 0 deletions l10n_es_vat_book/tests/test_l10n_es_aeat_vat_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,15 @@ def test_model_vat_book(self):
report_xlsx = self.env.ref(report_name)._render(vat_book.ids)
self.assertGreaterEqual(len(report_xlsx[0]), 1)
self.assertEqual(report_xlsx[1], "xlsx")
# Check empty Vat Book
vat_book.write(
{
"tax_agency_ids": [
(4, self.env.ref("l10n_es_aeat.aeat_tax_agency_araba").id)
],
}
)
vat_book.button_calculate()
self.assertEqual(len(vat_book.issued_line_ids), 0)
self.assertEqual(len(vat_book.rectification_issued_line_ids), 0)
self.assertEqual(len(vat_book.issued_tax_summary_ids), 0)
1 change: 1 addition & 0 deletions l10n_es_vat_book/views/aeat_vat_book_map_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<field name="fee_amount_xlsx_column" />
<field name="tax_tmpl_ids" widget="many2many_tags" />
<field name="tax_account_id" />
<field name="tax_agency_ids" widget="many2many_tags" />
</tree>
</field>
</record>
Expand Down
14 changes: 13 additions & 1 deletion l10n_es_vat_book/views/l10n_es_vat_book.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_l10n_es_vat_book_tree" model="ir.ui.view">
<field name="name">l10n_es.vat.book.tree</field>
<field name="model">l10n.es.vat.book</field>
<field name="inherit_id" ref="l10n_es_aeat.view_l10n_es_aeat_report_tree" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="period_type" position="after">
<field name="tax_agency_ids" widget="many2many_tags" />
</field>
</field>
</record>
<record id="view_l10n_es_vat_book_form" model="ir.ui.view">
<field name="name">l10n_es.vat.book.form</field>
<field name="model">l10n.es.vat.book</field>
Expand Down Expand Up @@ -44,6 +55,7 @@
</field>
<group name="group_other_parameters" position="inside">
<field name="auto_renumber" />
<field name="tax_agency_ids" widget="many2many_tags" />
</group>
<xpath expr="//group[@name='group_declaration']" position="after">
<notebook>
Expand Down Expand Up @@ -96,7 +108,7 @@
<record model="ir.actions.act_window.view" id="action_l10n_vat_book_report_tree">
<field name="sequence" eval="2" />
<field name="view_mode">tree</field>
<field name="view_id" ref="l10n_es_aeat.view_l10n_es_aeat_report_tree" />
<field name="view_id" ref="view_l10n_es_vat_book_tree" />
<field name="act_window_id" ref="l10n_es_vat_book_action" />
</record>
<record model="ir.actions.act_window.view" id="action_l10n_vat_book_report_form">
Expand Down

0 comments on commit 52edbcd

Please sign in to comment.