-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
[16.0][ADD] account_multi_foreign_vat #387
Closed
ArnauCForgeFlow
wants to merge
7
commits into
OCA:16.0
from
ForgeFlow:16.0-add-account_multi_foreign_vat
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ff452ea
[ADD] account_multi_foreign_vat
ArnauCForgeFlow 78bfa41
[IMP] account_multi_foreign_vat: allows multiple fp from same country
ArnauCForgeFlow 8b893b1
[IMP] account_multi_foreign_vat: fixed some review comments
ArnauCForgeFlow fa4fe83
[FIX] account_multi_foreign_vat: consider new cases also when creatin…
LoisRForgeFlow 6f98c2d
[IMP][ADD] account_multi_foreign_vat: added tests, and improved readme
ArnauCForgeFlow a9e85dd
[IMP] account_multi_foreign_vat
ArnauCForgeFlow b297be1
[IMP] account_multi_foreign_vat: allow selecting different country taxes
JordiMForgeFlow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (C) 2023 - ForgeFlow S.L. | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Account fiscal position - Multi foreign VAT", | ||
"summary": "Allow having multiple foreign vat with same location", | ||
"version": "16.0.1.0.0", | ||
"author": "ForgeFlow S.L.,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/account-fiscal-rule", | ||
"license": "AGPL-3", | ||
"depends": ["account", "base_vat", "partner_identification"], | ||
"data": [ | ||
"views/account_fiscal_position.xml", | ||
"views/account_move.xml", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import account_fiscal_position | ||
from . import account_move |
54 changes: 54 additions & 0 deletions
54
account_multi_foreign_vat/models/account_fiscal_position.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import logging | ||
|
||
from odoo import _, api, models | ||
from odoo.exceptions import ValidationError | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class AccountFiscalPosition(models.Model): | ||
_inherit = "account.fiscal.position" | ||
|
||
@api.constrains("country_id", "foreign_vat") | ||
def _validate_foreign_vat(self): | ||
for record in self: | ||
try: | ||
super()._validate_foreign_vat() | ||
except Exception as e: | ||
checked_country_code = self.env["res.partner"]._run_vat_test( | ||
record.foreign_vat, record.country_id | ||
) | ||
|
||
if ( | ||
checked_country_code | ||
and record.country_id | ||
and checked_country_code != record.country_id.code.lower() | ||
): | ||
raise ValidationError( | ||
_( | ||
"The country detected for this foreign VAT " | ||
"number does not match the one set on this fiscal position." | ||
) | ||
) from e | ||
if not checked_country_code and not record.country_id: | ||
raise ValidationError( | ||
_("The foreign VAT number is not correct.") | ||
) from e | ||
if not checked_country_code: | ||
fp_label = _("fiscal position [%s]", record.name) | ||
error_message = self.env["res.partner"]._build_vat_error_message( | ||
record.country_id.code.lower(), record.foreign_vat, fp_label | ||
) | ||
raise ValidationError(error_message) from e | ||
return True | ||
|
||
@api.constrains("country_id", "state_ids", "foreign_vat") | ||
def _validate_foreign_vat_country(self): | ||
for _record in self: | ||
try: | ||
super()._validate_foreign_vat_country() | ||
except ValidationError: | ||
_logger.info("Ignored foreign vat country constrains") | ||
except Exception as e: | ||
raise e | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Copyright 2023 ForgeFlow S.L. (https://www.forgeflow.com) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class AccountMove(models.Model): | ||
_inherit = "account.move" | ||
|
||
@api.constrains("line_ids", "fiscal_position_id", "company_id") | ||
def _validate_taxes_country(self): | ||
filtered_self = self.browse() | ||
for record in self: | ||
amls = record.line_ids | ||
impacted_countries = amls.tax_ids.country_id | amls.tax_line_id.country_id | ||
if record.fiscal_position_id.country_group_id and all( | ||
ic in record.fiscal_position_id.country_group_id.country_ids | ||
for ic in impacted_countries | ||
): | ||
continue | ||
if ( | ||
not record.fiscal_position_id.country_group_id | ||
and not record.fiscal_position_id.country_id | ||
): | ||
continue | ||
filtered_self |= record | ||
|
||
return super(AccountMove, filtered_self)._validate_taxes_country() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* ForgeFlow, S.L. (https://www.forgeflow.com) | ||
* Arnau Cruz <arnau.cruz@forgeflow.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* This module allows the user to have multiple fiscal positions for the same country with identical foreign VAT. With this feature, users can efficiently manage distinct fiscal positions within a country, even when they share the same foreign VAT. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* To use this module, users simply need to create two fiscal positions with the same country and foreign VAT. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_account_multi_foreign_vat |
47 changes: 47 additions & 0 deletions
47
account_multi_foreign_vat/tests/test_account_multi_foreign_vat.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from odoo.exceptions import ValidationError | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestAccountMultiForeignVat(TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.country_dk = self.env["res.country"].search([("code", "=", "DK")]) | ||
self.valid_vat_dk = "DK12345674" | ||
self.invalid_vat_dk = "INVALID VAT" | ||
self.fiscal_position_1 = self.env["account.fiscal.position"].create( | ||
{ | ||
"name": "Denmark Fiscal Position 1", | ||
"country_id": self.country_dk.id, | ||
"foreign_vat": self.valid_vat_dk, | ||
} | ||
) | ||
self.fiscal_position_2 = self.env["account.fiscal.position"].create( | ||
{ | ||
"name": "Denmark Fiscal Position 2", | ||
"country_id": self.country_dk.id, | ||
"foreign_vat": self.valid_vat_dk, | ||
} | ||
) | ||
|
||
def test_account_multi_foreign_vat(self): | ||
# Check that 2 fiscal position are created successfully | ||
self.assertTrue(self.fiscal_position_1) | ||
self.assertTrue(self.fiscal_position_2) | ||
|
||
# Check that both fiscal positions have the same foreign_vat and country_id | ||
self.assertEqual( | ||
self.fiscal_position_2.foreign_vat, self.fiscal_position_1.foreign_vat | ||
) | ||
self.assertEqual( | ||
self.fiscal_position_2.country_id, self.fiscal_position_1.country_id | ||
) | ||
|
||
# Check that you cannot enter an invalid vat | ||
with self.assertRaises(ValidationError): | ||
self.env["account.fiscal.position"].create( | ||
{ | ||
"name": "Denmark Fiscal Position 3", | ||
"country_id": self.country_dk.id, | ||
"foreign_vat": self.invalid_vat_dk, | ||
} | ||
) |
20 changes: 20 additions & 0 deletions
20
account_multi_foreign_vat/views/account_fiscal_position.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<record id="account_fiscal_position_form_view" model="ir.ui.view"> | ||
<field | ||
name="name" | ||
>account.fiscal.position.form (in account_multi_foreign_vat)</field> | ||
<field name="model">account.fiscal.position</field> | ||
<field name="inherit_id" ref="account.view_account_position_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//field[@name='country_id']" position="attributes"> | ||
<attribute name="attrs">{}</attribute> | ||
<attribute | ||
name="options" | ||
>{'no_open': True, 'no_create': True}</attribute> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<record id="view_move_form" model="ir.ui.view"> | ||
<field name="name">account.move.form (in account_multi_foreign_vat)</field> | ||
<field name="model">account.move</field> | ||
<field name="inherit_id" ref="account.view_move_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath | ||
expr="//field[@name='invoice_line_ids']/tree/field[@name='tax_ids']" | ||
position="attributes" | ||
> | ||
<attribute | ||
name="domain" | ||
>[('type_tax_use', '=?', parent.invoice_filter_type_domain), ('company_id', '=', parent.company_id)]</attribute> | ||
</xpath> | ||
</field> | ||
</record> | ||
|
||
</odoo> |
1 change: 1 addition & 0 deletions
1
setup/account_multi_foreign_vat/odoo/addons/account_multi_foreign_vat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../account_multi_foreign_vat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the only change done to the standard method? https://github.com/odoo/odoo/blob/7d678cc7f4c9e00d78d4120f703e90bd282c1a51/addons/base_vat/models/account_fiscal_position.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes