Sylvain LE GAL
8 years ago
15 changed files with 402 additions and 0 deletions
-
2barcodes_generate/__init__.py
-
69barcodes_generate/__openerp__.py
-
13barcodes_generate/demo/res_users.xml
-
110barcodes_generate/i18n/fr.po
-
6barcodes_generate/models/__init__.py
-
56barcodes_generate/models/barcode_generate_mixin.py
-
27barcodes_generate/models/barcode_rule.py
-
11barcodes_generate/models/product_product.py
-
11barcodes_generate/models/res_partner.py
-
20barcodes_generate/security/res_groups.xml
-
BINbarcodes_generate/static/description/barcode_rule.png
-
BINbarcodes_generate/static/description/icon.png
-
21barcodes_generate/views/view_barcode_rule.xml
-
28barcodes_generate/views/view_product_product.xml
-
28barcodes_generate/views/view_res_partner.xml
@ -0,0 +1,2 @@ |
|||
# -*- coding: utf-8 -*- |
|||
from . import models |
@ -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' |
|||
], |
|||
} |
@ -0,0 +1,13 @@ |
|||
<?xml version="1.0" encoding="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). |
|||
--> |
|||
|
|||
<openerp><data> |
|||
|
|||
<record id="base.user_root" model="res.users"> |
|||
<field name="groups_id" eval="[(4, ref('barcodes_generate.generate_product_barcode')), (4, ref('barcodes_generate.generate_partner_barcode'))]" /> |
|||
</record> |
|||
</data></openerp> |
@ -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" |
|||
|
@ -0,0 +1,6 @@ |
|||
# -*- coding: utf-8 -*- |
|||
from . import barcode_generate_mixin |
|||
|
|||
from . import res_partner |
|||
from . import barcode_rule |
|||
from . import product_product |
@ -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' |
@ -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 |
@ -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'] |
@ -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'] |
@ -0,0 +1,20 @@ |
|||
<?xml version="1.0" encoding="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). |
|||
--> |
|||
|
|||
<openerp><data> |
|||
|
|||
<record id="generate_product_barcode" model="res.groups"> |
|||
<field name="name">Generate Barcodes for Products</field> |
|||
<field name="category_id" ref="base.module_category_hidden" /> |
|||
</record> |
|||
|
|||
<record id="generate_partner_barcode" model="res.groups"> |
|||
<field name="name">Generate Barcodes for Partners</field> |
|||
<field name="category_id" ref="base.module_category_hidden" /> |
|||
</record> |
|||
|
|||
</data></openerp> |
After Width: 760 | Height: 61 | Size: 8.8 KiB |
After Width: 196 | Height: 196 | Size: 16 KiB |
@ -0,0 +1,21 @@ |
|||
<?xml version="1.0" encoding="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). |
|||
--> |
|||
|
|||
<openerp><data> |
|||
|
|||
<record id="view_barcode_rule_form" model="ir.ui.view"> |
|||
<field name="model">barcode.rule</field> |
|||
<field name="inherit_id" ref="barcodes.view_barcode_rule_form"/> |
|||
<field name="arch" type="xml"> |
|||
<field name="encoding" position="after"> |
|||
<field name="is_product_available"/> |
|||
<field name="is_partner_available"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
</data></openerp> |
@ -0,0 +1,28 @@ |
|||
<?xml version="1.0" encoding="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). |
|||
--> |
|||
|
|||
<openerp><data> |
|||
|
|||
<record id="view_product_product_form" model="ir.ui.view"> |
|||
<field name="model">product.product</field> |
|||
<field name="inherit_id" ref="product.product_normal_form_view"/> |
|||
<field name="arch" type="xml"> |
|||
<field name="default_code" position="after"> |
|||
<field name="barcode_rule_id" |
|||
domain="[('is_product_available', '=', True)]" |
|||
groups="barcodes_generate.generate_product_barcode" colspan="2" |
|||
attrs="{'readonly': [('ean13', '!=', False)]}"/> |
|||
<field name="barcode_base" attrs="{'invisible': [('barcode_rule_id', '=', False)], 'readonly': [('ean13', '!=', False)]}" |
|||
groups="barcodes_generate.generate_product_barcode" colspan="2"/> |
|||
<button name="generate_barcode" type="object" string="Generate Barcode" |
|||
attrs="{'invisible': ['|','|', ('ean13', '!=', False), ('barcode_rule_id', '=', False), ('barcode_base', '=', 0)]}" |
|||
groups="barcodes_generate.generate_product_barcode" colspan="2"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
</data></openerp> |
@ -0,0 +1,28 @@ |
|||
<?xml version="1.0" encoding="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). |
|||
--> |
|||
|
|||
<openerp><data> |
|||
|
|||
<record id="view_res_partner_form" model="ir.ui.view"> |
|||
<field name="model">res.partner</field> |
|||
<field name="inherit_id" ref="point_of_sale.view_partner_property_form"/> |
|||
<field name="arch" type="xml"> |
|||
<field name="ean13" position="before"> |
|||
<field name="barcode_rule_id" |
|||
domain="[('is_partner_available', '=', True)]" |
|||
groups="barcodes_generate.generate_partner_barcode" colspan="2" |
|||
attrs="{'readonly': [('ean13', '!=', False)]}"/> |
|||
<field name="barcode_base" attrs="{'invisible': [('barcode_rule_id', '=', False)], 'readonly': [('ean13', '!=', False)]}" |
|||
groups="barcodes_generate.generate_partner_barcode" colspan="2"/> |
|||
<button name="generate_barcode" type="object" string="Generate Barcode" |
|||
attrs="{'invisible': ['|','|', ('ean13', '!=', False), ('barcode_rule_id', '=', False), ('barcode_base', '=', 0)]}" |
|||
groups="barcodes_generate.generate_partner_barcode" colspan="2"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
</data></openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue