MIG product_print_zpl_barcode from v10 to v14
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# Copyright 2016-2020 Akretion (http://www.akretion.com/)
|
||||||
# Copyright 2016-2018 Akretion
|
|
||||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Product Generate Price Weight Barcode',
|
'name': 'Product Generate Price Weight Barcode',
|
||||||
'version': '10.0.1.0.0',
|
'version': '14.0.1.0.0',
|
||||||
'category': 'Extra Tools',
|
'category': 'Extra Tools',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'summary': 'Add a wizard to print product barcode stickers on ZPL printer',
|
'summary': 'Add a wizard to print product barcode stickers on ZPL printer',
|
||||||
@@ -27,21 +26,21 @@ This module adds a wizard on product.product form view which allows to generate
|
|||||||
* price per kg
|
* price per kg
|
||||||
* EAN13 barcode
|
* EAN13 barcode
|
||||||
|
|
||||||
Roadmap: It would be cool one to day use the OCA module *printer_zpl2* or the underlying *zpl2* lib.
|
|
||||||
|
|
||||||
This module has been written by Alexis de Lattre from Akretion
|
This module has been written by Alexis de Lattre from Akretion
|
||||||
<alexis.delattre@akretion.com>.
|
<alexis.delattre@akretion.com>.
|
||||||
""",
|
""",
|
||||||
'author': 'Akretion',
|
'author': 'Akretion',
|
||||||
'website': 'http://www.akretion.com',
|
'website': 'http://www.akretion.com',
|
||||||
# We depend on point_of_sale and not only 'product'
|
# We depend on point_of_sale and not only 'product'
|
||||||
# because the weight barcode rules are added by the point_of_sale module
|
# because the price barcode rule is added by the point_of_sale module
|
||||||
|
# (the weight barcode rule is added by the stock module)
|
||||||
'depends': [
|
'depends': [
|
||||||
'point_of_sale',
|
'point_of_sale',
|
||||||
'barcodes',
|
'barcodes',
|
||||||
'base_report_to_printer',
|
'base_report_to_printer',
|
||||||
],
|
],
|
||||||
'data': [
|
'data': [
|
||||||
|
'security/ir.model.access.csv',
|
||||||
'wizard/product_print_zpl_barcode_view.xml',
|
'wizard/product_print_zpl_barcode_view.xml',
|
||||||
'views/product.xml',
|
'views/product.xml',
|
||||||
],
|
],
|
||||||
|
|||||||
2
product_print_zpl_barcode/security/ir.model.access.csv
Normal file
2
product_print_zpl_barcode/security/ir.model.access.csv
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
|
access_product_print_zpl_barcode,Full access to product.print.zpl.barcode wizard,model_product_print_zpl_barcode,base_report_to_printer.printing_group_user,1,1,1,1
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
<field name="inherit_id" ref="product.product_normal_form_view" />
|
<field name="inherit_id" ref="product.product_normal_form_view" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<header position="inside">
|
<header position="inside">
|
||||||
<button name="%(product_print_zpl_barcode.product_print_zpl_barcode_action)d" type="action" string="Print Barcode"/>
|
<button name="%(product_print_zpl_barcode.product_print_zpl_barcode_action)d" type="action" string="Print Barcode" groups="base_report_to_printer.printing_group_user"/>
|
||||||
</header>
|
</header>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
@@ -1,3 +1 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import product_print_zpl_barcode
|
from . import product_print_zpl_barcode
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# Copyright 2016-2020 Akretion France (http://www.akretion.com/)
|
||||||
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
|
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from odoo import models, fields, api, _
|
from odoo import api, fields, models, _
|
||||||
from odoo.exceptions import UserError
|
from odoo.exceptions import UserError
|
||||||
from odoo.tools import float_compare, float_is_zero
|
from odoo.tools import float_compare, float_is_zero
|
||||||
import odoo.addons.decimal_precision as dp
|
|
||||||
import base64
|
import base64
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ class ProductPrintZplBarcode(models.TransientModel):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields_list):
|
def default_get(self, fields_list):
|
||||||
res = super(ProductPrintZplBarcode, self).default_get(fields_list)
|
res = super().default_get(fields_list)
|
||||||
assert self._context.get('active_model') == 'product.product',\
|
assert self._context.get('active_model') == 'product.product',\
|
||||||
'wrong active_model, should be product.product'
|
'wrong active_model, should be product.product'
|
||||||
product_id = self._context.get('active_id')
|
product_id = self._context.get('active_id')
|
||||||
@@ -27,7 +26,7 @@ class ProductPrintZplBarcode(models.TransientModel):
|
|||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
"Product '%s' doesn't have a barcode") % product.display_name)
|
"Product '%s' doesn't have a barcode") % product.display_name)
|
||||||
nomenclature = self.env.ref('barcodes.default_barcode_nomenclature')
|
nomenclature = self.env.ref('barcodes.default_barcode_nomenclature')
|
||||||
company = self.env.user.company_id
|
company = self.env.company
|
||||||
posconfig = self.env['pos.config'].sudo().search(
|
posconfig = self.env['pos.config'].sudo().search(
|
||||||
[('company_id', '=', company.id)], limit=1)
|
[('company_id', '=', company.id)], limit=1)
|
||||||
if posconfig:
|
if posconfig:
|
||||||
@@ -74,7 +73,7 @@ class ProductPrintZplBarcode(models.TransientModel):
|
|||||||
currency_id = fields.Many2one(
|
currency_id = fields.Many2one(
|
||||||
related='pricelist_id.currency_id', readonly=True)
|
related='pricelist_id.currency_id', readonly=True)
|
||||||
# TODO: for the moment, we only support weight, but...
|
# TODO: for the moment, we only support weight, but...
|
||||||
quantity = fields.Float(digits=dp.get_precision('Stock Weight'))
|
quantity = fields.Float(digits='Stock Weight')
|
||||||
price_uom = fields.Monetary(
|
price_uom = fields.Monetary(
|
||||||
readonly=True, string="Price per Unit of Measure",
|
readonly=True, string="Price per Unit of Measure",
|
||||||
compute='_compute_price') # given by pricelist
|
compute='_compute_price') # given by pricelist
|
||||||
@@ -102,18 +101,18 @@ class ProductPrintZplBarcode(models.TransientModel):
|
|||||||
wiz.price_uom = price_uom
|
wiz.price_uom = price_uom
|
||||||
wiz.price = price_uom * wiz.quantity
|
wiz.price = price_uom * wiz.quantity
|
||||||
|
|
||||||
@api.one
|
|
||||||
@api.depends('nomenclature_id')
|
@api.depends('nomenclature_id')
|
||||||
def _compute_rule_id(self):
|
def _compute_rule_id(self):
|
||||||
match_rule = False
|
for wiz in self:
|
||||||
if self.nomenclature_id and self.barcode:
|
match_rule = False
|
||||||
for rule in self.nomenclature_id.rule_ids:
|
if wiz.nomenclature_id and wiz.barcode:
|
||||||
match = self.nomenclature_id.match_pattern(
|
for rule in wiz.nomenclature_id.rule_ids:
|
||||||
self.barcode, rule.pattern)
|
match = wiz.nomenclature_id.match_pattern(
|
||||||
if match.get('match'):
|
wiz.barcode, rule.pattern)
|
||||||
match_rule = rule.id
|
if match.get('match'):
|
||||||
break
|
match_rule = rule.id
|
||||||
self.rule_id = match_rule
|
break
|
||||||
|
wiz.rule_id = match_rule
|
||||||
|
|
||||||
def _prepare_price_weight_barcode_type(self):
|
def _prepare_price_weight_barcode_type(self):
|
||||||
dpo = self.env['decimal.precision']
|
dpo = self.env['decimal.precision']
|
||||||
@@ -154,11 +153,11 @@ class ProductPrintZplBarcode(models.TransientModel):
|
|||||||
"The value to encode in the barcode (%s) is superior "
|
"The value to encode in the barcode (%s) is superior "
|
||||||
"to the maximum value allowed by the barcode pattern (%s).")
|
"to the maximum value allowed by the barcode pattern (%s).")
|
||||||
% (value, max_value))
|
% (value, max_value))
|
||||||
value_u = unicode(value)
|
value_str = str(value)
|
||||||
value_u_split = value_u.split('.')
|
value_str_split = value_str.split('.')
|
||||||
assert len(value_u_split) == 2
|
assert len(value_str_split) == 2
|
||||||
value_n = value_u_split[0]
|
value_n = value_str_split[0]
|
||||||
value_d = value_u_split[1]
|
value_d = value_str_split[1]
|
||||||
assert len(value_n) <= pattern_val.count('N')
|
assert len(value_n) <= pattern_val.count('N')
|
||||||
barcode += value_n.zfill(pattern_val.count('N'))
|
barcode += value_n.zfill(pattern_val.count('N'))
|
||||||
# end fill doesn't exists... so:
|
# end fill doesn't exists... so:
|
||||||
@@ -181,9 +180,9 @@ class ProductPrintZplBarcode(models.TransientModel):
|
|||||||
'quantity': value,
|
'quantity': value,
|
||||||
'uom_name': self.uom_id.name,
|
'uom_name': self.uom_id.name,
|
||||||
}
|
}
|
||||||
zpl_encoded = zpl_unicode.encode('utf-8')
|
zpl_bytes = zpl_unicode.encode('utf-8')
|
||||||
vals = {
|
vals = {
|
||||||
'zpl_file': zpl_encoded.encode('base64'),
|
'zpl_file': base64.encodebytes(zpl_bytes),
|
||||||
'barcode': barcode,
|
'barcode': barcode,
|
||||||
}
|
}
|
||||||
return vals
|
return vals
|
||||||
@@ -234,9 +233,9 @@ class ProductPrintZplBarcode(models.TransientModel):
|
|||||||
'currency_symbol': self.currency_id.symbol, # symbol is a required field
|
'currency_symbol': self.currency_id.symbol, # symbol is a required field
|
||||||
'copies': self.copies,
|
'copies': self.copies,
|
||||||
}
|
}
|
||||||
zpl_encoded = zpl_unicode.encode('utf-8')
|
zpl_bytes = zpl_unicode.encode('utf-8')
|
||||||
vals = {
|
vals = {
|
||||||
'zpl_file': zpl_encoded.encode('base64'),
|
'zpl_file': base64.encodebytes(zpl_bytes),
|
||||||
'barcode': self.barcode, # unchanged
|
'barcode': self.barcode, # unchanged
|
||||||
}
|
}
|
||||||
return vals
|
return vals
|
||||||
@@ -264,9 +263,7 @@ class ProductPrintZplBarcode(models.TransientModel):
|
|||||||
'zpl_filename': 'barcode_%s.zpl' % vals['barcode'],
|
'zpl_filename': 'barcode_%s.zpl' % vals['barcode'],
|
||||||
})
|
})
|
||||||
self.write(vals)
|
self.write(vals)
|
||||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
action = self.env.ref('product_print_zpl_barcode.product_print_zpl_barcode_action').read()[0]
|
||||||
'product_print_zpl_barcode',
|
|
||||||
'product_print_zpl_barcode_action')
|
|
||||||
action.update({
|
action.update({
|
||||||
'res_id': self.id,
|
'res_id': self.id,
|
||||||
'context': self._context,
|
'context': self._context,
|
||||||
@@ -278,12 +275,10 @@ class ProductPrintZplBarcode(models.TransientModel):
|
|||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
"You must select a ZPL Printer."))
|
"You must select a ZPL Printer."))
|
||||||
self.zpl_printer_id.print_document(
|
self.zpl_printer_id.print_document(
|
||||||
self.zpl_filename, base64.decodestring(self.zpl_file), 'raw')
|
self.zpl_filename, base64.decodestring(self.zpl_file), format='raw')
|
||||||
action = True
|
action = True
|
||||||
if self._context.get('print_and_new'):
|
if self._context.get('print_and_new'):
|
||||||
action = self.env['ir.actions.act_window'].for_xml_id(
|
action = self.env.ref('product_print_zpl_barcode.product_print_zpl_barcode_action').read()[0]
|
||||||
'product_print_zpl_barcode',
|
|
||||||
'product_print_zpl_barcode_action')
|
|
||||||
action.update({
|
action.update({
|
||||||
'views': False,
|
'views': False,
|
||||||
'context': self._context,
|
'context': self._context,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!--
|
<!--
|
||||||
© 2016 Akretion (http://www.akretion.com/)
|
Copyright 2016-2020 Akretion France (http://www.akretion.com/)
|
||||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
-->
|
-->
|
||||||
@@ -33,17 +33,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</group>
|
</group>
|
||||||
<group name="step2" states="step2" string="Label">
|
<group name="step2" states="step2" string="Label">
|
||||||
<field name="price"/>
|
<field name="price" attrs="{'invisible': [('barcode_type', 'not in', ('price', 'weight'))]}"/>
|
||||||
<field name="zpl_file" filename="zpl_filename" />
|
<field name="zpl_file" filename="zpl_filename" />
|
||||||
<field name="zpl_filename" invisible="1"/>
|
<field name="zpl_filename" invisible="1"/>
|
||||||
<field name="zpl_printer_id" required="1"/>
|
<field name="zpl_printer_id" required="1"/>
|
||||||
</group>
|
</group>
|
||||||
<footer>
|
<footer>
|
||||||
<button name="generate" type="object" string="Generate Label" class="btn-primary" states="step1"/>
|
<button name="generate" type="object" string="Generate Label" class="btn-primary" states="step1"/>
|
||||||
<button special="cancel" string="Cancel" class="oe_link" states="step1"/>
|
<button special="cancel" string="Cancel" class="btn-default" states="step1"/>
|
||||||
<button name="print_zpl" type="object" string="Print" class="btn-primary" states="step2"/>
|
<button name="print_zpl" type="object" string="Print" class="btn-primary" states="step2"/>
|
||||||
<button name="print_zpl" type="object" string="Print and New" class="btn-primary" context="{'print_and_new': True}" attrs="{'invisible': ['|', ('state', '!=', 'step2'), ('barcode_type', '=', 'product')]}"/>
|
<button name="print_zpl" type="object" string="Print and New" class="btn-primary" context="{'print_and_new': True}" attrs="{'invisible': ['|', ('state', '!=', 'step2'), ('barcode_type', '=', 'product')]}"/>
|
||||||
<button special="cancel" string="Close" class="oe_link" states="step2"/>
|
<button special="cancel" string="Close" class="btn-default" states="step2"/>
|
||||||
</footer>
|
</footer>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user