Skip to content

Commit

Permalink
[ADD]stock_ux: zpl global function
Browse files Browse the repository at this point in the history
  • Loading branch information
jcadhoc committed Nov 5, 2024
1 parent 667f391 commit d13ecef
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 20 deletions.
1 change: 1 addition & 0 deletions stock_ux/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
'security/ir.model.access.csv',
'views/product_template_views.xml',
'views/product_product_views.xml',
'wizards/stock_picking_wizard_views.xml',
'views/stock_picking_views.xml',
'views/stock_move_views.xml',
'views/stock_move_line_views.xml',
Expand Down
18 changes: 15 additions & 3 deletions stock_ux/report/ir.action.reports.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<record id="action_custom_label_transfer_template_view_pdf" model="ir.actions.report">
<field name="name">Etiqueta de despacho (PDF)</field>
<field name="model">stock.picking</field>
<field name="model">stock.picking.zpl</field>
<field name="binding_model_id" ref="stock.model_stock_picking"/>
<field name="report_type">qweb-pdf</field>
<field name="report_name">stock_ux.custom_label_transfer_template_view_pdf</field>
Expand All @@ -38,14 +38,26 @@
<field name="paperformat_id" ref="stock_ux.label_10x15"/>
</record>

<record id="action_custom_barcode_transfer_template_view_pdf" model="ir.actions.report">
<record id="action_custom_barcode_transfer_template_view_zpl" model="ir.actions.report">
<field name="name">Etiquetas de Productos del picking (ZPL)</field>
<field name="model">stock.picking</field>
<field name="model">stock.picking.zpl</field>
<field name="binding_model_id" ref="stock.model_stock_picking"/>
<field name="report_type">qweb-text</field>
<field name="report_name">stock_ux.custom_barcode_transfer_template_view_zpl</field>
<field name="report_file">stock_ux.custom_barcode_transfer_template_view_zpl</field>
<field name="binding_type">report</field>
</record>

<record id="action_custom_zpl" model="ir.actions.report">
<field name="name">Etiquetas zpl global</field>
<field name="model">stock.picking.zpl</field>
<field name="binding_model_id" ref="stock.model_stock_picking"/>
<field name="report_type">qweb-text</field>
<field name="report_name">stock_ux.custom_label_transfer_template_view_zpl</field>
<field name="report_file">stock_ux.custom_label_transfer_template_view_zpl</field>
<field name="binding_type">report</field>

</record>

</odoo>

21 changes: 12 additions & 9 deletions stock_ux/report/picking_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Fecha
</template>
<template id="stock_ux.custom_label_transfer_template_view_pdf">
<t t-call="web.basic_layout">
<t t-foreach="docs" t-as="picking">
<t t-foreach="docs.line_ids.move_id.picking_id" t-as="picking">
<t t-set="numero" t-value="0"/>
<t t-set="qty" t-value="picking.number_of_packages"/>
<t t-if="qty == 0">
Expand Down Expand Up @@ -260,10 +260,13 @@ Transportista:
<div style="font-weight: normal;">Orden:
<t t-esc="picking.origin"/>
</div>
<!-- TODO: comentamos ya que ahora no depende de aeroo, revisamos dependencia? Sacamos estas lineas? Movemos informe? -->
<!-- <t t-if="picking.voucher_ids">
<div style="font-weight: normal;">Remito/s:
<t t-set="voucher_names" t-value="','.join(picking.voucher_ids.mapped('name'))"/>
<t t-esc="voucher_names"/>
</div>
</t> -->
<br/>
<div name="footer_left_column" position="inside">
<img t-if="picking.name" t-att-src="'/report/barcode/?barcode_type=%s&amp;value=%s&amp;width=%s&amp;height=%s' % ('Code128', picking.name, 400, 40)" alt="barcode" style="height:40"/>
Expand Down Expand Up @@ -310,8 +313,8 @@ Transportista:
<template id="stock_ux.custom_barcode_transfer_template_view_zpl">
<t t-set="numero" t-value="0"/>
<t t-as="l" t-foreach="docs">
<t t-as="o" t-foreach="l.move_line_ids.filtered(lambda v: v.product_id.uom_id.id == 1)">
<t t-as="i" t-foreach="range(0,int(o.qty_done))">
<t t-as="o" t-foreach="l.line_ids.filtered(lambda v: v.move_id.product_id.uom_id.id == 1)">
<t t-as="i" t-foreach="range(0,int(o.move_quantity))">
<t t-set="numero" t-value="numero + 1"/>
<t t-if="numero % 2 != 0 ">
^XA
Expand All @@ -320,32 +323,32 @@ Transportista:
^FO20,10,0

^FO260,10
^A0N,20,25^FD<t t-esc="l.date_done" t-options="{'widget': 'date'}"/>^FS
^A0N,20,25^FD<t t-esc="o.move_id.picking_id.date_done" t-options="{'widget': 'date'}"/>^FS

^FO20,40
^A0N,40,30
^TBN,360,40
^FD<t t-esc="o.product_id.display_name"/>^FS
^FD<t t-esc="o.move_id.product_id.display_name"/>^FS

