Skip to content

Commit

Permalink
[ADD] module grap_custom_import_account_product_fiscal_classification
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Feb 6, 2024
1 parent 190a4e6 commit d335ed8
Show file tree
Hide file tree
Showing 13 changed files with 135 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
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,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_product
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(

Check warning on line 40 in grap_custom_import_account_product_fiscal_classification/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

grap_custom_import_account_product_fiscal_classification/models/product_product.py#L40

Added line #L40 was not covered by tests
_(
"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(

Check warning on line 53 in grap_custom_import_account_product_fiscal_classification/models/product_product.py

View check run for this annotation

Codecov / codecov/patch

grap_custom_import_account_product_fiscal_classification/models/product_product.py#L53

Added line #L53 was not covered by tests
_(
"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

View check run for this annotation

Codecov / codecov/patch

grap_custom_import_account_product_fiscal_classification/models/product_product.py#L62-L63

Added lines #L62 - L63 were not covered by tests
"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")),
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sylvain LE GAL <https://twitter.com/legalsylvain>
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.
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_module
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
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)
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,
)

0 comments on commit d335ed8

Please sign in to comment.