-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] module grap_custom_import_account_product_fiscal_classification
- Loading branch information
1 parent
190a4e6
commit d335ed8
Showing
13 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
1 change: 1 addition & 0 deletions
1
grap_custom_import_account_product_fiscal_classification/__init__.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 @@ | ||
from . import models |
17 changes: 17 additions & 0 deletions
17
grap_custom_import_account_product_fiscal_classification/__manifest__.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,17 @@ | ||
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "GRAP - Custom Import Fiscal Classification", | ||
"summary": "Extra GRAP Tools to import data for" | ||
" Account Product Fiscal Classification", | ||
"version": "16.0.1.0.0", | ||
"category": "Tools", | ||
"author": "GRAP", | ||
"website": "https://github.com/grap/grap-odoo-import", | ||
"license": "AGPL-3", | ||
"depends": ["grap_custom_import_product", "account_product_fiscal_classification"], | ||
"auto_install": True, | ||
"installable": True, | ||
} |
1 change: 1 addition & 0 deletions
1
grap_custom_import_account_product_fiscal_classification/models/__init__.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 @@ | ||
from . import product_product |
70 changes: 70 additions & 0 deletions
70
grap_custom_import_account_product_fiscal_classification/models/product_product.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,70 @@ | ||
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import _, fields, models | ||
from odoo.exceptions import ValidationError | ||
from odoo.osv import expression | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = "product.product" | ||
|
||
grap_import_vat_amount = fields.Float(string="VAT Amount (For import)", store=False) | ||
|
||
# pylint: disable=missing-return | ||
def _custom_import_hook_vals(self, old_vals, new_vals): | ||
super()._custom_import_hook_vals(old_vals, new_vals) | ||
self._custom_import_handle_fiscal_classification_id(old_vals, new_vals) | ||
|
||
def _custom_import_get_fiscal_classifications(self, vat_amount): | ||
domain = expression.OR( | ||
[[("company_id", "=", self.env.company.id)], [("company_id", "=", False)]] | ||
) | ||
if vat_amount: | ||
domain = expression.AND( | ||
[domain, [("sale_tax_ids.amount", "=", 100 * vat_amount)]] | ||
) | ||
else: | ||
domain = expression.AND([domain, [("sale_tax_ids", "=", False)]]) | ||
|
||
return ( | ||
self.env["account.product.fiscal.classification"] | ||
.search(domain) | ||
.filtered(lambda x: len(x.sale_tax_ids) < 2) | ||
) | ||
|
||
def _custom_import_handle_fiscal_classification_id(self, old_vals, new_vals): | ||
vat_amount = old_vals.get("grap_import_vat_amount") | ||
if not vat_amount and not self.env.context.get("install_mode"): | ||
raise ValidationError( | ||
_( | ||
"No VAT Amount found for the product %(product_name)s", | ||
product_name=old_vals.get("name"), | ||
) | ||
) | ||
classifications = self._custom_import_get_fiscal_classifications(vat_amount) | ||
|
||
if len(classifications) == 1: | ||
new_vals["fiscal_classification_id"] = classifications.id | ||
return | ||
|
||
elif len(classifications) == 0: | ||
raise ValidationError( | ||
_( | ||
"No Fiscal Classification Found for the product %(product_name)s." | ||
" Vat Amount %(vat_amount)s", | ||
product_name=old_vals.get("name"), | ||
vat_amount=vat_amount, | ||
) | ||
) | ||
|
||
raise ValidationError( | ||
_( | ||
Check warning on line 63 in grap_custom_import_account_product_fiscal_classification/models/product_product.py Codecov / codecov/patchgrap_custom_import_account_product_fiscal_classification/models/product_product.py#L62-L63
|
||
"Many Fiscal Classifications Found for the product %(product_name)s." | ||
" Vat Amount %(vat_amount)s. Fiscal Classifications : %(classification_names)s", | ||
product_name=old_vals.get("name"), | ||
vat_amount=vat_amount, | ||
classification_names=",".join(classifications.mapped("name")), | ||
) | ||
) |
1 change: 1 addition & 0 deletions
1
grap_custom_import_account_product_fiscal_classification/readme/CONTRIBUTORS.rst
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 @@ | ||
* Sylvain LE GAL <https://twitter.com/legalsylvain> |
5 changes: 5 additions & 0 deletions
5
grap_custom_import_account_product_fiscal_classification/readme/DESCRIPTION.rst
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,5 @@ | ||
This module improve the "import" features provided by Odoo. | ||
|
||
* ``product.product``: | ||
|
||
* Allow to recover ``multiplier_qty`` field in the supplier info level. |
2 changes: 2 additions & 0 deletions
2
grap_custom_import_account_product_fiscal_classification/readme/ROADMAP.rst
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 @@ | ||
* handle selection of classifications for ``recurring_consignment``, | ||
once the module is ported in V16. |
1 change: 1 addition & 0 deletions
1
grap_custom_import_account_product_fiscal_classification/tests/__init__.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 @@ | ||
from . import test_module |
2 changes: 2 additions & 0 deletions
2
..._import_account_product_fiscal_classification/tests/templates/product.product/product.csv
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 @@ | ||
name,uom_id,categ_id,barcode,list_price,grap_import_supplier_name,grap_import_supplier_product_code,grap_import_supplier_product_name,grap_import_supplier_gross_price,grap_import_vat_amount | ||
Mention Good (Late chocolate),Units,All / Saleable,3222472195092,2.29,Ready Mat,GOOD,MENTION GOOD,1.98,0.20 |
28 changes: 28 additions & 0 deletions
28
grap_custom_import_account_product_fiscal_classification/tests/test_module.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,28 @@ | ||
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop) | ||
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo.tests import tagged | ||
|
||
from odoo.addons.grap_custom_import_product.tests.test_module import TestModuleProduct | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestModuleProductSupplierinfoQtyMultiplier(TestModuleProduct): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.ProductProduct = cls.env["product.product"] | ||
cls.classification_20 = cls.env.ref( | ||
"account_product_fiscal_classification.fiscal_classification_A_company_1" | ||
) | ||
|
||
def test_01_import_product_account_product_fiscal_classification(self): | ||
products, messages = self._test_import_file( | ||
"grap_custom_import_account_product_fiscal_classification", | ||
"product.product", | ||
"product.csv", | ||
) | ||
self.assertFalse(messages) | ||
self.assertEqual(len(products), 1) | ||
self.assertEqual(products.fiscal_classification_id, self.classification_20) |
1 change: 1 addition & 0 deletions
1
...iscal_classification/odoo/addons/grap_custom_import_account_product_fiscal_classification
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 @@ | ||
../../../../grap_custom_import_account_product_fiscal_classification |
6 changes: 6 additions & 0 deletions
6
setup/grap_custom_import_account_product_fiscal_classification/setup.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,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |