Skip to content

Commit

Permalink
[IMP] stock_barcodes_gs1: Use weight (gs1 code start with 3) as produ…
Browse files Browse the repository at this point in the history
…ct_qty only if product_uom_categ_kgm

TT49953
  • Loading branch information
carlosdauden authored and sergio-teruel committed Aug 1, 2024
1 parent 40a89c4 commit a3832d0
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 11 deletions.
1 change: 1 addition & 0 deletions stock_barcodes_gs1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Copyright 2019 Sergio Teruel <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models
from . import wizard
3 changes: 3 additions & 0 deletions stock_barcodes_gs1/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
"category": "Extra Tools",
"depends": ["stock_barcodes", "barcodes_gs1_nomenclature"],
"installable": True,
"data": [
"views/barcodes_view.xml",
],
}
29 changes: 20 additions & 9 deletions stock_barcodes_gs1/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-08-27 14:47+0000\n"
"PO-Revision-Date: 2023-10-30 21:36+0000\n"
"Last-Translator: Ivorra78 <[email protected]>\n"
"POT-Creation-Date: 2024-07-09 14:06+0000\n"
"PO-Revision-Date: 2024-07-09 16:07+0200\n"
"Last-Translator: Sergio Teruel <[email protected]>\n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"
"X-Generator: Poedit 3.0.1\n"

#. module: stock_barcodes_gs1
#: code:addons/stock_barcodes_gs1/wizard/stock_barcodes_read.py:0
Expand All @@ -29,12 +29,27 @@ msgstr "({ai}){barcode} No encontrado"
msgid "AI GS1 ({ai}) Not implemented"
msgstr "AI GS1 ({ai}) No implementado"

#. module: stock_barcodes_gs1
#: model:ir.model,name:stock_barcodes_gs1.model_barcode_nomenclature
msgid "Barcode Nomenclature"
msgstr "Nomenclatura de código de barras"

#. module: stock_barcodes_gs1
#: model:ir.model,name:stock_barcodes_gs1.model_barcode_rule
msgid "Barcode Rule"
msgstr "Regla de código de barras"

#. module: stock_barcodes_gs1
#: code:addons/stock_barcodes_gs1/wizard/stock_barcodes_read.py:0
#, python-format
msgid "Review and confirm"
msgstr "Revisar y confirmar"

#. module: stock_barcodes_gs1
#: model:ir.model.fields,field_description:stock_barcodes_gs1.field_barcode_rule__use_weight_as_unit
msgid "Use Weight As Unit"
msgstr "Usar peso como unidades"

#. module: stock_barcodes_gs1
#: model:ir.model,name:stock_barcodes_gs1.model_wiz_stock_barcodes_read
msgid "Wizard to read barcode"
Expand All @@ -57,11 +72,7 @@ msgstr "Asistente para leer código de barras"
#~ msgstr "Se ha encontrado más de un empaquetado"

#~ msgid "Wizard to create new lot from barcode scanner"
#~ msgstr ""
#~ "Asistente para crear nuevo lote desde el lector de códigos de barras"

#~ msgid "Barcode not found"
#~ msgstr "Código de barras no encontrado"
#~ msgstr "Asistente para crear nuevo lote desde el lector de códigos de barras"

#~ msgid "More than one product found"
#~ msgstr "Se ha encontrado más de un producto."
17 changes: 17 additions & 0 deletions stock_barcodes_gs1/i18n/stock_barcodes_gs1.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-07-09 14:06+0000\n"
"PO-Revision-Date: 2024-07-09 14:06+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
Expand All @@ -25,12 +27,27 @@ msgstr ""
msgid "AI GS1 ({ai}) Not implemented"
msgstr ""

#. module: stock_barcodes_gs1
#: model:ir.model,name:stock_barcodes_gs1.model_barcode_nomenclature
msgid "Barcode Nomenclature"
msgstr ""

#. module: stock_barcodes_gs1
#: model:ir.model,name:stock_barcodes_gs1.model_barcode_rule
msgid "Barcode Rule"
msgstr ""

