Skip to content

Commit

Permalink
[MIG] barcodes_generator_abstract: 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 9883072 commit 5009673
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 10 deletions.
4 changes: 2 additions & 2 deletions barcodes_generator_abstract/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
{
"name": "Generate Barcodes (Abstract)",
"summary": "Generate Barcodes for Any Models",
"version": "12.0.1.0.2",
"version": "14.0.1.0.0",
"category": "Tools",
"author": "GRAP, " "La Louve, " "LasLabs, " "Odoo Community Association (OCA)",
"author": "GRAP, La Louve, LasLabs, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-barcode",
"license": "AGPL-3",
"depends": [
Expand Down
2 changes: 0 additions & 2 deletions barcodes_generator_abstract/models/barcode_generate_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def create(self, vals):
return record

# View Section
@api.multi
def generate_base(self):
for item in self:
if item.generate_type != "sequence":
Expand All @@ -67,7 +66,6 @@ def generate_base(self):
else:
item.barcode_base = item.barcode_rule_id.sequence_id.next_by_id()

@api.multi
def generate_barcode(self):
for item in self:
padding = item.barcode_rule_id.padding
Expand Down
7 changes: 1 addition & 6 deletions barcodes_generator_abstract/models/barcode_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,18 @@ class BarcodeRule(models.Model):

# Compute Section
@api.depends("pattern")
@api.multi
def _compute_padding(self):
for rule in self:
rule.padding = rule.pattern.count(".")

# On Change Section
@api.onchange("generate_type")
@api.multi
def onchange_generate_type(self):
for rule in self:
if rule.generate_type == "no":
rule.generate_model = False

# Constrains Section
@api.multi
@api.constrains("generate_model", "generate_automate")
def _check_generate_model_automate(self):
"""It should not allow two automated barcode generators per model.
Expand Down Expand Up @@ -94,13 +91,11 @@ def create(self, vals):
self._clear_cache(vals)
return super(BarcodeRule, self).create(vals)

@api.multi
def write(self, vals):
self._clear_cache(vals)
return super(BarcodeRule, self).write(vals)

# View Section
@api.multi
def generate_sequence(self):
sequence_obj = self.env["ir.sequence"]
for rule in self:
Expand Down Expand Up @@ -156,7 +151,7 @@ def get_automatic_rule_ids(self, model):
)
return record.ids

@api.model_cr_context
@api.model
def _clear_cache(self, vals):
"""It clears the caches if certain vals are updated."""
fields = ("generate_model", "generate_automate")
Expand Down
23 changes: 23 additions & 0 deletions barcodes_generator_abstract/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
To configure this module, you need to:

* Go to Settings / Technical / Sequences & Identifiers / Barcode Nomenclatures
* Select a Nomenclature
* Create or select a rule

.. image:: /barcodes_generator_abstract/static/description/barcode_rule_tree.png

* For manual generation, set:
* 'Base set Manually' in 'Generate Type'
* Set the model

.. image:: /barcodes_generator_abstract/static/description/barcode_rule_form_manual.png

* For automatic generation, set:
* 'Base managed by Sequence' in 'Generate Type'
* Set the model
* Generate a new sequence by button, or affect a existing one

.. image:: /barcodes_generator_abstract/static/description/barcode_rule_form_sequence.png

In all cases, padding will be computed automaticaly, based on the number
of '.' in the Barcode Pattern field.
2 changes: 2 additions & 0 deletions barcodes_generator_abstract/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Sylvain LE GAL (https://twitter.com/legalsylvain)
* Dave Lasley <[email protected]>
21 changes: 21 additions & 0 deletions barcodes_generator_abstract/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
This module expends Odoo functionality, allowing user to generate barcode
depending on a given barcode rule for any Model.

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:

* Affect a pattern (barcode.rule) to a model

* 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
4 changes: 4 additions & 0 deletions barcodes_generator_abstract/readme/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module use an extra python library named 'python-barcode' you should install
to make barcode generation works properly.

``sudo pip install python-barcode``
27 changes: 27 additions & 0 deletions barcodes_generator_abstract/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
This module is an abstract module. You can configure Barcode Rule, but to
enable this feature, you need to install an extra module for a given model.
This repository provide 'barcodes_generator_product' and
'barcodes_generator_partner' module to generate barcode for product or partner
model.

Alternatively, you can develop a custom module for a custom model.

If you want to generate barcode for another model, you can create a custom
module that inherits on 'barcodes_generator_abstract' and inherit your model
like that:

class MyModel(models.Model):
_name = 'my.model'
_inherit = ['my.model', 'barcode.generate.mixin']

class barcode_rule(models.Model):
_inherit = 'barcode.rule'

generate_model = fields.Selection(selection_add=[('my.model', 'My Model')])

Finally, you should inherit your model view adding buttons and fields.

Note
----

Your model should have a field 'barcode' defined.

0 comments on commit 5009673

Please sign in to comment.