Skip to content

Commit

Permalink
[ADD]stock_ux: zpl global function
Browse files Browse the repository at this point in the history
X-original-commit: 695fd64
  • Loading branch information
jcadhoc committed Dec 5, 2024
1 parent 5d20d02 commit dbf6be9
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 91 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
8 changes: 4 additions & 4 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">product.label.layout</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,14 @@
<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="binding_model_id" ref="stock.model_stock_picking"/>
<field name="model">product.label.layout</field>
<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>

</odoo>

22 changes: 9 additions & 13 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,6 @@ Transportista:
<div style="font-weight: normal;">Orden:
<t t-esc="picking.origin"/>
</div>
<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>
<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 +306,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">
<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 +316,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
1 change: 1 addition & 0 deletions stock_ux/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
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_lines,access_stock_picking_zpl_lines,stock_ux.model_stock_picking_zpl_lines,base.group_user,1,1,1,1
11 changes: 0 additions & 11 deletions stock_ux/views/report_deliveryslip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,4 @@
</xpath>
</template>

<!-- <template id="stock_report_delivery_has_serial_move_line" inherit_id="stock.stock_report_delivery_has_serial_move_line">
<xpath expr="//td[1]" position="attributes">
<attribute name="t-if">o.env['ir.config_parameter'].sudo().get_param('stock_ux.delivery_slip_use_origin', 'False') == 'False' or not move_line.origin_description</attribute>
</xpath>
<xpath expr="//td[1]" position="after">
<td t-if="o.env['ir.config_parameter'].sudo().get_param('stock_ux.delivery_slip_use_origin') == 'True' and move_line.origin_description">
<span t-field="move_line.origin_description"/>
</td>
</xpath>
</template> -->

</odoo>
37 changes: 7 additions & 30 deletions stock_ux/views/stock_move_line_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
<field name="picking_partner_id"/>
<field name="picking_code"/>
</field>
<<<<<<< HEAD
<field name="lot_id" position="attributes">
<attribute name="context">{'default_product_id': product_id, 'active_picking_id': picking_id, 'display_complete':True}</attribute>
</field>
<!-- <field name="quantity" position="after">
<button name="set_all_done" string="Set all Done" type="object" icon="fa-check" invisible="not context.get('show_reserved') or context.get('state_done')"/>
</field> -->
||||||| parent of 29a5b1f3 (temp)
<!-- <field name="quantity" position="after">
<button name="set_all_done" string="Set all Done" type="object" icon="fa-check" invisible="not context.get('show_reserved') or context.get('state_done')"/>
</field> -->
=======
>>>>>>> 29a5b1f3 (temp)
</field>
</record>

Expand Down Expand Up @@ -105,9 +112,6 @@
<attribute name="options">{'create':True, 'create_edit':True}</attribute>
<attribute name="context">{'default_product_id': product_id, 'active_picking_id': picking_id, 'default_company_id':company_id, 'display_complete':True}</attribute>
</field>
<!-- <field name="quantity" position="after">
<button name="set_all_done" title="Set all Done" type="object" icon="fa-check" invisible="state not in ('confirmed', 'assigned', 'waiting', 'partially_available')"/>
</field> -->
</field>
</record>

Expand All @@ -120,9 +124,6 @@
<field name="description_picking" optional="hide"/>
<field name="origin_description" string="Descripción de origen" optional="hide"/>
</field>
<!-- <field name="quantity" position="after">
<button name="set_all_done" title="Set all Done" type="object" icon="fa-check" invisible="state not in ('confirmed', 'assigned', 'waiting', 'partially_available')"/>
</field> -->
<!-- for compatibility with web_m2x_options we force allowing create lots -->
<field name="lot_id" position="attributes">
<attribute name="options">{'create':True, 'create_edit':True}</attribute>
Expand All @@ -136,9 +137,6 @@
<field name="model">stock.move.line</field>
<field name="inherit_id" ref="stock.view_stock_move_line_operation_tree"/>
<field name="arch" type="xml">
<!-- <field name="quantity" position="after">
<button name="set_all_done" title="Set all Done" type="object" icon="fa-check" invisible="state not in ('confirmed', 'assigned', 'waiting', 'partially_available')" context="{'from_popup':True}"/>
</field> -->
<!-- for compatibility with web_m2x_options we force allowing create lots -->
<field name="lot_id" position="attributes">
<attribute name="options">{'create':True, 'create_edit':True}</attribute>
Expand All @@ -152,18 +150,6 @@
</field>
</record>

<!-- adds action to add all move lines -->
<!-- <record model="ir.actions.server" id="action_operation_set_all_done">
<field name="name">Set all done</field>
<field name="model_id" ref="stock.model_stock_move_line"/>
<field name="binding_model_id" ref="stock.model_stock_move_line"/>
<field name="state">code</field>
<field name="code">
records.set_all_done()
</field>
</record> -->

<!-- adds action to add all move lines -->
<record model="ir.actions.server" id="action_operation_set_all_undone">
<field name="name">Set all undone</field>
<field name="model_id" ref="stock.model_stock_move_line"/>
Expand All @@ -174,13 +160,4 @@ records.filtered(lambda x: x.state not in ['draft', 'done', 'cancel']).write({'q
</field>
</record>

<!-- <record id="stock.stock_move_line_action" model="ir.actions.act_window">
<field name="name">Products Moves Detailed</field>
<field name="context">{'search_default_todo': 1,'search_default_done': 1}</field>
</record>
-->
<!-- <record id="stock.stock_move_line_menu" model="ir.ui.menu">
<field name="name">Products Moves Detailed</field>
</record> -->

</odoo>
9 changes: 0 additions & 9 deletions stock_ux/views/stock_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,4 @@
</field>
</record>

<!-- <record id="stock.stock_move_action" model="ir.actions.act_window">
<field name="name">Products Moves</field>
</record>
<record id="stock.stock_move_menu" model="ir.ui.menu">
<field name="name">Products Moves</field>
<field name="groups_id" eval="[(3, ref('base.group_no_one'))]"/>
</record> -->

</odoo>
13 changes: 13 additions & 0 deletions stock_ux/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?xml version="1.0"?>
<odoo>
<record id="view_picking_form" model="ir.ui.view">
<field name="name">stock.picking.form.inherit</field>
Expand Down Expand Up @@ -117,4 +118,16 @@
<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>

</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_label_type

53 changes: 53 additions & 0 deletions stock_ux/wizards/stock_label_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import _, fields, models,api, Command


class ProductLabelLayout(models.TransientModel):
_inherit = 'product.label.layout'
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,'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.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

class StockPickingZplLines(models.TransientModel):
_name = 'stock.picking.zpl.lines'
_description = "Print Stock Voucher lines"

picking_zpl_id = fields.Many2one('product.label.layout')

move_id = fields.Many2one('stock.move')

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.")
29 changes: 23 additions & 6 deletions stock_ux/wizards/stock_picking_wizard.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
from odoo import fields, api, models, Command
from odoo import fields, api, models, Command, exceptions


class StockPickingZpl(models.TransientModel):
_name = 'stock.picking.zpl'
_name = 'product.label.layout'
_description = "Print Stock Voucher"

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,14 @@ 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.")


Loading

0 comments on commit dbf6be9

Please sign in to comment.