-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] fermente_custom_import_product_margin_classification
- Loading branch information
1 parent
96ea26a
commit 96eb2e7
Showing
16 changed files
with
164 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+61.9 KB
(790%)
fermente_custom_import_demo/static/xlsx/template_product.xlsx
Binary file not shown.
Empty file.
1 change: 1 addition & 0 deletions
1
fermente_custom_import_product_margin_classification/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
17 changes: 17 additions & 0 deletions
17
fermente_custom_import_product_margin_classification/__manifest__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 Product Import - Product Margin Classification Module", | ||
"summary": "Extra GRAP Tools to import product data for" | ||
" Product Margin Classification 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_margin_classification"], | ||
"auto_install": True, | ||
"installable": True, | ||
} |
2 changes: 2 additions & 0 deletions
2
fermente_custom_import_product_margin_classification/models/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import custom_import_product_mixin | ||
from . import product_template |
50 changes: 50 additions & 0 deletions
50
fermente_custom_import_product_margin_classification/models/custom_import_product_mixin.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# 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 | ||
from odoo.tools import float_compare | ||
|
||
|
||
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_margin_classification_vals(old_vals, new_vals) | ||
|
||
def _custom_import_handle_margin_classification_vals(self, old_vals, new_vals): | ||
profit_margin = ( | ||
"grap_import_margin_rate" in old_vals | ||
and old_vals["grap_import_margin_rate"] * 100 | ||
) | ||
if profit_margin: | ||
# Look for existing classification | ||
classifications = self.env["product.margin.classification"].search([]) | ||
product_classification = False | ||
for classification in classifications: | ||
if not float_compare( | ||
profit_margin, | ||
classification.profit_margin, | ||
precision_rounding=self.env["decimal.precision"].precision_get( | ||
"Margin Rate" | ||
), | ||
): | ||
product_classification = classification | ||
break | ||
|
||
if not product_classification: | ||
# If not found, create a new one | ||
product_classification = self.env[ | ||
"product.margin.classification" | ||
].create( | ||
{ | ||
"name": _( | ||
f"Margin Rate {old_vals['grap_import_margin_rate']} %" | ||
), | ||
"markup": 100 * (profit_margin / (100 - profit_margin)), | ||
} | ||
) | ||
new_vals["margin_classification_id"] = product_classification.id |
13 changes: 13 additions & 0 deletions
13
fermente_custom_import_product_margin_classification/models/product_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# 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_margin_rate = fields.Float( | ||
string="Margin Rate (For import)", store=False | ||
) |
1 change: 1 addition & 0 deletions
1
fermente_custom_import_product_margin_classification/readme/CONTRIBUTORS.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Sylvain LE GAL <https://twitter.com/legalsylvain> |
6 changes: 6 additions & 0 deletions
6
fermente_custom_import_product_margin_classification/readme/DESCRIPTION.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
This module improve the "import" features provided by Odoo. | ||
|
||
* ``product.product``: | ||
|
||
* Create a margin classification if it doens't exist, | ||
with the correct margin rate amount. |
1 change: 1 addition & 0 deletions
1
fermente_custom_import_product_margin_classification/tests/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_module |
5 changes: 5 additions & 0 deletions
5
fermente_custom_import_product_margin_classification/tests/templates/product/product.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
name,uom_id,categ_id,grap_import_margin_rate | ||
Product 1,Units,All / Saleable,0.333333 | ||
Product 2,Units,All / Saleable,0.5 | ||
Product 3,Units,All / Saleable,0.4123 | ||
Product 4,Units,All / Saleable,0.4123 |
51 changes: 51 additions & 0 deletions
51
fermente_custom_import_product_margin_classification/tests/test_module.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# 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.margin_33 = cls.env.ref( | ||
"product_margin_classification.classification_normal_margin" | ||
) | ||
cls.margin_50 = cls.env.ref( | ||
"product_margin_classification.classification_big_margin" | ||
) | ||
|
||
def _test_import_product_margin_classification(self, model): | ||
products, messages = self._test_import_file( | ||
"fermente_custom_import_product_margin_classification", | ||
model, | ||
"product.csv", | ||
folder="product", | ||
) | ||
self.assertFalse(messages) | ||
self.assertEqual(len(products), 4) | ||
|
||
product_1 = products.filtered(lambda x: x.name == "Product 1") | ||
self.assertEqual(product_1.margin_classification_id, self.margin_33) | ||
|
||
product_2 = products.filtered(lambda x: x.name == "Product 2") | ||
self.assertEqual(product_2.margin_classification_id, self.margin_50) | ||
|
||
product_3 = products.filtered(lambda x: x.name == "Product 3") | ||
product_4 = products.filtered(lambda x: x.name == "Product 4") | ||
self.assertEqual( | ||
product_3.margin_classification_id, product_4.margin_classification_id | ||
) | ||
|
||
def test_01_import_product_margin_classification_product(self): | ||
self._test_import_product_margin_classification("product.product") | ||
|
||
def test_02_import_product_margin_classification_template(self): | ||
self._test_import_product_margin_classification("product.template") |
1 change: 1 addition & 0 deletions
1
...ct_margin_classification/odoo/addons/fermente_custom_import_product_margin_classification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../fermente_custom_import_product_margin_classification |
6 changes: 6 additions & 0 deletions
6
setup/fermente_custom_import_product_margin_classification/setup.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |