Skip to content

Commit

Permalink
[MIG] barcodes_generator_product: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chafique-delli committed Dec 14, 2020
1 parent 20ca903 commit a2a2140
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 36 deletions.
1 change: 1 addition & 0 deletions barcodes_generator_product/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Contributors

* Sylvain LE GAL (https://twitter.com/legalsylvain)
* Dave Lasley <dave@laslabs.com>
* Chafique Delli <chafique.delli@akretion.com>

Maintainer
----------
Expand Down
4 changes: 2 additions & 2 deletions barcodes_generator_product/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
{
"name": "Generate Barcodes for Products",
"summary": "Generate Barcodes for Products (Templates and Variants)",
"version": "12.0.1.0.0",
"version": "14.0.1.0.0",
"category": "Tools",
"author": "GRAP," "La Louve," "Odoo Community Association (OCA)",
"author": "GRAP, La Louve, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-barcode",
"license": "AGPL-3",
"depends": [
Expand Down
4 changes: 2 additions & 2 deletions barcodes_generator_product/demo/function.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<function
model="product.product"
name="generate_barcode"
eval="[ref('product_product_variant_1')]"
eval="[ref('barcodes_generator_product.product_product_variant_1')]"
/>

<function
model="product.product"
name="generate_barcode"
eval="[ref('product_product_variant_2')]"
eval="[ref('barcodes_generator_product.product_product_variant_2')]"
/>

</odoo>
45 changes: 32 additions & 13 deletions barcodes_generator_product/demo/product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,24 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

<record id="product_template_mono_variant" model="product.template">
<field name="name">Template with Generated Barcode (Mono Variant)</field>
<field name="barcode_rule_id" ref="product_generated_barcode" />
<field name="barcode_base">50</field>
</record>

<record id="product_template_multi_variant" model="product.template">
<field name="name">Template with Generated Barcode (Multi Variant)</field>
</record>

<record id="product_product_variant_1" model="product.product">
<field name="barcode_rule_id" ref="product_generated_barcode" />
<field name="barcode_base">10001</field>
<field name="product_tmpl_id" ref="product_template_multi_variant" />
<field
name="attribute_value_ids"
name="product_template_attribute_value_ids"
eval="[(6,0,[ref('product.product_attribute_value_3')])]"
/>
</record>

<record id="product_product_variant_2" model="product.product">
<field name="barcode_rule_id" ref="product_generated_barcode" />
<field name="barcode_base">10002</field>
<field name="product_tmpl_id" ref="product_template_multi_variant" />
<field
name="attribute_value_ids"
name="product_template_attribute_value_ids"
eval="[(6,0,[ref('product.product_attribute_value_4')])]"
/>
</record>
Expand All @@ -49,11 +43,36 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
/>
</record>

<record id="product_template_multi_variant" model="product.template">
<field
name="attribute_line_ids"
eval="[(6,0,[ref('product_template_multi_variant_attribute_line')])]"
<function model="ir.model.data" name="_update_xmlids">
<value
model="base"
eval="[{
'xml_id': 'barcodes_generator_product.product_template_multi_variant_attribute_2_value_1',
'record': obj().env.ref('barcodes_generator_product.product_template_multi_variant_attribute_line').product_template_value_ids[0],
'noupdate': True,
}, {
'xml_id': 'barcodes_generator_product.product_template_multi_variant_attribute_2_value_2',
'record': obj().env.ref('barcodes_generator_product.product_template_multi_variant_attribute_line').product_template_value_ids[1],
'noupdate': True,
}]"
/>
</record>
</function>

<function model="ir.model.data" name="_update_xmlids">
<value
model="base"
eval="[{
'xml_id': 'barcodes_generator_product.product_product_variant_1',
'record': obj().env.ref('barcodes_generator_product.product_template_multi_variant')._get_variant_for_combination(
obj().env.ref('barcodes_generator_product.product_template_multi_variant_attribute_2_value_1')),
'noupdate': True,
}, {
'xml_id': 'barcodes_generator_product.product_product_variant_2',
'record': obj().env.ref('barcodes_generator_product.product_template_multi_variant')._get_variant_for_combination(
obj().env.ref('barcodes_generator_product.product_template_multi_variant_attribute_2_value_2')),
'noupdate': True,
},]"
/>
</function>

</odoo>
2 changes: 0 additions & 2 deletions barcodes_generator_product/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ class ProductTemplate(models.Model):
)

