Skip to content

Commit

Permalink
[ADD] fermente_custom_import_product_label
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Nov 24, 2024
1 parent f4bd6eb commit 5b4cbf5
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 0 deletions.
1 change: 1 addition & 0 deletions fermente_custom_import_demo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# OCA
"account_product_fiscal_classification",
"l10n_fr_department_product_origin",
"product_label",
"product_origin",
"product_supplierinfo_qty_multiplier",
"purchase_discount",
Expand Down
Empty file.
1 change: 1 addition & 0 deletions fermente_custom_import_product_label/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions fermente_custom_import_product_label/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (C) 2019 - 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 Product Import - Product Label Module",
"summary": "Extra GRAP Tools to import product data for" " Product Label module",
"version": "16.0.1.0.0",
"category": "Tools",
"author": "GRAP",
"website": "https://github.com/grap/grap-odoo-import",
"license": "AGPL-3",
"depends": ["fermente_custom_import_product", "product_label"],
"auto_install": True,
"installable": True,
}
2 changes: 2 additions & 0 deletions fermente_custom_import_product_label/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import custom_import_product_mixin
from . import product_template
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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 models


class CustomImportProductMixin(models.AbstractModel):
_name = "custom.import.product.mixin"
_inherit = ["custom.import.product.mixin"]

# 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_product_label_vals(old_vals, new_vals)

def _custom_import_handle_product_label_vals(self, old_vals, new_vals):
label_ids = []
for x in range(1, 4):
field_name = f"grap_import_label_{x}"
if old_vals.get(field_name, False):
label_ids.append(old_vals[field_name])
new_vals["label_ids"] = [(6, 0, label_ids)]
# new_vals["label_ids"] = [Command.link(label_ids)]
21 changes: 21 additions & 0 deletions fermente_custom_import_product_label/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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


class ProductTemplate(models.Model):
_inherit = "product.template"

grap_import_label_1 = fields.Many2one(
comodel_name="product.label", string="Label 1 (For import)", store=False
)

grap_import_label_2 = fields.Many2one(
comodel_name="product.label", string="Label 2 (For import)", store=False
)

grap_import_label_3 = fields.Many2one(
comodel_name="product.label", string="Label 3 (For import)", store=False
)
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 fermente_custom_import_product_label/readme/DESCRIPTION.rst
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 ``discount`` field in the supplier info level.
1 change: 1 addition & 0 deletions fermente_custom_import_product_label/tests/__init__.py
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,3 @@
name,uom_id,categ_id,grap_import_label_1,grap_import_label_2,grap_import_label_3
Product 1,Units,All / Saleable,Organic Food,Gluten Free,
Product 2,Units,All / Saleable,,,Max Havelaar
44 changes: 44 additions & 0 deletions fermente_custom_import_product_label/tests/test_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.fermente_custom_import_product.tests.test_module import (
TestModuleProduct,
)


@tagged("post_install", "-at_install")
class TestModulePurchaseDiscount(TestModuleProduct):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.ProductProduct = cls.env["product.product"]
cls.label_organic = cls.env.ref("product_label.label_agriculture_biologique")
cls.label_gluten_free = cls.env.ref("product_label.label_gluten_free")
cls.label_max_havelaar = cls.env.ref("product_label.label_max_havelaar")

def _test_import_product_label(self, model):
products, messages = self._test_import_file(
"fermente_custom_import_product_label",
model,
"product.csv",
folder="product",
)
self.assertFalse(messages)
self.assertEqual(len(products), 2)

product_1 = products.filtered(lambda x: x.name == "Product 1")
self.assertEqual(
product_1.label_ids, self.label_organic | self.label_gluten_free
)

product_2 = products.filtered(lambda x: x.name == "Product 2")
self.assertEqual(product_2.label_ids, self.label_max_havelaar)

def test_01_import_product_label_product(self):
self._test_import_product_label("product.product")

def test_02_import_product_label_template(self):
self._test_import_product_label("product.template")
6 changes: 6 additions & 0 deletions setup/fermente_custom_import_product_label/setup.py
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 5b4cbf5

Please sign in to comment.