Skip to content

Commit e4ece4c

Browse files
Merge PR #3 into 16.0
Signed-off-by legalsylvain
2 parents 3d78e37 + 3eccf28 commit e4ece4c

File tree

148 files changed

+1125
-212
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+1125
-212
lines changed

grap_custom_import_account_product_fiscal_classification/README.rst renamed to fermente_custom_import_account_product_fiscal_classification/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ GRAP - Custom Import Fiscal Classification
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-grap%2Fgrap--odoo--import-lightgray.png?logo=github
20-
:target: https://github.com/grap/grap-odoo-import/tree/16.0/grap_custom_import_account_product_fiscal_classification
20+
:target: https://github.com/grap/grap-odoo-import/tree/16.0/fermente_custom_import_account_product_fiscal_classification
2121
:alt: grap/grap-odoo-import
2222

2323
|badge1| |badge2| |badge3|
@@ -45,7 +45,7 @@ Bug Tracker
4545
Bugs are tracked on `GitHub Issues <https://github.com/grap/grap-odoo-import/issues>`_.
4646
In case of trouble, please check there if your issue has already been reported.
4747
If you spotted it first, help us to smash it by providing a detailed and welcomed
48-
`feedback <https://github.com/grap/grap-odoo-import/issues/new?body=module:%20grap_custom_import_account_product_fiscal_classification%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
48+
`feedback <https://github.com/grap/grap-odoo-import/issues/new?body=module:%20fermente_custom_import_account_product_fiscal_classification%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
4949

5050
Do not contact contributors directly about support or help with technical issues.
5151

@@ -65,6 +65,6 @@ Contributors
6565
Maintainers
6666
~~~~~~~~~~~
6767

68-
This module is part of the `grap/grap-odoo-import <https://github.com/grap/grap-odoo-import/tree/16.0/grap_custom_import_account_product_fiscal_classification>`_ project on GitHub.
68+
This module is part of the `grap/grap-odoo-import <https://github.com/grap/grap-odoo-import/tree/16.0/fermente_custom_import_account_product_fiscal_classification>`_ project on GitHub.
6969

7070
You are welcome to contribute.

grap_custom_import_account_product_fiscal_classification/__manifest__.py renamed to fermente_custom_import_account_product_fiscal_classification/__manifest__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
44

55
{
6-
"name": "GRAP - Custom Import Fiscal Classification",
7-
"summary": "Extra GRAP Tools to import data for"
6+
"name": "GRAP - Custom Product Import - Fiscal Classification Module",
7+
"summary": "Extra GRAP Tools to import product data for"
88
" Account Product Fiscal Classification",
99
"version": "16.0.1.0.0",
1010
"category": "Tools",
1111
"author": "GRAP",
1212
"website": "https://github.com/grap/grap-odoo-import",
1313
"license": "AGPL-3",
14-
"depends": ["grap_custom_import_product", "account_product_fiscal_classification"],
14+
"depends": [
15+
"fermente_custom_import_product",
16+
"account_product_fiscal_classification",
17+
],
1518
"auto_install": True,
1619
"installable": True,
1720
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import custom_import_product_mixin
2+
from . import product_template

grap_custom_import_account_product_fiscal_classification/models/product_product.py renamed to fermente_custom_import_account_product_fiscal_classification/models/custom_import_product_mixin.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
44

5-
from odoo import _, fields, models
5+
from odoo import _, models
66
from odoo.exceptions import ValidationError
77
from odoo.osv import expression
88

99

10-
class ProductProduct(models.Model):
11-
_inherit = "product.product"
10+
class CustomImportProductMixin(models.AbstractModel):
11+
_name = "custom.import.product.mixin"
12+
_inherit = ["custom.import.product.mixin"]
1213

13-
grap_import_vat_amount = fields.Float(string="VAT Amount (For import)", store=False)
14-
15-
# pylint: disable=missing-return
1614
def _custom_import_hook_vals(self, old_vals, new_vals):
1715
super()._custom_import_hook_vals(old_vals, new_vals)
1816
self._custom_import_handle_fiscal_classification_id(old_vals, new_vals)
17+
return
1918

20-
def _custom_import_get_fiscal_classifications(self, vat_amount):
19+
def _custom_import_fiscal_classification_domain(self, vat_amount):
2120
domain = expression.OR(
2221
[[("company_id", "=", self.env.company.id)], [("company_id", "=", False)]]
2322
)
@@ -28,11 +27,7 @@ def _custom_import_get_fiscal_classifications(self, vat_amount):
2827
else:
2928
domain = expression.AND([domain, [("sale_tax_ids", "=", False)]])
3029

31-
return (
32-
self.env["account.product.fiscal.classification"]
33-
.search(domain)
34-
.filtered(lambda x: len(x.sale_tax_ids) < 2)
35-
)
30+
return domain
3631

3732
def _custom_import_handle_fiscal_classification_id(self, old_vals, new_vals):
3833
vat_amount = old_vals.get("grap_import_vat_amount")
@@ -43,11 +38,16 @@ def _custom_import_handle_fiscal_classification_id(self, old_vals, new_vals):
4338
product_name=old_vals.get("name"),
4439
)
4540
)
46-
classifications = self._custom_import_get_fiscal_classifications(vat_amount)
41+
domain = self._custom_import_fiscal_classification_domain(vat_amount)
42+
43+
classifications = (
44+
self.env["account.product.fiscal.classification"]
45+
.search(domain)
46+
.filtered(lambda x: len(x.sale_tax_ids) < 2)
47+
)
4748