# View Section
@api.multi
def generate_base(self):
self.product_variant_ids.generate_base()

@api.multi
def generate_barcode(self):
self.ensure_one()
self.product_variant_ids.generate_barcode()
Expand Down
2 changes: 2 additions & 0 deletions barcodes_generator_product/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
To configure this module, see the 'Configuration' Section of the description
of the module 'barcodes_generator_abstract'
3 changes: 3 additions & 0 deletions barcodes_generator_product/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Sylvain LE GAL (https://twitter.com/legalsylvain)
* Dave Lasley <dave@laslabs.com>
* Chafique Delli <chafique.delli@akretion.com>
21 changes: 21 additions & 0 deletions barcodes_generator_product/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
This module expands Odoo functionality, allowing user to generate barcode
depending on a given barcode rule for Products.

For example, a typical pattern for products is "20.....{NNNDD}" that means
that:
* the EAN13 code will begin by '20'
* followed by 5 digits (named Barcode Base in this module)
* and after 5 others digits to define the variable price
* a 13 digit control

With this module, it is possible to:

* Assign a pattern (barcode.rule) to a product.product

* Define a Barcode base:
* manually, if the base of the barcode must be set by a user. (typically an
internal code defined in your company)
* automaticaly by a sequence, if you want to let Odoo to increment a
sequence. (typical case of a customer number incrementation)

* Generate a barcode, based on the defined pattern and the barcode base
15 changes: 15 additions & 0 deletions barcodes_generator_product/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
To use this module, you need to:

* Go to a Product form (or a template form):

1 for manual generation
* Set a Barcode Rule
* Set a Barcode Base
* click on the button 'Generate Barcode (Using Barcode Rule)'

.. image:: /barcodes_generator/static/description/product_template_manual_generation.png

2 for automatic generation
* Set a Barcode Rule
* click on the button 'Generate Base (Using Sequence)'
* click on the button 'Generate Barcode (Using Barcode Rule)'
45 changes: 28 additions & 17 deletions barcodes_generator_product/tests/test_barcodes_generator_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,56 @@
# Copyright (C) 2016-Today La Louve (http://www.lalouve.net)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import SavepointCase

from odoo.tests.common import TransactionCase


class Tests(TransactionCase):
class TestBarcodeGeneratorProduct(SavepointCase):
"""Tests 'Barcodes Generator for Products'"""

def setUp(self):
super(Tests, self).setUp()
self.template_obj = self.env["product.template"]
self.product_obj = self.env["product.product"]
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.template_obj = cls.env["product.template"]
cls.product_obj = cls.env["product.product"]
cls.barcode_rule = cls.env.ref(
"barcodes_generator_product.product_generated_barcode"
)

# Test Section
def test_01_manual_generation_template(self):
self.template_mono = self.template_obj.browse(
self.ref("barcodes_generator_product.product_template_mono_variant")
template_mono = self.env.ref(
"barcodes_generator_product.product_template_mono_variant"
)
template_mono.write(
{"barcode_rule_id": self.barcode_rule.id, "barcode_base": 50}
)
template_mono.generate_barcode()
self.assertEqual(
self.template_mono.barcode,
template_mono.barcode,
"2000050000003",
"Incorrect Manual Barcode Generation for non varianted Template."
" Pattern : %s - Base : %s"
% (
self.template_mono.barcode_rule_id.pattern,
self.template_mono.barcode_base,
template_mono.barcode_rule_id.pattern,
template_mono.barcode_base,
),
)

def test_02_manual_generation_product(self):
self.product_variant_1 = self.product_obj.browse(
self.ref("barcodes_generator_product.product_product_variant_1")
product_variant_1 = self.env.ref(
"barcodes_generator_product.product_product_variant_1"
)
product_variant_1.write(
{"barcode_rule_id": self.barcode_rule.id, "barcode_base": 10001}
)
product_variant_1.generate_barcode()
self.assertEqual(
self.product_variant_1.barcode,
product_variant_1.barcode,
"2010001000006",
"Incorrect Manual Barcode Generation for varianted Product."
" Pattern : %s - Base : %s"
% (
self.product_variant_1.barcode_rule_id.pattern,
self.product_variant_1.barcode_base,
product_variant_1.barcode_rule_id.pattern,
product_variant_1.barcode_base,
),
)

0 comments on commit a2a2140

Please sign in to comment.