Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][IMP] l10n_es_vat_porate: Use a proper account on investments and assets #3731

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion l10n_es_vat_prorate/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def _compute_all_tax(self):
new_key.update(
{
"vat_prorate": True,
"account_id": line.account_id.id,
"account_id": line.company_id._get_tax_prorrate_account_map().get(
line.account_id.account_type
)
or line.account_id.id,
"analytic_distribution": line.analytic_distribution,
}
)
Expand Down
47 changes: 46 additions & 1 deletion l10n_es_vat_prorate/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2023 Tecnativa Carolina Fernandez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo import _, api, fields, models, tools
from odoo.exceptions import ValidationError
from odoo.tools import ormcache

Expand All @@ -19,6 +19,36 @@ class ResCompany(models.Model):
vat_prorate_ids = fields.One2many(
"res.company.vat.prorate", inverse_name="company_id"
)
prorrate_asset_account_id = fields.Many2one(
"account.account",
domain="[('company_id', '=', id)]",
compute="_compute_prorrate_accounts",
store=True,
readonly=False,
)
prorrate_investment_account_id = fields.Many2one(
"account.account",
domain="[('company_id', '=', id)]",
compute="_compute_prorrate_accounts",
store=True,
readonly=False,
)

@api.depends("chart_template_id", "with_vat_prorate")
def _compute_prorrate_accounts(self):
for record in self:
if record.with_vat_prorate and record.chart_template_id:
Comment on lines +37 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@api.depends("chart_template_id", "with_vat_prorate")
def _compute_prorrate_accounts(self):
for record in self:
if record.with_vat_prorate and record.chart_template_id:
@api.depends("chart_template", "with_vat_prorate")
def _compute_prorrate_accounts(self):
for record in self:
if record.with_vat_prorate and record.chart_template:

En 17.0 cambian el nombre del field y lo hacen de tipo selection

record.prorrate_asset_account_id = self.env.ref(
"l10n_es.%s_account_common_6341" % record.id,
raise_if_not_found=False,
)
record.prorrate_investment_account_id = self.env.ref(
"l10n_es.%s_account_common_6342" % record.id,
raise_if_not_found=False,
)
else:
record.prorrate_asset_account_id = False
record.prorrate_investment_account_id = False

@ormcache("self")
def _get_prorate_accounts(self):
Expand Down Expand Up @@ -50,6 +80,21 @@ def _check_vat_prorate_ids(self):
if rec.with_vat_prorate and not rec.vat_prorate_ids:
raise ValidationError(_("You must complete VAT prorate information"))

@tools.ormcache(
"self.id",
"self.prorrate_asset_account_id.id",
"self.prorrate_investment_account_id.id",
)
def _get_tax_prorrate_account_map(self):
"""Get the account mapping according user type"""
return {
"asset_current": self.prorrate_asset_account_id.id,
"asset_non_current": self.prorrate_asset_account_id.id,
"asset_fixed": self.prorrate_asset_account_id.id,
"liability_current": self.prorrate_investment_account_id.id,
"liability_non_current": self.prorrate_investment_account_id.id,
}


class ResCompanyVatProrate(models.Model):
_name = "res.company.vat.prorate"
Expand Down
34 changes: 34 additions & 0 deletions l10n_es_vat_prorate/tests/test_vat_prorate.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def test_no_company_vat_prorate_information(self):
with self.assertRaises(exceptions.ValidationError):
self.env.company.write({"vat_prorate_ids": False})

def test_company_configuration(self):
self.assertTrue(self.env.company.with_vat_prorate)
self.assertTrue(self.env.company.prorrate_asset_account_id)
self.assertTrue(self.env.company.prorrate_investment_account_id)
self.env.company.write({"with_vat_prorate": False})
self.assertFalse(self.env.company.prorrate_asset_account_id)
self.assertFalse(self.env.company.prorrate_investment_account_id)

def test_no_prorate_in_invoice(self):
self.env.company.write(
{"with_vat_prorate": False}
Expand All @@ -87,6 +95,18 @@ def test_prorate_different_accounts_in_invoice(self):
)
self.assertEqual(6, len(invoice.line_ids))
self.assertEqual(3, len(invoice.line_ids.filtered(lambda r: r.tax_line_id)))
self.assertTrue(
invoice.line_ids.filtered(
lambda r: r.tax_line_id
and r.account_id == self.product_a.property_account_expense_id
)
)
self.assertTrue(
invoice.line_ids.filtered(
lambda r: r.tax_line_id
and r.account_id == self.product_b.property_account_expense_id
)
)
# Deal with analytics
invoice.line_ids[0].analytic_distribution = {self.analytic_account.id: 100}
self.assertEqual(6, len(invoice.line_ids))
Expand Down Expand Up @@ -124,6 +144,20 @@ def test_prorate_same_accounts_in_invoice(self):
# One of the tax lines should have expense account and the other the tax account
self.assertNotEqual(tax_lines[0].account_id, tax_lines[1].account_id)

def test_prorate_asset_in_invoice(self):
self.product_b.property_account_expense_id = self.company_data[
"default_account_assets"
]
invoice = self.init_invoice("in_invoice", products=[self.product_b])
self.assertEqual(4, len(invoice.line_ids))
self.assertEqual(2, len(invoice.line_ids.filtered(lambda r: r.tax_line_id)))
self.assertFalse(
invoice.line_ids.filtered(
lambda r: r.tax_line_id
and r.account_id == self.product_b.property_account_expense_id
)
)

def test_no_prorate_in_refund(self):
self.env.company.write(
{"with_vat_prorate": False}
Expand Down
8 changes: 8 additions & 0 deletions l10n_es_vat_prorate/views/res_company_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
</notebook>
<field name="company_registry" position="after">
<field name="with_vat_prorate" />
<field
name="prorrate_asset_account_id"
attrs="{'invisible': [('with_vat_prorate', '=', False)]}"
/>
<field
name="prorrate_investment_account_id"
attrs="{'invisible': [('with_vat_prorate', '=', False)]}"
/>
</field>
</field>
</record>
Expand Down
Loading