Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] mrp_workflow_print_label: define new workflow with QR code #90

Open
wants to merge 2 commits into
base: 8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mrp_workflow_print_label/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'views/mrp_bom_view.xml',
'views/mrp_workflow.xml',
'views/stock_inventory.xml',
"views/res_company_view.xml",
'reports/label.xml',
"security/security.xml",
"security/ir.model.access.csv",
Expand Down
1 change: 1 addition & 0 deletions mrp_workflow_print_label/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
from . import mrp_bom
from . import stock_picking
from . import stock_move
from . import res_company
1 change: 1 addition & 0 deletions mrp_workflow_print_label/models/mrp_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class MrpProduction(models.Model):
cloth_rolls = fields.Char(string="Cloth Rolls", readonly=True)
total_pieces = fields.Integer(readonly=True)
print_lot_barcode = fields.Binary(readonly=True)
production_barcode = fields.Binary(readonly=True)
cloth_type = fields.Selection(related='bom_id.cloth_type')
produce_button = fields.Boolean(
string='Button Produce',
Expand Down
13 changes: 9 additions & 4 deletions mrp_workflow_print_label/reports/label.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
<span t-esc="doc.product_id.default_code"/>
</td>
<td rowspan="4">
<img style="max-height: 45px;" t-att-src="'data:image/png;base64,%s' % res_company.logo" t-if="res_company.logo"/>
<img style="max-height: 200px;" t-att-src="'data:image/png;base64,%s' % doc.production_barcode"/>
<img style="max-height: 50px;" t-att-src="'data:image/png;base64,%s' % res_company.logo" t-if="res_company.logo"/>
</td>
</tr>
<tr>
Expand All @@ -51,8 +52,12 @@
<span t-esc="doc.user_id.name"/>
</td>
</tr>
<tr>
<td colspan="2" class="text-center">
<img style="max-height: 50px;" t-att-src="'data:image/png;base64,%s' % doc.print_lot_barcode"/>
</td>
</tr>
</table>
<img style="aling:center;" t-att-src="'data:image/png;base64,%s' % doc.print_lot_barcode"/>
<br/>
<div>
<span style="float:left;font-size:11px">FOR-PRO-18</span>
Expand Down Expand Up @@ -115,9 +120,9 @@
</td>
</tr>
</table>
<img style="aling:center;" t-att-src="'data:image/png;base64,%s' % doc.print_lot_barcode"/>
<img style="max-height: 100px;" t-att-src="'data:image/png;base64,%s' % doc.production_barcode"/>
<br/>
<div>
<div>
<span style="float:left;font-size:11px">FOR-PRO-17</span>
<span style="float:right;font-size:11px">Ver.01</span>
</div>
Expand Down
15 changes: 15 additions & 0 deletions mrp_workflow_print_label/views/res_company_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_res_company_form_inherit" model="ir.ui.view">
<field name="name">res.company.form.inherit</field>
<field name="model">res.company</field>
<field name="inherit_id" ref="base.view_company_form"/>
<field name="arch" type="xml">
<field name="currency_id" position="after">
<field name="supplier_number"/>
</field>
</field>
</record>
</data>
</openerp>
31 changes: 20 additions & 11 deletions mrp_workflow_print_label/wizard/mrp_print_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ class MrpPrintLabel(models.TransientModel):
def print_report(self):
self.order_id.state = "print_label"
message = _("Printed by: %s") % self.order_id.user_id.name
if self.order_id.bom_id.cloth_type == 'cloth':
image = self.env['report'].barcode(
'Code128', self.print_lot,
width=300, height=50, humanreadable=1)
image_b64 = base64.encodestring(image)
else:
production_barcode = self.env['report'].barcode(
'QR', self._prepare_qr_code(),
width=300, height=300)
production_barcode_b64 = base64.encodestring(production_barcode)
print_lot_barcode = self.env['report'].barcode(
'Code128', self.print_lot,
width=300, height=50, humanreadable=1)
print_lot_barcode_b64 = base64.encodestring(print_lot_barcode)
if self.order_id.bom_id.cloth_type != 'cloth':
message = message + _(
'<br/>Container Quantity: %s') % self.container_qty
image = self.env['report'].barcode(
'Code128', self.print_lot,
width=300, height=50, humanreadable=1)
image_b64 = base64.encodestring(image)
self.order_id.write({
'components_number': self.components_number,
'components_pieces': self.components_pieces,
'total_pieces': self.components_pieces * self.components_number,
'container_qty': self.container_qty,
'print_lot': self.print_lot,
'print_lot_barcode': image_b64,
'print_lot_barcode': print_lot_barcode_b64,
'production_barcode': production_barcode_b64,
})
self.order_id.message_post(
body=message)
Expand All @@ -65,6 +65,15 @@ def print_report(self):
'docs': self.order_id.id
}

@api.multi
def _prepare_qr_code(self):
qr_code = "1J{supplier_number}Q{quantity}P{part_number}V{supplier_number}1T{lot}21L".format(
supplier_number=self.order_id.company_id.supplier_number.ljust(18, '0'),
quantity=self.components_pieces * self.components_number,
part_number=self.order_id.product_id.default_code or "",
lot=self.print_lot)
return qr_code

@api.model
def default_get(self, fields):
res = super(MrpPrintLabel, self).default_get(fields)
Expand Down