Skip to content

Commit

Permalink
Merge 63177fe into 800dbb3
Browse files Browse the repository at this point in the history
  • Loading branch information
JordiBForgeFlow committed Nov 14, 2019
2 parents 800dbb3 + 63177fe commit 3cdbb85
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 8 deletions.
5 changes: 3 additions & 2 deletions base_gs1_barcode/__manifest__.py
Expand Up @@ -10,8 +10,9 @@
'base',
],
'data': [
'views/gs1_barcode.xml',
'views/res_users.xml',
'views/gs1_barcode_views.xml',
'views/gs1_barcode_model_map_views.xml',
'views/res_users_views.xml',
'data/gs1_barcode.csv',
"security/ir.model.access.csv",
],
Expand Down
1 change: 1 addition & 0 deletions base_gs1_barcode/models/__init__.py
@@ -1,2 +1,3 @@
from . import gs1_barcode
from . import gs1_barcode_model_map
from . import res_users
44 changes: 44 additions & 0 deletions base_gs1_barcode/models/gs1_barcode_model_map.py
@@ -0,0 +1,44 @@
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


class GS1BarcodeModelMap(models.Model):
_name = 'gs1_barcode.model.map'

@api.model
def _get_tier_validation_model_names(self):
res = []
return res

model_id = fields.Many2one(
comodel_name="ir.model",
string="Referenced Model",
required=True,
)
model = fields.Char(
related='model_id.model', index=True, store=True,
)
field_id = fields.Many2one(
'ir.model.fields',
required=True,
domain="[('model_id', '=', model_id)]",
)
gs1_barcode_id = fields.Many2one(
'gs1_barcode',
required=True,
)
ai = fields.Char(
related='gs1_barcode_id.ai',
)

_sql_constraints = [
('gs1_model_field_uniq', 'unique (model_id,field_id,gs1_barcode_id)',
"There cannot be two repeated mappings of "
"the GS1 code to model and field.")]

@api.onchange('model_id')
def onchange_model_id(self):
return {'domain': {
'model_id': [
('model', 'in', self._get_tier_validation_model_names())]}}
6 changes: 4 additions & 2 deletions base_gs1_barcode/security/ir.model.access.csv
@@ -1,3 +1,5 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
"access_gs1_barcode","gs1_barcode","model_gs1_barcode","base.group_user",1,0,0,0
"access_gs1_barcode_admin","gs1_barcode","model_gs1_barcode","base.group_system",1,1,1,1
"access_gs1_barcode","access_gs1_barcode","model_gs1_barcode","base.group_user",1,0,0,0
"access_gs1_barcode_admin","access_gs1_barcode admin","model_gs1_barcode","base.group_system",1,1,1,1
"access_gs1_barcode_model_map","access_gs1_barcode_model_map","model_gs1_barcode_model_map","base.group_user",1,0,0,0
"access_gs1_barcode_model_map_admin","access_gs1_barcode_model_map admin","model_gs1_barcode_model_map","base.group_user",1,1,1,1
47 changes: 47 additions & 0 deletions base_gs1_barcode/views/gs1_barcode_model_map_views.xml
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="gs1_barcode_model_map_tree_view" model="ir.ui.view">
<field name="name">gs1_barcode.model.map.tree</field>
<field name="model">gs1_barcode.model.map</field>
<field name="arch" type="xml">
<tree string="GS1-128/GS1-Datamatrix decoding model map">
<field name="gs1_barcode_id" />
<field name="model_id"/>
<field name="field_id"/>
</tree>
</field>
</record>

<record id="gs1_barcode_model_map_form_view" model="ir.ui.view">
<field name="name">gs1_barcode.model.map.form</field>
<field name="model">gs1_barcode.model.map</field>
<field name="arch" type="xml">
<form string="GS1-128/GS1-Datamatrix decoding model map">
<sheet>
<group name="application_identifier" string="Application Identifier">
<field name="ai"/>
<field name="gs1_barcode_id" colspan="4"/>
</group>
<group name="model_mapping" string="Field">
<field name="model_id"/>
<newline/>
<field name="field_id"/>
</group>
</sheet>
</form>
</field>
</record>

<!-- Add a menu entry for the configuration of GSA-128 mapping -->
<record id="action_config_gs1_barcode_model_map" model="ir.actions.act_window">
<field name="name">GS1-128/GS1-Datamatrix Model Mapping</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">gs1_barcode.model.map</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>

<menuitem action="action_config_gs1_barcode_model_map" id="menu_config_gs1_barcode_model_map" parent="base.next_id_9"/>

