diff --git a/barcodes_generate/__init__.py b/barcodes_generate/__init__.py new file mode 100644 index 00000000..a0fdc10f --- /dev/null +++ b/barcodes_generate/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import models diff --git a/barcodes_generate/__openerp__.py b/barcodes_generate/__openerp__.py new file mode 100644 index 00000000..f91c0d73 --- /dev/null +++ b/barcodes_generate/__openerp__.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2016-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). + +{ + 'name': 'Barcodes - Generate', + 'summary': 'Generate Barcodes for Products and Customers', + 'version': '1.0', + 'category': 'Point Of Sale', + 'description': """ +============================================ +Generate Barcodes for Products and Customers +============================================ + +This module depends on a backport of the V9 modules of Odoo 'barcodes'. + +It expends Odoo functionnality, to allow user to generate barcode depending +on a given barcode rule. + +For exemple, a typical pattern for products is "23.....{NNNDD}" that means +that the EAN13 code will begin by '23', followed by 5 digits and after 5 others +digits to define the variable price. (EAN13 has a third char for control). + +With this module, it is possible to: +- Affect a pattern (barcode.rule) to a product.product or a res.partner +- To generate an EAN13 depending on the defined pattern and a custom ID + +Note +---- +Dependency to point_of_sale is required because ean13 field, defined in 'base' +module (in the res.partner model), is defined in a point_of_sale view. + +The same design error is present in odoo 9.0 with the renamed 'barcode' field. + +It's a relative problem, because product barcodes generation will occures +mostly in a Point of Sale context. + +You could comment 'point_of_sale' dependency if you use this module without +point of sale. + +Copyright Note +-------------- +Icon of the module is based on the Oxygen Team work and is under LGPL licence: + +http://www.iconarchive.com/show/oxygen-icons-by-oxygen-icons.org.html + + +""", + 'author': 'GRAP', + 'website': 'http://www.grap.coop', + 'license': 'AGPL-3', + 'depends': [ + 'barcodes', + 'point_of_sale', + ], + 'data': [ + 'security/res_groups.xml', + 'views/view_res_partner.xml', + 'views/view_product_product.xml', + 'views/view_barcode_rule.xml', + ], + 'demo': [ + 'demo/res_users.xml', + ], + 'images': [ + 'static/description/barcode_rule.png' + ], +} diff --git a/barcodes_generate/demo/res_users.xml b/barcodes_generate/demo/res_users.xml new file mode 100644 index 00000000..bdf035f6 --- /dev/null +++ b/barcodes_generate/demo/res_users.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/barcodes_generate/i18n/fr.po b/barcodes_generate/i18n/fr.po new file mode 100644 index 00000000..fa7cdd25 --- /dev/null +++ b/barcodes_generate/i18n/fr.po @@ -0,0 +1,110 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * barcodes_generate +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 7.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-09-21 00:43+0000\n" +"PO-Revision-Date: 2016-09-21 00:43+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: \n" + +#. module: barcodes_generate +#: field:barcode.rule,is_partner_available:0 +msgid "Available for Partners" +msgstr "Disponible pour les partenaires" + +#. module: barcodes_generate +#: field:barcode.rule,is_product_available:0 +msgid "Available for Products" +msgstr "Disponible pour les articles" + +#. module: barcodes_generate +#: field:barcode.generate.mixin,barcode_base:0 +#: field:product.product,barcode_base:0 +#: field:res.partner,barcode_base:0 +msgid "Barcode Base" +msgstr "Base du code Barre" + +#. module: barcodes_generate +#: field:barcode.generate.mixin,barcode_rule_id:0 +#: field:product.product,barcode_rule_id:0 +#: field:res.partner,barcode_rule_id:0 +msgid "Barcode Rule" +msgstr "Règle de code barre" + +#. module: barcodes_generate +#: constraint:res.partner:0 +msgid "Error: Invalid ean code" +msgstr "Erreur : code EAN incorrect" + +#. module: barcodes_generate +#: view:product.product:0 +#: view:res.partner:0 +msgid "Generate Barcode" +msgstr "Générer un code barre" + +#. module: barcodes_generate +#: model:res.groups,name:barcodes_generate.generate_partner_barcode +msgid "Generate Barcodes for Partners" +msgstr "Générer un code barre pour les partenaires" + +#. module: barcodes_generate +#: model:res.groups,name:barcodes_generate.generate_product_barcode +msgid "Generate Barcodes for Products" +msgstr "Générer un code barre pour les articles" + +#. module: barcodes_generate +#: help:barcode.rule,is_partner_available:0 +msgid "If checked, users with specific access right will have the possibility to generate barcodes with this pattern for the partners." +msgstr "Si cette case est cochée, les utilisateurs avec une autorisation adéquate auront la possibilité de générer des codes barres en suivant ce motif, pour les partenaires." + +#. module: barcodes_generate +#: help:barcode.rule,is_product_available:0 +msgid "If checked, users with specific access right will have the possibility to generate barcodes with this pattern for the products." +msgstr "Si cette case est cochée, les utilisateurs avec une autorisation adéquate auront la possibilité de générer des codes barres en suivant ce motif, pour les articles." + +#. module: barcodes_generate +#: code:_description:0 +#: model:ir.model,name:barcodes_generate.model_res_partner +#, python-format +msgid "Partner" +msgstr "Partenaire" + +#. module: barcodes_generate +#: code:_description:0 +#: model:ir.model,name:barcodes_generate.model_product_product +#, python-format +msgid "Product" +msgstr "Article" + +#. module: barcodes_generate +#: constraint:res.partner:0 +msgid "You cannot create recursive Partner hierarchies." +msgstr "Vous ne pouvez pas créer de hiérarchies de partenaires récursives." + +#. module: barcodes_generate +#: constraint:product.product:0 +msgid "You provided an invalid \"EAN13 Barcode\" reference. You may use the \"Internal Reference\" field instead." +msgstr "Vous avez indiqué un code barre EAN13 erroné. Vous pouvez utiliser le champ \"Référence interne\" à la place." + +#. module: barcodes_generate +#: code:_description:0 +#: model:ir.model,name:barcodes_generate.model_barcode_generate_mixin +#, python-format +msgid "barcode.generate.mixin" +msgstr "barcode.generate.mixin" + +#. module: barcodes_generate +#: code:_description:0 +#: model:ir.model,name:barcodes_generate.model_barcode_rule +#, python-format +msgid "barcode.rule" +msgstr "barcode.rule" + diff --git a/barcodes_generate/models/__init__.py b/barcodes_generate/models/__init__.py new file mode 100644 index 00000000..a76dbdcf --- /dev/null +++ b/barcodes_generate/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +from . import barcode_generate_mixin + +from . import res_partner +from . import barcode_rule +from . import product_product diff --git a/barcodes_generate/models/barcode_generate_mixin.py b/barcodes_generate/models/barcode_generate_mixin.py new file mode 100644 index 00000000..10c544bf --- /dev/null +++ b/barcodes_generate/models/barcode_generate_mixin.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2014 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). + +import barcode + +from openerp.osv import fields +from openerp.osv.orm import AbstractModel + + +class barcode_generate_mixin(AbstractModel): + _name = 'barcode.generate.mixin' + + _columns = { + 'barcode_rule_id': fields.many2one( + 'barcode.rule', 'Barcode Rule'), + 'barcode_base': fields.integer('Barcode Base'), + } + + def generate_barcode(self, cr, uid, ids, context=None): + vals = self._compute_custom_barcode(cr, uid, ids, context=context) + for id in vals.keys(): + self.write(cr, uid, id, {'ean13': vals[id]}, context=context) + return True + + def _compute_custom_barcode(self, cr, uid, ids, context=None): + res = {} + for item in self.browse(cr, uid, ids, context=context): + if item.barcode_rule_id and item.barcode_base: + pass + barcode_class = barcode.get_barcode_class( + item.barcode_rule_id.encoding) + padding = item.barcode_rule_id.pattern.count('.') + full_base = str(item.barcode_base).rjust(padding, '0') + + # Define barcode + custom_code = item.barcode_rule_id.pattern + custom_code = custom_code.replace('{', '').replace('}', '') + custom_code = custom_code.replace( + 'D', self._get_barcode_replacement_char( + cr, uid, 'D', context=context)) + custom_code = custom_code.replace( + 'N', self._get_barcode_replacement_char( + cr, uid, 'N', context=context)) + custom_code = custom_code.replace('.' * padding, full_base) + res[item.id] = barcode_class(custom_code) + return res + + def _get_barcode_replacement_char(self, cr, uid, char, context=None): + """ + Can be overload by inheritance + Define wich character will be used instead of the 'N' or the 'D' + char, present in the pattern of the barcode_rule_id + """ + return '0' diff --git a/barcodes_generate/models/barcode_rule.py b/barcodes_generate/models/barcode_rule.py new file mode 100644 index 00000000..3a4a63f7 --- /dev/null +++ b/barcodes_generate/models/barcode_rule.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2014 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). + +from openerp.osv import fields +from openerp.osv.orm import Model + + +class barcode_rule(Model): + _inherit = 'barcode.rule' + + _columns = { + 'is_product_available': fields.boolean( + string='Available for Products', help="If checked, users with" + " specific access right will have the possibility to generate" + " barcodes with this pattern for the products."), + 'is_partner_available': fields.boolean( + string='Available for Partners', help="If checked, users with" + " specific access right will have the possibility to generate" + " barcodes with this pattern for the partners."), + } + + # TODO set constraint + # is_product_available and is_partner_available: + # - should be possible only for ean13 barcode rule + # - should be possible only if pattern contains at leas one '.' char diff --git a/barcodes_generate/models/product_product.py b/barcodes_generate/models/product_product.py new file mode 100644 index 00000000..c20f9475 --- /dev/null +++ b/barcodes_generate/models/product_product.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2014 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). + +from openerp.osv.orm import Model + + +class product_product(Model): + _name = 'product.product' + _inherit = ['product.product', 'barcode.generate.mixin'] diff --git a/barcodes_generate/models/res_partner.py b/barcodes_generate/models/res_partner.py new file mode 100644 index 00000000..9ae48017 --- /dev/null +++ b/barcodes_generate/models/res_partner.py @@ -0,0 +1,11 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2014 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). + +from openerp.osv.orm import Model + + +class res_partner(Model): + _name = 'res.partner' + _inherit = ['res.partner', 'barcode.generate.mixin'] diff --git a/barcodes_generate/security/res_groups.xml b/barcodes_generate/security/res_groups.xml new file mode 100644 index 00000000..0d81da22 --- /dev/null +++ b/barcodes_generate/security/res_groups.xml @@ -0,0 +1,20 @@ + + + + + + + Generate Barcodes for Products + + + + + Generate Barcodes for Partners + + + + diff --git a/barcodes_generate/static/description/barcode_rule.png b/barcodes_generate/static/description/barcode_rule.png new file mode 100644 index 00000000..82cad0a9 Binary files /dev/null and b/barcodes_generate/static/description/barcode_rule.png differ diff --git a/barcodes_generate/static/description/icon.png b/barcodes_generate/static/description/icon.png new file mode 100644 index 00000000..f3533a28 Binary files /dev/null and b/barcodes_generate/static/description/icon.png differ diff --git a/barcodes_generate/views/view_barcode_rule.xml b/barcodes_generate/views/view_barcode_rule.xml new file mode 100644 index 00000000..08b7299d --- /dev/null +++ b/barcodes_generate/views/view_barcode_rule.xml @@ -0,0 +1,21 @@ + + + + + + + barcode.rule + + + + + + + + + + diff --git a/barcodes_generate/views/view_product_product.xml b/barcodes_generate/views/view_product_product.xml new file mode 100644 index 00000000..77df09cf --- /dev/null +++ b/barcodes_generate/views/view_product_product.xml @@ -0,0 +1,28 @@ + + + + + + + product.product + + + + + +