-
-
Notifications
You must be signed in to change notification settings - Fork 715
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] product_ingredient: New module
- Loading branch information
1 parent
4e2a9e1
commit 3612d4a
Showing
22 changed files
with
844 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
=================== | ||
Product Ingredients | ||
=================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:1dc7d3334f8ad49a0cd0b9009ef8e79c847ce6603f4dc701c86765ab23097d56 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
:target: https://odoo-community.org/page/development-status | ||
:alt: Beta | ||
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html | ||
:alt: License: AGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproduct--attribute-lightgray.png?logo=github | ||
:target: https://github.com/OCA/product-attribute/tree/15.0/product_ingredient | ||
:alt: OCA/product-attribute | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/product-attribute-15-0/product-attribute-15-0-product_ingredient | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/product-attribute&target_branch=15.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows to set ingredients information for a given product. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
To use this module you have to: | ||
|
||
- Create or edit a product variant or product template with just a variant. | ||
- Go to ingredients page | ||
- Create some ingredients for the product. | ||
|
||
Now you can print the "Ingredients Info" report label. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/product-attribute/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/product-attribute/issues/new?body=module:%20product_ingredient%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Tecnativa | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Tecnativa <https://www.tecnativa.com>`_ | ||
|
||
* Sergio Teruel | ||
* Carlos Dauden | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
This module is maintained by the OCA. | ||
|
||
.. image:: https://odoo-community.org/logo.png | ||
:alt: Odoo Community Association | ||
:target: https://odoo-community.org | ||
|
||
OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
mission is to support the collaborative development of Odoo features and | ||
promote its widespread use. | ||
|
||
.. |maintainer-sergio-teruel| image:: https://github.com/sergio-teruel.png?size=40px | ||
:target: https://github.com/sergio-teruel | ||
:alt: sergio-teruel | ||
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-sergio-teruel| | ||
|
||
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/15.0/product_ingredient>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
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 |
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,24 @@ | ||
# Copyright 2023 Tecnativa - Sergio Teruel | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Product Ingredients", | ||
"summary": "Product ingredients", | ||
"version": "15.0.1.0.0", | ||
"development_status": "Beta", | ||
"category": "Technical Settings", | ||
"website": "https://github.com/OCA/product-attribute", | ||
"author": "Tecnativa, Odoo Community Association (OCA)", | ||
"maintainers": ["sergio-teruel"], | ||
"license": "AGPL-3", | ||
"depends": ["product", "stock"], | ||
"data": [ | ||
"security/ir.model.access.csv", | ||
"data/product_allergen_data.xml", | ||
"views/product_attribute_value_views.xml", | ||
"views/product_ingredient_views.xml", | ||
"views/product_views.xml", | ||
"views/stock_production_lot_view.xml", | ||
], | ||
"application": False, | ||
"installable": True, | ||
} |
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,10 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo noupdate="1"> | ||
|
||
<record id="product_allergen_attribute" model="product.attribute"> | ||
<field name="name">Allergens</field> | ||
<field name="create_variant">no_variant</field> | ||
<field name="display_type">select</field> | ||
</record> | ||
|
||
</odoo> |
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 @@ | ||
from . import stock_production_lot | ||
from . import product_ingredient | ||
from . import product_ingredient_value | ||
from . import production_lot_ingredient_value | ||
from . import product_product | ||
from . import product_template |
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,24 @@ | ||
# Copyright 2023 Tecnativa - Sergio Teruel | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class ProductIngredients(models.Model): | ||
_name = "product.ingredient" | ||
_description = "Ingredients of a product." | ||
|
||
def _get_allergen_attribute_domain(self): | ||
return [ | ||
( | ||
"attribute_id", | ||
"=", | ||
self.env.ref("product_ingredient.product_allergen_attribute").id, | ||
) | ||
] | ||
|
||
name = fields.Char(translate=True) | ||
scientific_name = fields.Char(translate=True) | ||
allergen_id = fields.Many2one( | ||
comodel_name="product.attribute.value", | ||
domain=lambda self: self._get_allergen_attribute_domain(), | ||
) |
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 2023 Tecnativa - Sergio Teruel | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class ProductIngredientValue(models.Model): | ||
_name = "product.ingredient.value" | ||
_description = "Ingredient values for a product." | ||
_rec_name = "ingredient_id" | ||
_order = "sequence, id" | ||
|
||
sequence = fields.Integer() | ||
product_id = fields.Many2one(comodel_name="product.product") | ||
ingredient_id = fields.Many2one(comodel_name="product.ingredient") | ||
scientific_name = fields.Char(related="ingredient_id.scientific_name") | ||
allergen_id = fields.Many2one(related="ingredient_id.allergen_id") | ||
percentage = fields.Float(digits="Product Unit of Measure") |
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,11 @@ | ||
# Copyright 2023 Tecnativa - Sergio Teruel | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = "product.product" | ||
|
||
ingredient_ids = fields.One2many( | ||
comodel_name="product.ingredient.value", inverse_name="product_id" | ||
) |
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,33 @@ | ||
# Copyright 2023 Tecnativa - Sergio Teruel | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
allergens_ids = fields.Many2many( | ||
comodel_name="product.attribute.value", compute="_compute_allergens_ids" | ||
) | ||
ingredient_ids = fields.One2many( | ||
related="product_variant_ids.ingredient_ids", readonly=False | ||
) | ||
|
||
def _compute_allergens_ids(self): | ||
self._set_attribute_values( | ||
"product_fishing.product_allergens_attribute", "allergens_ids" | ||
) | ||
|
||
def _set_attribute_values(self, attribute_ref, field_name): | ||
""" | ||
Helper method to retrieve the allergen data from product attributes | ||
""" | ||
attribute = self.env.ref(attribute_ref) | ||
ptal_obj = self.env["product.template.attribute.line"] | ||
attribute_lines = ptal_obj.search( | ||
[("product_tmpl_id", "in", self.ids), ("attribute_id", "=", attribute.id)] | ||
) | ||
for template in self: | ||
template[field_name] = attribute_lines.filtered( | ||
lambda att_line: att_line.product_tmpl_id == template | ||
).value_ids |
18 changes: 18 additions & 0 deletions
18
product_ingredient/models/production_lot_ingredient_value.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,18 @@ | ||
# Copyright 2023 Tecnativa - Sergio Teruel | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import fields, models | ||
|
||
|
||
class ProductionLotIngredientValue(models.Model): | ||
_name = "production.lot.ingredient.value" | ||
_description = "Ingredient values for a product lots." | ||
_rec_name = "ingredient_id" | ||
_order = "sequence, id" | ||
|
||
sequence = fields.Integer() | ||
lot_id = fields.Many2one(comodel_name="stock.production.lot") | ||
# product_id = fields.Many2one(related='lot_id.product_id') | ||
ingredient_id = fields.Many2one(comodel_name="product.ingredient") | ||
scientific_name = fields.Char(related="ingredient_id.scientific_name") | ||
allergen_id = fields.Many2one(related="ingredient_id.allergen_id") | ||
percentage = fields.Float(digits="Product Unit of Measure") |
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,28 @@ | ||
# Copyright 2023 Tecnativa - Sergio Teruel | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import api, fields, models | ||
|
||
|
||
class StockProductionLot(models.Model): | ||
_inherit = "stock.production.lot" | ||
|
||
ingredient_ids = fields.One2many( | ||
comodel_name="production.lot.ingredient.value", | ||
inverse_name="lot_id", | ||
compute="_compute_ingredient_values", | ||
store=True, | ||
readonly=False, | ||
) | ||
|
||
@api.depends("product_id") | ||
def _compute_ingredient_values(self): | ||
self.ingredient_ids = False | ||
for lot in self: | ||
for ingredient_line in lot.product_id.ingredient_ids: | ||
lot.ingredient_ids += self.env["production.lot.ingredient.value"].new( | ||
{ | ||
"sequence": ingredient_line.sequence, | ||
"ingredient_id": ingredient_line.ingredient_id.id, | ||
"percentage": ingredient_line.percentage, | ||
} | ||
) |
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,4 @@ | ||
* `Tecnativa <https://www.tecnativa.com>`_ | ||
|
||
* Sergio Teruel | ||
* Carlos Dauden |
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 @@ | ||
This module allows to set ingredients information for a given product. |
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,7 @@ | ||
To use this module you have to: | ||
|
||
- Create or edit a product variant or product template with just a variant. | ||
- Go to ingredients page | ||
- Create some ingredients for the product. | ||
|
||
Now you can print the "Ingredients Info" report label. |
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,4 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
product_ingredient.access_product_ingredient,access_product_ingredient,product_ingredient.model_product_ingredient,base.group_user,1,1,1,1 | ||
product_ingredient.access_product_ingredient_value,access_product_ingredient_value,product_ingredient.model_product_ingredient_value,base.group_user,1,1,1,1 | ||
product_ingredient.access_production_lot_ingredient_value,access_production_lot_ingredient_value,product_ingredient.model_production_lot_ingredient_value,base.group_user,1,1,1,1 |
Oops, something went wrong.