</odoo>
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions stock_barcodes_gs1/__manifest__.py
Expand Up @@ -13,5 +13,8 @@
'stock_barcodes',
'base_gs1_barcode',
],
"data": [
'data/gs1_barcode_model_map_data.xml',
],
'installable': True,
}
26 changes: 26 additions & 0 deletions stock_barcodes_gs1/data/gs1_barcode_model_map_data.xml
@@ -0,0 +1,26 @@
<?xml version="1.0" ?>
<!--
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo noupdate="1">
<record id="GTIN" model="gs1_barcode.model.map">
<field name="model_id" ref="stock_barcodes.model_wiz_stock_barcodes_read"/>
<field name="field_id" ref="stock_barcodes.field_wiz_stock_barcodes_read_packaging_id"/>
<field name="gs1_barcode_id" ref="base_gs1_barcode.GTIN"/>
</record>
<record id="CONTENT_GTIN" model="gs1_barcode.model.map">
<field name="model_id" ref="stock_barcodes.model_wiz_stock_barcodes_read"/>
<field name="field_id" ref="stock_barcodes.field_wiz_stock_barcodes_read_product_id"/>
<field name="gs1_barcode_id" ref="base_gs1_barcode.CONTENT_GTIN"/>
</record>
<record id="LOT" model="gs1_barcode.model.map">
<field name="model_id" ref="stock_barcodes.model_wiz_stock_barcodes_read"/>
<field name="field_id" ref="stock_barcodes.field_wiz_stock_barcodes_read_lot_id"/>
<field name="gs1_barcode_id" ref="base_gs1_barcode.LOT"/>
</record>
<record id="NB_CONTAINED" model="gs1_barcode.model.map">
<field name="model_id" ref="stock_barcodes.model_wiz_stock_barcodes_read"/>
<field name="field_id" ref="stock_barcodes.field_wiz_stock_barcodes_read_product_qty"/>
<field name="gs1_barcode_id" ref="base_gs1_barcode.NB_CONTAINED"/>
</record>
</odoo>
4 changes: 4 additions & 0 deletions stock_barcodes_gs1/readme/CONFIGURATION.rst
@@ -0,0 +1,4 @@
To change the defailt mapping of the Application Identifiers to the
associated fields in the scanning wizard, go to
*Settings -> Technical -> Database Structure ->
GS1-128/GS1-Datamatrix Model Mapping*
31 changes: 27 additions & 4 deletions stock_barcodes_gs1/wizard/stock_barcodes_read.py
Expand Up @@ -31,15 +31,38 @@ def process_barcode(self, barcode):
""" Only has been implemented AI (01, 02, 10, 37), so is possible that
scanner reads a barcode ok but this one is not precessed.
"""
model_map = self.env['gs1_barcode.model.map'].search([])
try:
barcode_decoded = self.env['gs1_barcode'].decode(barcode)
except Exception:
return super().process_barcode(barcode)
processed = False
package_barcode = barcode_decoded.get('01', False)
product_barcode = barcode_decoded.get('02', False)
lot_barcode = barcode_decoded.get('10', False)
product_qty = barcode_decoded.get('37', False)
model = self.env.ref(
'stock_barcodes_gs1.model_wiz_stock_barcodes_read')
package_field = self.env.ref(
'stock_barcodes.field_wiz_stock_barcodes_read_packaging_id')
package_map = model_map.filtered(
lambda m: m.model_id == model
and m.field_id == package_field)
package_barcode = barcode_decoded.get(package_map.ai, False)
product_field = self.env.ref(
'stock_barcodes.field_wiz_stock_barcodes_read_product_id')
product_map = model_map.filtered(
lambda m: m.model_id == model
and m.field_id == product_field)
product_barcode = barcode_decoded.get(product_map.ai, False)
lot_field = self.env.ref(
'stock_barcodes.field_wiz_stock_barcodes_read_lot_id')
lot_map = model_map.filtered(
lambda m: m.model_id == model
and m.field_id == lot_field)
lot_barcode = barcode_decoded.get(lot_map.ai, False)
product_qty_field = self.env.ref(
'stock_barcodes.field_wiz_stock_barcodes_read_product_qty')
lot_map = model_map.filtered(
lambda m: m.model_id == model
and m.field_id == product_qty_field)
product_qty = barcode_decoded.get(lot_map.ai, False)
if product_barcode:
product = self.env['product.product'].search(
self._barcode_domain(product_barcode))
Expand Down

0 comments on commit 3cdbb85

Please sign in to comment.