forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] product_net_weight: Adapt module like Odoo manage weight field …
…with multiple variants
- Loading branch information
1 parent
98c4835
commit 0eacfcc
Showing
8 changed files
with
85 additions
and
62 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 |
---|---|---|
|
@@ -14,16 +14,16 @@ Products - Net Weight | |
: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_net_weight | ||
:target: https://github.com/OCA/product-attribute/tree/16.0/product_net_weight | ||
: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_net_weight | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/135/15.0 | ||
:alt: Try me on Runbot | ||
.. |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=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module extends the functionality of stock module to support net weight. (container excluded) | ||
|
||
|
@@ -78,6 +78,10 @@ Contributors | |
|
||
* Fernando La Chica <[email protected]> | ||
|
||
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* Sergio Teruel | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
||
|
@@ -97,7 +101,7 @@ promote its widespread use. | |
|
||
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
||
|maintainer-legalsylvain| | ||
|maintainer-legalsylvain| | ||
|
||
This module is part of the `OCA/product-attribute <https://github.com/OCA/product-attribute/tree/15.0/product_net_weight>`_ project on GitHub. | ||
|
||
|
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 |
---|---|---|
|
@@ -4,17 +4,16 @@ | |
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 15.0\n" | ||
"Project-Id-Version: Odoo Server 16.0+e\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"PO-Revision-Date: 2023-01-09 13:45+0000\n" | ||
"Last-Translator: Carlos Dauden <[email protected]>\n" | ||
"Language-Team: none\n" | ||
"Language: es\n" | ||
"POT-Creation-Date: 2023-03-02 08:36+0000\n" | ||
"PO-Revision-Date: 2023-03-02 08:36+0000\n" | ||
"Last-Translator: \n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: nplurals=2; plural=n != 1;\n" | ||
"X-Generator: Weblate 4.14.1\n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: product_net_weight | ||
#: model:ir.model.fields,field_description:product_net_weight.field_product_product__weight | ||
|
@@ -35,35 +34,23 @@ msgid "Net Weight of the product, container excluded." | |
msgstr "Peso neto del producto, contenedor excluido." | ||
|
||
#. module: product_net_weight | ||
#: model:ir.model,name:product_net_weight.model_product_product | ||
#: model:ir.model,name:product_net_weight.model_product_template | ||
msgid "Product" | ||
msgstr "Producto" | ||
|
||
#. module: product_net_weight | ||
#: model:ir.model,name:product_net_weight.model_product_template | ||
msgid "Product Template" | ||
msgstr "Plantilla de producto" | ||
#: model:ir.model,name:product_net_weight.model_product_product | ||
msgid "Product Variant" | ||
msgstr "Variantes de producto" | ||
|
||
#. module: product_net_weight | ||
#: model:product.product,name:product_net_weight.product_strawberry_jam | ||
#: model:product.template,name:product_net_weight.product_strawberry_jam_product_template | ||
msgid "Strawberry Jam (Jar of 250 grams)" | ||
msgstr "" | ||
|
||
#. module: product_net_weight | ||
#: model:product.product,uom_name:product_net_weight.product_strawberry_jam | ||
#: model:product.template,uom_name:product_net_weight.product_strawberry_jam_product_template | ||
msgid "Units" | ||
msgstr "Unidades" | ||
|
||
#. module: product_net_weight | ||
#: model:product.product,weight_uom_name:product_net_weight.product_strawberry_jam | ||
#: model:product.template,weight_uom_name:product_net_weight.product_strawberry_jam_product_template | ||
msgid "kg" | ||
msgstr "kg" | ||
|
||
#. module: product_net_weight | ||
#: model:product.product,volume_uom_name:product_net_weight.product_strawberry_jam | ||
#: model:product.template,volume_uom_name:product_net_weight.product_strawberry_jam_product_template | ||
msgid "m³" | ||
msgstr "m³" | ||
#. odoo-python | ||
#: code:addons/product_net_weight/models/product_product.py:0 | ||
#, python-format | ||
msgid "The net weight of product must be lower than gross weight." | ||
msgstr "El peso neto tiene que ser menor que el peso bruto." |
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
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 |
---|---|---|
@@ -1,20 +1,43 @@ | ||
# Copyright (C) 2021 - 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). | ||
# Copyright 2023 Tecnativa - Sergio Teruel | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
from odoo import api, fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
net_weight = fields.Float( | ||
string="Net Weight", | ||
related="product_variant_ids.net_weight", | ||
compute="_compute_net_weight", | ||
inverse="_inverse_net_weight", | ||
digits="Stock Weight", | ||
help="Net Weight of the product, container excluded.", | ||
readonly=False, | ||
store=True, | ||
) | ||
|
||
# Explicit field, renaming it | ||
weight = fields.Float(string="Gross Weight") | ||
|
||
@api.depends("product_variant_ids", "product_variant_ids.net_weight") | ||
def _compute_net_weight(self): | ||
for template in self: | ||
if template.product_variant_count == 1: | ||
template.net_weight = template.product_variant_ids.net_weight | ||
else: | ||
template.net_weight = 0.0 | ||
|
||
def _inverse_net_weight(self): | ||
for template in self: | ||
if len(template.product_variant_ids) == 1: | ||
template.product_variant_ids.net_weight = template.net_weight | ||
|
||
@api.model_create_multi | ||
def create(self, vals_list): | ||
templates = super(ProductTemplate, self).create(vals_list) | ||
# This is needed to set given values to first variant after creation | ||
for template, vals in zip(templates, vals_list): | ||
if vals.get("net_weight"): | ||
template.write({"net_weight": vals["net_weight"]}) | ||
return templates |
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 |
---|---|---|
|
@@ -2,3 +2,7 @@ | |
* `Greenice <https://www.greenice.com>`_: | ||
|
||
* Fernando La Chica <[email protected]> | ||
|
||
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* Sergio Teruel |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from . import test_product_net_weight |