4849
if len(classifications) == 1:
4950
new_vals["fiscal_classification_id"] = classifications.id
50-
return
5151

5252
elif len(classifications) == 0:
5353
raise ValidationError(
@@ -58,13 +58,24 @@ def _custom_import_handle_fiscal_classification_id(self, old_vals, new_vals):
5858
vat_amount=vat_amount,
5959
)
6060
)
61-
62-
raise ValidationError(
63-
_(
64-
"Many Fiscal Classifications Found for the product %(product_name)s."
65-
" Vat Amount %(vat_amount)s. Fiscal Classifications : %(classification_names)s",
66-
product_name=old_vals.get("name"),
67-
vat_amount=vat_amount,
68-
classification_names=",".join(classifications.mapped("name")),
61+
else:
62+
raise ValidationError(
63+
_(
64+
"Many Fiscal Classifications Found for the product %(product_name)s."
65+
" Vat Amount %(vat_amount)s."
66+
" Fiscal Classifications : %(classification_names)s",
67+
product_name=old_vals.get("name"),
68+
vat_amount=vat_amount,
69+
classification_names=",".join(classifications.mapped("name")),
70+
)
6971
)
70-
)
72+
73+
# If Specific Vat Excl / VAT Incl field are set, we use it, depending of the
74+
# the configuration of the fiscal classification
75+
if (
76+
all(classifications.mapped("sale_tax_ids.price_include"))
77+
and "grap_import_list_price_vat_incl" in old_vals
78+
):
79+
new_vals["list_price"] = old_vals["grap_import_list_price_vat_incl"]
80+
elif "grap_import_list_price_vat_excl" in old_vals:
81+
new_vals["list_price"] = old_vals["grap_import_list_price_vat_excl"]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
2+
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from odoo import fields, models
6+
7+
8+
class ProductTemplate(models.Model):
9+
_inherit = "product.template"
10+
11+
grap_import_vat_amount = fields.Float(string="VAT Amount (For import)", store=False)
12+
13+
grap_import_list_price_vat_excl = fields.Float(
14+
string="Sale Price Vat Excl (For import)", store=False
15+
)
16+
17+
grap_import_list_price_vat_incl = fields.Float(
18+
string="Sale Price Vat Incl (For import)", store=False
19+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name,uom_id,categ_id,grap_import_vat_amount,grap_import_list_price_vat_excl,grap_import_list_price_vat_incl
2+
Product 1,Units,All / Saleable,0.20,1,1.21
3+
Product 2,Units,All / Saleable,0.20,0.99,1.20
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
2+
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from odoo.tests import tagged
6+
7+
from odoo.addons.fermente_custom_import_product.tests.test_module import (
8+
TestModuleProduct,
9+
)
10+
11+
12+
@tagged("post_install", "-at_install")
13+
class TestModuleProductSupplierinfoQtyMultiplier(TestModuleProduct):
14+
@classmethod
15+
def setUpClass(cls):
16+
super().setUpClass()
17+
cls.classification_20 = cls.env.ref(
18+
"account_product_fiscal_classification.fiscal_classification_A_company_1"
19+
)
20+
cls.tax_20 = cls.env.ref(
21+
"account_product_fiscal_classification.account_tax_sale_20_company_1"
22+
)
23+
24+
def _test_import_product_account_product_fiscal_classification(
25+
self, model, vat_included
26+
):
27+
products, messages = self._test_import_file(
28+
"fermente_custom_import_account_product_fiscal_classification",
29+
model,
30+
"product.csv",
31+
folder="product",
32+
)
33+
self.assertFalse(messages)
34+
self.assertEqual(len(products), 2)
35+
36+
product_1 = products.filtered(lambda x: x.name == "Product 1")
37+
self.assertEqual(product_1.fiscal_classification_id, self.classification_20)
38+
39+
product_2 = products.filtered(lambda x: x.name == "Product 2")
40+
self.assertEqual(product_2.fiscal_classification_id, self.classification_20)
41+
42+
if vat_included:
43+
self.assertEqual(product_1.list_price, 1.21)
44+
self.assertEqual(product_2.list_price, 1.20)
45+
else:
46+
self.assertEqual(product_1.list_price, 1.00)
47+
self.assertEqual(product_2.list_price, 0.99)
48+
49+
def test_01_import_product_account_product_fiscal_classification_product_vat_excl(
50+
self,
51+
):
52+
self.tax_20.price_include = False
53+
self._test_import_product_account_product_fiscal_classification(
54+
"product.product", False
55+
)
56+
57+
def test_02_import_product_account_product_fiscal_classification_product_vat_incl(
58+
self,
59+
):
60+
self.tax_20.price_include = True
61+
self._test_import_product_account_product_fiscal_classification(
62+
"product.product", True
63+
)
64+
65+
def test_11_import_product_account_product_fiscal_classification_template_vat_excl(
66+
self,
67+
):
68+
self.tax_20.price_include = False
69+
self._test_import_product_account_product_fiscal_classification(
70+
"product.template", False
71+
)
72+
73+
def test_12_import_product_account_product_fiscal_classification_template_vat_incl(
74+
self,
75+
):
76+
self.tax_20.price_include = True
77+
self._test_import_product_account_product_fiscal_classification(
78+
"product.template", True
79+
)

grap_custom_import_base/README.rst renamed to fermente_custom_import_base/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ GRAP - Custom Import Base Module
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-grap%2Fgrap--odoo--import-lightgray.png?logo=github
20-
:target: https://github.com/grap/grap-odoo-import/tree/16.0/grap_custom_import_base
20+
:target: https://github.com/grap/grap-odoo-import/tree/16.0/fermente_custom_import_base
2121
:alt: grap/grap-odoo-import
2222

2323
|badge1| |badge2| |badge3|
@@ -41,7 +41,7 @@ Bug Tracker
4141
Bugs are tracked on `GitHub Issues <https://github.com/grap/grap-odoo-import/issues>`_.
4242
In case of trouble, please check there if your issue has already been reported.
4343
If you spotted it first, help us to smash it by providing a detailed and welcomed
44-
`feedback <https://github.com/grap/grap-odoo-import/issues/new?body=module:%20grap_custom_import_base%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
44+
`feedback <https://github.com/grap/grap-odoo-import/issues/new?body=module:%20fermente_custom_import_base%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
4545

4646
Do not contact contributors directly about support or help with technical issues.
4747

@@ -61,6 +61,6 @@ Contributors
6161
Maintainers
6262
~~~~~~~~~~~
6363

64-
This module is part of the `grap/grap-odoo-import <https://github.com/grap/grap-odoo-import/tree/16.0/grap_custom_import_base>`_ project on GitHub.
64+
This module is part of the `grap/grap-odoo-import <https://github.com/grap/grap-odoo-import/tree/16.0/fermente_custom_import_base>`_ project on GitHub.
6565

6666
You are welcome to contribute.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from . import custom_import_mixin
2+
from . import custom_import_partner_mixin
23
from . import res_partner

grap_custom_import_base/models/custom_import_mixin.py renamed to fermente_custom_import_base/models/custom_import_mixin.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def _custom_import_hook_vals(self, old_vals, new_vals):
3131
)
3232
return new_vals
3333

34+
def _custom_import_hook_check(self, vals_list):
35+
self._custom_import_check_duplicates_new_vals(vals_list)
36+
3437
def _custom_import_check_duplicates_new_vals(self, vals_list):
3538
for field in self._custom_import_prevent_duplicate_fields():
3639
duplicates = []
@@ -72,11 +75,19 @@ def _custom_import_get_or_create(
7275

7376
# Overload Section
7477
def _load_records_create(self, vals_list):
78+
# This function is called in many places in odoo Core
79+
# to create records, specially when loading
80+
# 'demo' or 'data' from xml files.
81+
# We only want to alter data in a 'import' process.
82+
if not self.env.context.get("import_file"):
83+
return super()._load_records_create(vals_list)
84+
7585
new_vals_list = []
7686
for vals in vals_list:
7787
new_vals = vals.copy()
7888
self._custom_import_hook_vals(vals, new_vals)
7989
new_vals_list.append(new_vals)
80-
# TODO, move this check in another part
81-
self._custom_import_check_duplicates_new_vals(new_vals_list)
90+
91+
self._custom_import_hook_check(new_vals_list)
92+
8293
return super()._load_records_create(new_vals_list)

grap_custom_import_base/models/res_partner.py renamed to fermente_custom_import_base/models/custom_import_partner_mixin.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
44

5-
import logging
6-
75
from odoo import models
86

9-
logger = logging.getLogger(__name__)
10-
117

12-
class ResPartner(models.Model):
13-
_name = "res.partner"
14-
_inherit = ["res.partner", "custom.import.mixin"]
8+
class CustomImportPartnerMixin(models.AbstractModel):
9+
_name = "custom.import.partner.mixin"
10+
_description = "Abstract model to import partner (customer and supplier)"
11+
_inherit = ["custom.import.mixin"]
1512

1613
def _custom_import_prevent_duplicate_fields(self):
1714
res = super()._custom_import_prevent_duplicate_fields()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Copyright (C) 2024 - Today: GRAP (http://www.grap.coop)
2+
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
import logging
6+
7+
from odoo import models
8+
9+
logger = logging.getLogger(__name__)
10+
11+
12+
class ResPartner(models.Model):
13+
_name = "res.partner"
14+
_inherit = ["res.partner", "custom.import.partner.mixin"]

grap_custom_import_base/readme/DESCRIPTION.rst renamed to fermente_custom_import_base/readme/DESCRIPTION.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ It provides generic tools for that purpose, and improve imports for some models.
44

55
* ``res.partner``:
66

7-
* Prevent to create duplicates regarding ``name`` and ``vat`` fields.
7+
* Prevent to create duplicates regarding ``name`` and ``vat`` fields.
8+
9+
TO FINISH
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import test_module
2+
from . import test_module_partner
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
name,email,phone,mobile,website,street,street2,zip,city,country_id,vat
2+
Azure Interior,,,,,,,,,,

0 commit comments

Comments
 (0)