Browse Source

S0043 : Create a new barcode rule for beescoop product (with prefix 043), and add a button to generate a barcode for a product if it does not have one yet

pull/14/head
EliseDup 8 years ago
committed by Thibault Francois
parent
commit
807166e7d9
  1. 1
      beesdoo_product/__openerp__.py
  2. 13
      beesdoo_product/data/barcode_rule.xml
  3. 15
      beesdoo_product/models/beesdoo_product.py
  4. 4
      beesdoo_product/views/beesdoo_product.xml

1
beesdoo_product/__openerp__.py

@ -25,6 +25,7 @@
# always loaded # always loaded
'data': [ 'data': [
'data/product_label.xml', 'data/product_label.xml',
'data/barcode_rule.xml',
'views/beesdoo_product.xml', 'views/beesdoo_product.xml',
'wizard/views/label_printing_utils.xml', 'wizard/views/label_printing_utils.xml',
'security/ir.model.access.csv', 'security/ir.model.access.csv',

13
beesdoo_product/data/barcode_rule.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<record model="barcode.rule" id="beesdoo_product_barcode_rule">
<field name="name">Beescoop Product Barcodes</field>
<field name="barcode_nomenclature_id">1</field>
<field name="type">product</field>
<field name="pattern">043</field>
<field name="sequence">45</field>
<field name="encoding">ean13</field>
</record>
</data>
</odoo>

15
beesdoo_product/models/beesdoo_product.py

@ -2,6 +2,7 @@
from openerp import models, fields, api from openerp import models, fields, api
from openerp.tools.translate import _ from openerp.tools.translate import _
from openerp.exceptions import UserError from openerp.exceptions import UserError
import uuid
class BeesdooProduct(models.Model): class BeesdooProduct(models.Model):
_inherit = "product.template" _inherit = "product.template"
@ -26,6 +27,20 @@ class BeesdooProduct(models.Model):
note = fields.Text('Comments') note = fields.Text('Comments')
@api.one
def generate_barcode(self):
print 'generate barcode', self.barcode, self.barcode == ''
rule = self.env['barcode.rule'].search([('name', '=', 'Beescoop Product Barcodes')])[0]
size = 13 - len(rule.pattern)
ean = rule.pattern + str(uuid.uuid4().fields[-1])[:size]
bc = ean[0:12] + str(self.env['barcode.nomenclature'].ean_checksum(ean))
# Make sure there is no other active member with the same barcode
while(self.search_count([('barcode', '=', bc)]) > 1):
ean = rule.pattern + str(uuid.uuid4().fields[-1])[:size]
bc = ean[0:12] + str(self.env['barcode.nomenclature'].ean_checksum(ean))
print 'barcode :', bc
self.barcode = bc
@api.one @api.one
@api.depends('seller_ids', 'seller_ids.date_start') @api.depends('seller_ids', 'seller_ids.date_start')
def _compute_main_seller_id(self): def _compute_main_seller_id(self):

4
beesdoo_product/views/beesdoo_product.xml

@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<odoo> <odoo>
<record model="ir.ui.view" id="beesdoo_product_form"> <record model="ir.ui.view" id="beesdoo_product_form">
<field name="name">bees.product.template.form</field> <field name="name">bees.product.template.form</field>
<field name="model">product.template</field> <field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view" /> <field name="inherit_id" ref="product.product_template_only_form_view" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="barcode" position="after">
<button string="Generate Barcode" name="generate_barcode" type="object" attrs="{'invisible' : [('barcode','!=',False)]}" /> />
</field>
<field name="invoice_policy" position="attributes"> <field name="invoice_policy" position="attributes">
<attribute name="invisible">1</attribute> <attribute name="invisible">1</attribute>
</field> </field>

Loading…
Cancel
Save