#. module: stock_barcodes_gs1
#: code:addons/stock_barcodes_gs1/wizard/stock_barcodes_read.py:0
#, python-format
msgid "Review and confirm"
msgstr ""

#. module: stock_barcodes_gs1
#: model:ir.model.fields,field_description:stock_barcodes_gs1.field_barcode_rule__use_weight_as_unit
msgid "Use Weight As Unit"
msgstr ""

#. module: stock_barcodes_gs1
#: model:ir.model,name:stock_barcodes_gs1.model_wiz_stock_barcodes_read
msgid "Wizard to read barcode"
Expand Down
4 changes: 4 additions & 0 deletions stock_barcodes_gs1/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024 Tecnativa - Sergio Teruel
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import barcode_nomenclature
from . import barcode_rule
11 changes: 11 additions & 0 deletions stock_barcodes_gs1/models/barcode_nomenclature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import models


class BarcodeNomenclature(models.Model):
_inherit = "barcode.nomenclature"

def parse_gs1_rule_pattern(self, match, rule):
# Allow use weight ai as units directly for products with unit category uom
result = super().parse_gs1_rule_pattern(match, rule)
result["use_weight_as_unit"] = True if rule.use_weight_as_unit else False
return result
7 changes: 7 additions & 0 deletions stock_barcodes_gs1/models/barcode_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class BarcodeRule(models.Model):
_inherit = "barcode.rule"

use_weight_as_unit = fields.Boolean()
35 changes: 35 additions & 0 deletions stock_barcodes_gs1/views/barcodes_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" ?>
<odoo>
<!-- Allow use weight ai as units directly for products with unit category uom -->
<record id="view_barcode_gs1_nomenclature_form" model="ir.ui.view">
<field name="model">barcode.nomenclature</field>
<field
name="inherit_id"
ref="barcodes_gs1_nomenclature.view_barcode_gs1_nomenclature_form"
/>
<field name="arch" type="xml">
<!-- Rules table -->
<xpath expr="//field[@name='associated_uom_id']" position="after">
<field
name="use_weight_as_unit"
attrs="{'column_invisible': [('parent.is_gs1_nomenclature', '!=', True)], 'invisible': [('gs1_content_type', '!=', 'measure')]}"
/>
</xpath>
</field>
</record>
<record id="view_barcode_gs1_rule_form" model="ir.ui.view">
<field name="model">barcode.rule</field>
<field
name="inherit_id"
ref="barcodes_gs1_nomenclature.view_barcode_gs1_rule_form"
/>
<field name="arch" type="xml">
<field name="is_gs1_nomenclature" position="before">
<field
name="use_weight_as_unit"
attrs="{'invisible': ['|', ('parent.is_gs1_nomenclature', '=', False), ('gs1_content_type', '!=', 'measure')]}"
/>
</field>
</field>
</record>
</odoo>
16 changes: 14 additions & 2 deletions stock_barcodes_gs1/wizard/stock_barcodes_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,24 @@ def _process_ai_37(self, gs1_list):

def _process_ai_310(self, gs1_list):
"""Net Weight"""
self.product_qty = self._process_product_qty_gs1(float(self.barcode))
weight_ai = next(filter(lambda f: f["ai"].startswith("31"), gs1_list), False)
if weight_ai[
"use_weight_as_unit"
] or self.product_uom_id.category_id == self.env.ref(
"uom.product_uom_categ_kgm"
):
self.product_qty = self._process_product_qty_gs1(float(self.barcode))
return True

def _process_ai_330(self, gs1_list):
"""Gross Weight"""
self.product_qty = self._process_product_qty_gs1(float(self.barcode))
weight_ai = next(filter(lambda f: f["ai"].startswith("33"), gs1_list), False)
if weight_ai[
"use_weight_as_unit"
] or self.product_uom_id.category_id == self.env.ref(
"uom.product_uom_categ_kgm"
):
self.product_qty = self._process_product_qty_gs1(float(self.barcode))
return True

def _process_ai_15(self, gs1_list):
Expand Down

0 comments on commit a3832d0

Please sign in to comment.