Skip to content

Commit

Permalink
[ADD] New module grap_custom_import_product
Browse files Browse the repository at this point in the history
  • Loading branch information
legalsylvain committed Jan 19, 2024
1 parent ed1cac0 commit 1473e22
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 1 deletion.
1 change: 0 additions & 1 deletion grap_custom_import_base/models/custom_import_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def _custom_import_prevent_duplicate_fields(self):
return []

def _custom_import_hook_vals(self, old_vals, new_vals):

# Check if existing duplicates are present in the database
for field in self._custom_import_prevent_duplicate_fields():
if new_vals.get(field):
Expand Down
Empty file.
1 change: 1 addition & 0 deletions grap_custom_import_product/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
16 changes: 16 additions & 0 deletions grap_custom_import_product/__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 Import Product Module",
"summary": "Extra GRAP Tools to import data for product module",
"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_base", "product"],
"auto_install": True,
"installable": True,
}
1 change: 1 addition & 0 deletions grap_custom_import_product/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_product
58 changes: 58 additions & 0 deletions grap_custom_import_product/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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 ResPartner(models.Model):
_name = "product.product"
_inherit = ["product.product", "custom.import.mixin"]

def _custom_import_prevent_duplicate_fields(self):
res = super()._custom_import_prevent_duplicate_fields()
res += ["name", "barcode"]
return res

grap_import_supplier_name = fields.Char(
string="Supplier Name (For import)", store=False
)
grap_import_supplier_product_code = fields.Char(
string="Product Code - Supplier (For import)", store=False
)
grap_import_supplier_product_name = fields.Char(
string="Product Name - Supplier (For import)", store=False
)
grap_import_supplier_min_qty = fields.Monetary(
string="Product Min Quantity - Supplier (For import)", store=False
)
grap_import_supplier_gross_price = fields.Monetary(
string="Product Gross Price - Supplier (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_supplierinfo_vals(old_vals, new_vals)

def _custom_import_handle_supplierinfo_vals(self, old_vals, new_vals):
supplier = self._custom_import_get_or_create(
"res.partner", "name", old_vals, "grap_import_supplier_name"
)
if supplier:
new_vals["seller_ids"] = [
(
0,
False,
self._custom_import_prepare_supplierinfo_vals(supplier, old_vals),
)
]

def _custom_import_prepare_supplierinfo_vals(self, partner, vals):
return {
"partner_id": partner.id,
"price": vals.get("grap_import_supplier_gross_price"),
"product_code": vals.get("grap_import_supplier_product_code"),
"product_name": vals.get("grap_import_supplier_product_name"),
"min_qty": vals.get("grap_import_supplier_min_qty"),
}
1 change: 1 addition & 0 deletions grap_custom_import_product/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Sylvain LE GAL <https://twitter.com/legalsylvain>
9 changes: 9 additions & 0 deletions grap_custom_import_product/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This module improve the "import" features provided by Odoo.

It provides generic tools for that purpose, and improve imports for some models.

* ``product.product``:

* Prevent to create duplicates regarding ``name`` and ``barcode`` fields.

* Allow to create main ``seller_ids``, based on supplier information fields.
1 change: 1 addition & 0 deletions grap_custom_import_product/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,4 @@
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
Coca Cola (Import),Units,All / Saleable / Office Furniture,5000112602791,4.12,Ready Mat,CC,BOTTLE 33CL,3.33
Produit B,Units,All / Saleable / Office Furniture,,8.00,Supplier From Product Import,PB,product_B,6.00
Produit C,Units,All / Saleable,,2.30,,,,
23 changes: 23 additions & 0 deletions grap_custom_import_product/tests/test_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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_base.tests.test_module import TestModuleBase


@tagged("post_install", "-at_install")
class TestModuleProduct(TestModuleBase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.ProductProduct = cls.env["product.product"]

def test_01_import_product(self):
products, messages = self._test_import_file(
"grap_custom_import_product", "product.product", "product.csv"
)
self.assertFalse(messages)
self.assertEqual(len(products), 3)
self.assertIn("Coca Cola (Import)", products.mapped("name"))
6 changes: 6 additions & 0 deletions setup/grap_custom_import_product/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 1473e22

Please sign in to comment.