Skip to content

Commit dcd5fd9

Browse files
committed
[ADD] fermente_custom_import_product_label
1 parent f4bd6eb commit dcd5fd9

File tree

15 files changed

+128
-0
lines changed

15 files changed

+128
-0
lines changed

fermente_custom_import_demo/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# OCA
1515
"account_product_fiscal_classification",
1616
"l10n_fr_department_product_origin",
17+
"product_label",
1718
"product_origin",
1819
"product_supplierinfo_qty_multiplier",
1920
"purchase_discount",

fermente_custom_import_product_label/README.rst

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (C) 2019 - 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+
{
6+
"name": "GRAP - Custom Product Import - Product Label Module",
7+
"summary": "Extra GRAP Tools to import product data for" " Product Label module",
8+
"version": "16.0.1.0.0",
9+
"category": "Tools",
10+
"author": "GRAP",
11+
"website": "https://github.com/grap/grap-odoo-import",
12+
"license": "AGPL-3",
13+
"depends": ["fermente_custom_import_product", "product_label"],
14+
"auto_install": True,
15+
"installable": True,
16+
}
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
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 models
6+
7+
8+
class CustomImportProductMixin(models.AbstractModel):
9+
_name = "custom.import.product.mixin"
10+
_inherit = ["custom.import.product.mixin"]
11+
12+
# pylint: disable=missing-return
13+
def _custom_import_hook_vals(self, old_vals, new_vals):
14+
super()._custom_import_hook_vals(old_vals, new_vals)
15+
self._custom_import_handle_product_label_vals(old_vals, new_vals)
16+
17+
def _custom_import_handle_product_label_vals(self, old_vals, new_vals):
18+
label_ids = []
19+
for x in range(1, 4):
20+
field_name = f"grap_import_label_{x}"
21+
if old_vals.get(field_name, False):
22+
label_ids.append(old_vals[field_name])
23+
new_vals["label_ids"] = [(6, 0, label_ids)]
24+
# new_vals["label_ids"] = [Command.link(label_ids)]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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_label_1 = fields.Many2one(
12+
comodel_name="product.label", string="Label 1 (For import)", store=False
13+
)
14+
15+
grap_import_label_2 = fields.Many2one(
16+
comodel_name="product.label", string="Label 2 (For import)", store=False
17+
)
18+
19+
grap_import_label_3 = fields.Many2one(
20+
comodel_name="product.label", string="Label 3 (For import)", store=False
21+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Sylvain LE GAL <https://twitter.com/legalsylvain>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This module improve the "import" features provided by Odoo.
2+
3+
* ``product.product``:
4+
5+
* Allow to recover ``discount`` field in the supplier info level.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_module
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_label_1,grap_import_label_2,grap_import_label_3
2+
Product 1,Units,All / Saleable,Organic Food,Gluten Free,
3+
Product 2,Units,All / Saleable,,,Max Havelaar
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 TestModulePurchaseDiscount(TestModuleProduct):
14+
@classmethod
15+
def setUpClass(cls):
16+
super().setUpClass()
17+
cls.ProductProduct = cls.env["product.product"]
18+
cls.label_organic = cls.env.ref("product_label.label_agriculture_biologique")
19+
cls.label_gluten_free = cls.env.ref("product_label.label_gluten_free")
20+
cls.label_max_havelaar = cls.env.ref("product_label.label_max_havelaar")
21+
22+
def _test_import_product_label(self, model):
23+
products, messages = self._test_import_file(
24+
"fermente_custom_import_product_label",
25+
model,
26+
"product.csv",
27+
folder="product",
28+
)
29+
self.assertFalse(messages)
30+
self.assertEqual(len(products), 2)
31+
32+
product_1 = products.filtered(lambda x: x.name == "Product 1")
33+
self.assertEqual(
34+
product_1.label_ids, self.label_organic | self.label_gluten_free
35+
)
36+
37+
product_2 = products.filtered(lambda x: x.name == "Product 2")
38+
self.assertEqual(product_2.label_ids, self.label_max_havelaar)
39+
40+
def test_01_import_product_label_product(self):
41+
self._test_import_product_label("product.product")
42+
43+
def test_02_import_product_label_template(self):
44+
self._test_import_product_label("product.template")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../../../fermente_custom_import_product_label
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
setup_requires=['setuptools-odoo'],
5+
odoo_addon=True,
6+
)

test-requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# grap/grap-odoo-business
2+
git+https://github.com/grap/grap-odoo-business@12.0#subdirectory=setup/product_label

0 commit comments

Comments
 (0)