^FO20,90
^BY3
^BCN,60,Y,N,N,A
^FD<t t-esc="o.product_id.barcode"/>^FS
^FD<t t-esc="o.move_id.product_id.barcode"/>^FS
</t>
<t t-if="numero % 2 == 0 ">
^FX Nueva etiqueta
^LH445,0
^FO20,10,0
^FO260,10
^A0N,20,25^FD<t t-esc="l.date_done" t-options="{'widget': 'date'}"/>^FS
^A0N,20,25^FD<t t-esc="o.move_id.picking_id.date_done" t-options="{'widget': 'date'}"/>^FS
^FO20,40
^A0N,40,30
^TBN,360,40
^FD<t t-esc="o.product_id.display_name"/>^FS
^FD<t t-esc="o.move_id.product_id.display_name"/>^FS
^FO20,90
^BY3
^BCN,60,Y,N,N,A
^FD<t t-esc="o.product_id.barcode"/>^FS
^FD<t t-esc="o.move_id.product_id.barcode"/>^FS
^XZ
</t>
</t>
Expand Down
2 changes: 2 additions & 0 deletions stock_ux/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_stock_operation_wizard,access_stock_operation_wizard,model_stock_operation_wizard,base.group_user,1,1,1,1
stock_ux.access_stock_picking_zpl,access_stock_picking_zpl,stock_ux.model_stock_picking_zpl,base.group_user,1,1,1,1
stock_ux.access_stock_picking_zpl_lines,access_stock_picking_zpl_lines,stock_ux.model_stock_picking_zpl_lines,base.group_user,1,1,1,1
23 changes: 23 additions & 0 deletions stock_ux/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,27 @@
<record id="stock.action_stock_move_pivot_all" model="ir.actions.act_window.view">
<field name="sequence" eval="10"/>
</record>

<record id="view_picking_form_inherited" model="ir.ui.view">
<field name="name">stock.picking.form</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<field name="description_picking" position="after">
<field name="origin_description" string="Descripción de origen" optional="hide"/>
</field>
</field>
</record>

<record id="view_picking_zpl" model="ir.ui.view">
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form" />
<field name="name">stock.picking.zpl</field>
<field name="arch" type="xml">
<xpath expr="//button[@name='button_validate']" position="after">
<button name="%(zpl)d" string="Etiquetas" type="action" groups="base.group_user" invisible="(picking_type_code != 'outgoing') or (state not in ['done'])"/>]
</xpath>
</field>
</record>

</odoo>
2 changes: 2 additions & 0 deletions stock_ux/wizards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
# directory
##############################################################################
from . import stock_operation_wizard
from . import stock_picking_wizard

26 changes: 21 additions & 5 deletions stock_ux/wizards/stock_picking_wizard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import fields, api, models, Command
from odoo import fields, api, models, Command, exceptions


class StockPickingZpl(models.TransientModel):
Expand All @@ -7,20 +7,27 @@ class StockPickingZpl(models.TransientModel):

picking_id = fields.Many2one('stock.picking',string='picking')
line_ids = fields.One2many('stock.picking.zpl.lines','picking_zpl_id', string='Moves')

@api.model
def default_get(self, default_fields):
rec = super().default_get(default_fields)
active_ids = self._context.get('active_ids') or self._context.get('active_id')
active_model = self._context.get('active_model')
if active_model == 'stock.picking':
move_ids = self.env[active_model].browse(active_ids).mapped('move_ids').filtered(lambda x: x.quantity > 0 )
rec['line_ids'] = [Command.create({'move_id': x.id, 'move_quantity':x.quantity}) for x in move_ids]
rec['line_ids'] = [Command.create({'move_id': x.id, 'move_quantity':x.quantity,'move_uom_id': x.product_uom}) for x in move_ids]
return rec

def action_print(self):
self.ensure_one()
report_id = self.env.ref("stock_ux.custom_label_transfer_template_view_zpl")
report_id = self.env.ref("stock_ux.action_custom_barcode_transfer_template_view_zpl")
report_action = report_id.report_action(self.ids)
report_action['close_on_report_download']=True
return report_action

def action_print_pdf(self):
self.ensure_one()
report_id = self.env.ref("stock_ux.action_custom_label_transfer_template_view_pdf")
report_action = report_id.report_action(self.ids)
report_action['close_on_report_download']=True
return report_action
Expand All @@ -35,4 +42,13 @@ class StockPickingZplLines(models.TransientModel):

move_quantity = fields.Float()

move_uom_id = fields.Many2one('uom.uom')

name = fields.Char(related='move_id.name')

@api.constrains('move_quantity')
def _check_move_quantity(self):
for line in self:
if line.move_quantity > line.move_id.quantity:
raise exceptions.ValidationError("La cantidad a imprimir no puede ser mayor que la cantidad original.")

8 changes: 5 additions & 3 deletions stock_ux/wizards/stock_picking_wizard_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@
<field name="picking_id" string="Transferencia" readonly="1"/>
<field name="line_ids">
<tree editable="top" create="false" delete="false">
<field name="move_id" column_invisible="True"/>
<field name="name" string="Producto"/>
<field name="move_id" invisible="1"/>
<field name="move_quantity" string="Cantidad a imprimir" readonly="0"/>
<field name="move_uom_id" string="Unidad" readonly="1"/>
</tree>
</field>
</sheet>
<footer>
<button name="action_print" type="object" string="Imprimir etiquetas"/>
<button name="action_print" type="object" string="Imprimir etiquetas de producto(ZPL)" class="btn btn-primary" help="Puede establecerse la cantidad de impresiones desde el asistente"/>
<button name="action_print_pdf" type="object" string="Imprimir etiqueta de despacho(PDF)" class="btn btn-primary" help="Imprimirá tantas como se indique en el número de paquetes"/>
</footer>
</form>
</field>
</record>

<record id="zpl" model="ir.actions.act_window">
<record id="stock_ux.zpl" model="ir.actions.act_window">
<field name="name">Asistente para impresion de reporte ZPL</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">stock.picking.zpl</field>
Expand Down

0 comments on commit d13ecef

Please sign in to comment.