Browse Source

commit inicial

Rodney Elpidio Enciso Arias 6 years ago
commit
dcb3b21ec4
15 changed files with 368 additions and 0 deletions
  1. 26 0
      __init__.py
  2. BIN
      __init__.pyc
  3. 50 0
      __openerp__.py
  4. 19 0
      data/ean_sequence.xml
  5. 128 0
      product.py
  6. BIN
      product.pyc
  7. 37 0
      product_view.xml
  8. 33 0
      res_company.py
  9. BIN
      res_company.pyc
  10. 22 0
      res_company_view.xml
  11. 36 0
      sequence.py
  12. BIN
      sequence.pyc
  13. 17 0
      sequence_view.xml
  14. BIN
      static/description/icon.png
  15. BIN
      static/src/img/icon.png

+ 26 - 0
__init__.py

@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+#################################################################################
+
+from . import res_company
+from . import product
+from . import sequence
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

BIN
__init__.pyc


+ 50 - 0
__openerp__.py

@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+#################################################################################
+
+{
+    "name": 'Product barcode generator',
+    "version": '1.0',
+    "description": """
+    *This is a frozen version. The module is moved to another repository. Check out newest version here:* https://github.com/OCA/stock-logistics-barcode/tree/8.0/product_barcode_generator
+
+    This module will add a function which leads to an automatic generation of EAN13 for products
+
+    You will have to define the company default value (6 firsts number of EAN13) then the 6 next number the sequence.
+    The 13rd is the key of the EAN13, this will be automatically computed.
+    """,
+    "author": 'Julius Network Solutions',
+    "website": 'http://www.julius.fr/',
+    "depends": [
+        'base',
+        'product',
+    ],
+    "demo": [],
+    "data": [
+        "data/ean_sequence.xml",
+        "res_company_view.xml",
+        "product_view.xml",
+        "sequence_view.xml",
+    ],
+    "installable": True,
+    "active": False,
+    "category": "Stock Management",
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

+ 19 - 0
data/ean_sequence.xml

@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data noupdate="1">
+    
+        <!-- Product Sequences -->
+        <record id="seq_type_ean13_sequence" model="ir.sequence.type">
+            <field name="name">EAN13 code</field>
+            <field name="code">product.ean13.code</field>
+        </record>
+        <record id="seq_ean13_sequence" model="ir.sequence">
+            <field name="name">Ean13 code</field>
+            <field name="code">product.ean13.code</field>
+            <field name="prefix">000000</field>
+            <field name="padding">6</field>
+            <field name="number_next">1</field>
+        </record>
+
+    </data>
+</openerp>

+ 128 - 0
product.py

@@ -0,0 +1,128 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+#################################################################################
+
+from openerp.osv import fields, orm
+from openerp.tools.translate import _
+
+
+def isodd(x):
+    return bool(x % 2)
+
+# class product_template(orm.Model):
+#    _inherit = 'product.template'
+#
+#    _columns = {
+#        'variants': fields.one2many('product.product', 'product_tmpl_id', 'Variants'),
+#    }
+#
+#    def generate_ean13(self, cr, uid, ids, context=None):
+#        if context is None: context = {}
+#        product_obj = self.pool.get('product.product')
+#        templates = self.browse(cr, uid, ids, context=context)
+#        for template in templates:
+#            variant_ids = [x.id for x in template.variant_ids]
+#            product_obj.generate_ean13(cr, uid, variant_ids, context=context)
+#        return True
+
+
+class product_category(orm.Model):
+    _inherit = 'product.category'
+
+    _columns = {
+        'ean_sequence_id': fields.many2one('ir.sequence', 'Ean Sequence'),
+    }
+
+
+class product_product(orm.Model):
+    _inherit = 'product.product'
+
+    _columns = {
+        'ean_sequence_id': fields.many2one('ir.sequence', 'Ean Sequence'),
+    }
+
+    def _get_ean_next_code(self, cr, uid, product, context=None):
+        if context is None:
+            context = {}
+        sequence_obj = self.pool.get('ir.sequence')
+        ean = ''
+        if product.ean_sequence_id:
+            ean = sequence_obj.next_by_id(cr, uid, product.ean_sequence_id.id, context=context)
+        elif product.categ_id.ean_sequence_id:
+            ean = sequence_obj.next_by_id(cr, uid, product.categ_id.ean_sequence_id.id, context=context)
+        elif product.company_id and product.company_id.ean_sequence_id:
+            ean = sequence_obj.next_by_id(cr, uid, product.company_id.ean_sequence_id.id, context=context)
+        elif context.get('sequence_id'):
+            ean = sequence_obj.next_by_id(cr, uid, context.get('sequence_id'), context=context)
+        else:
+            return None
+        if len(ean) > 12:
+            raise orm.except_orm(_("Configuration Error!"),
+                                 _("There next sequence is upper than 12 characters. This can't work."
+                                   "You will have to redefine the sequence or create a new one"))
+        else:
+            ean = (len(ean[0:6]) == 6 and ean[0:6] or ean[0:6].ljust(6, '0')) + ean[6:].rjust(6, '0')
+        return ean
+
+    def _get_ean_key(self, code):
+        sum = 0
+        for i in range(12):
+            if isodd(i):
+                sum += 3 * int(code[i])
+            else:
+                sum += int(code[i])
+        key = (10 - sum % 10) % 10
+        return str(key)
+
+    def _generate_ean13_value(self, cr, uid, product, context=None):
+        ean13 = False
+        if context is None:
+            context = {}
+        ean = self._get_ean_next_code(cr, uid, product, context=context)
+        if not ean:
+            return None
+        key = self._get_ean_key(ean)
+        ean13 = ean + key
+        return ean13
+
+    def generate_ean13(self, cr, uid, ids, context=None):
+        if context is None:
+            context = {}
+        product_ids = self.browse(cr, uid, ids, context=context)
+        for product in product_ids:
+            if product.ean13:
+                continue
+            ean13 = self._generate_ean13_value(cr, uid, product, context=context)
+            if not ean13:
+                continue
+            self.write(cr, uid, [product.id], {
+                'ean13': ean13
+            }, context=context)
+        return True
+
+    def copy(self, cr, uid, id, default=None, context=None):
+        if default is None:
+            default = {}
+        if context is None:
+            context = {}
+        default['ean13'] = False
+        return super(product_product, self).copy(cr, uid, id, default=default, context=context)
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

BIN
product.pyc


+ 37 - 0
product_view.xml

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        
+        <record id="view_product_category_simple_ean_form" model="ir.ui.view">
+            <field name="name">product.category.form</field>
+            <field name="model">product.category</field>
+            <field name="inherit_id" ref="product.product_category_form_view"/>
+            <field name="arch" type="xml">
+                <field name="type" position="after">
+                    <field name="ean_sequence_id" domain="[('barcode_sequence', '=', 1)]"
+                        context="{'default_name': name and 'EAN ' + name or 'EAN', 'default_barcode_sequence': 1}"/>
+                    <newline/>
+                </field>
+            </field>
+        </record>
+        
+        <record id="view_product_simple_ean_form" model="ir.ui.view">
+            <field name="name">product.product.form</field>
+            <field name="model">product.product</field>
+            <field name="inherit_id" ref="product.product_normal_form_view"/>
+            <field name="arch" type="xml">
+                <field name="ean13" position="after">
+                    <field name="ean_sequence_id" domain="[('barcode_sequence', '=', 1)]"
+                        context="{'default_name': name and 'EAN ' + name or 'EAN', 'default_barcode_sequence': 1}"
+                        class="oe_edit_only"/>
+                    <button
+                        string="Generar"
+                        name="generate_ean13"
+                        attrs="{'invisible': [('ean13', '!=', False)]}"
+                        type="object" colspan="2"/>
+                </field>
+            </field>
+        </record>
+        
+    </data>
+</openerp>

+ 33 - 0
res_company.py

@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+#################################################################################
+
+from openerp.osv import fields, orm
+
+
+class res_company(orm.Model):
+
+    _inherit = 'res.company'
+
+    _columns = {
+        'ean_sequence_id': fields.many2one('ir.sequence', 'Ean Sequence'),
+    }
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

BIN
res_company.pyc


+ 22 - 0
res_company_view.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        
+        <record id="view_company_ean_form" model="ir.ui.view">
+            <field name="name">res.company.form</field>
+            <field name="model">res.company</field>
+            <field name="inherit_id" ref="base.view_company_form"/>
+            <field name="arch" type="xml">
+                <page string="Configuration" position="inside">
+                    <newline/>
+                    <group colspan="2" col="2">
+                        <separator string="Ean Company code" colspan="2"/>
+                        <field name="ean_sequence_id" domain="[('barcode_sequence', '=', 1)]"
+                        context="{'default_name': name and 'EAN ' + name or 'EAN', 'default_barcode_sequence': 1}"/>
+                    </group>
+                </page>
+            </field>
+        </record>
+        
+    </data>
+</openerp>

+ 36 - 0
sequence.py

@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+#################################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2013 Julius Network Solutions SARL <contact@julius.fr>
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+#################################################################################
+
+from openerp.osv import fields, orm
+
+
+class ir_sequence(orm.Model):
+    _inherit = 'ir.sequence'
+
+    _columns = {
+        'barcode_sequence': fields.boolean('Barcode Sequence'),
+    }
+
+    _defaults = {
+        'barcode_sequence': False,
+    }
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

BIN
sequence.pyc


+ 17 - 0
sequence_view.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        
+        <record id="sequence_add_barcode_sequence_view" model="ir.ui.view">
+            <field name="name">ir.sequence.form</field>
+            <field name="model">ir.sequence</field>
+            <field name="inherit_id" ref="base.sequence_view"/>
+            <field name="arch" type="xml">
+                <field name="implementation" position="after">
+                    <field name="barcode_sequence"/>
+                </field>
+            </field>
+        </record>
+        
+    </data>
+</openerp>

BIN
static/description/icon.png


BIN
static/src/img/icon.png