Odoo Help


Developing a new popup in stock_picking, basic doubts about how to generate the popup

on 2/12/16, 1:03 AM 618 views

I am trying to develop a new popup for stock_picking which will display the move.lines and allow user to select them and print a custom report with selected ones.

As a first try I want to generate the popup with just a couple of fields of the stock.picking.

- Do I have to use models.Transient or models.Model?

- Do I have to give it a different _name="label.picking" or just extend "stock.picking" and use it?

- Do I have to use view_id field in the button controller?

This is the model:

# -*- coding: utf-8 -*-
from openerp import models, fields
class LabelPicking(models.TransientModel):
_name = "label.picking"
_inherit = "stock.picking"
def view_tree_print_dispatch_items(self):
return {
'type': 'ir.actions.act_window',
'name': 'view_tree_print_dispatch_items',
'view_type': 'tree',
'view_mode': 'tree',
'res_model': 'label.picking',
'target': 'new',

And this is the XML:

<?xml version="1.0" encoding="utf-8" ?>
<record model="ir.ui.view" id="stock.view_picking_form_item_labels">
<field name="name">stock.picking.form.item_labels</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='state']" position="before">
<button name="view_tree_print_dispatch_items" string="Imprimir Items" type="object"/>

<record id="view_tree_print_dispatch_items" model="ir.ui.view">
<field name="name">Labels Dispatch Items Tree</field>
<field name="model">stock.picking</field>
<field name="arch" type="xml">
<field name="name"/>-
<field name="origin"/>-

Jose M. González
On 2/12/16, 4:12 AM


this example may help, in my case i use popup to update other model and return the original view. (this popup is launched from button)

#modelo temporal para popup.

class refuse_leave(osv.osv_memory):

_name = "refuse.leave"

_description = "Reason that order is not delivered"

_columns = {

'refusal_explanation': fields.text('Refusal explanation', required=True),

'return_reasons_type': fields.many2one('delivery.return.reasons.type','Return type', required=True),



     #botón de guardar la información introducida en el popup

def refuse_leave(self,cr, uid, ids, context=None):

data = self.read(cr,uid,ids)[0] 

return_reason = data['refusal_explanation']

return_type = data['return_reasons_type'][0]

if return_reason == "" or( len(return_reason)< 5):

raise osv.except_osv(_('Error'), _('Motivo no válido'))


delivery_route_line_obj = self.pool.get('delivery.route.line')

record_id = context.get('delivery_line_id')

tipo_incidencia = context.get('tipo_entrega')     

[ operaciones que tenga que realizar ]

return True


<!-- xml con el modelo del popup --> <?xml version="1.0" encoding="utf-8"?>



<record id="view_refuse_leave" model="ir.ui.view">

<field name="name">Leave Refuse</field>

<field name="model">refuse.leave</field>

<field name="arch" type="xml">

<form string="Refuse_Leave"> <!-- position="attributes"-->

<separator string="Información de recepción de pedido" />

<attribute name="string"> Seleccione el motivo por el cual el pedido no se entregó correctamente del siguiente desplegable:<br></br></attribute>

<!-- <div style="float:left; widht:30%;">

<field name="return_reasons_type" />

</div> -->

<group colspan="0" col="0">

<div><b>Razones</b> </div><newline />

<field name="return_reasons_type" nolabel="1" />

<field name="refusal_explanation" nolabel="1" placeholder="Indique el motivo por el que no se pudo entregar es pedido..." />



Es obligatorio que indique algún texto de por qué este pedido no fue entregado correctamente.




<button string="Guardar motivo" class="oe_highlight" type="object" name="refuse_leave" />

<button string="Salir" special="cancel" /> <!-- class="oe_link" -->





<record id="action_view_refuse_leave" model="ir.actions.act_window">

<field name="name">Leave Refuse</field>

<field name="type">ir.actions.act_window</field>

<field name="res_model">refuse.leave</field>

<field name="view_type">form</field>

<field name="view_mode">form</field>

<field name="target">new</field>




<!-- xml que lanzará el popup -->


<button name="action_received_with_exception" string="Received with exception"

type="object" states="delivered" />

#python desde donde lanza la acción del botón

def action_received_with_exception (self, cr, uid, ids, context=None):


'tipo_entrega' : 'ok_con_incidencias',

'delivery_line_id': ids[0],



return {

'name': 'Causas de devolución de pedido',

'view_type': 'form',

"view_mode": 'form',

'res_model': 'refuse.leave',

'type': 'ir.actions.act_window',

'target': 'new',

'flags': {'action_buttons': False},

'context': context,


except ValueError:

raise osv.except_osv(_('Error'))

It helps, now I am trying a transient model which inherits from stock_picking, how do you move a given ID (or parameter) from stock_picking to the popup model/form when you click the button?

on 2/12/16, 4:17 AM

with that question I have also fought x-D with this code: [code] context.update({ 'tipo_entrega' : 'ok_con_incidencias', 'delivery_line_id': value that you want, }) [/code] you can pass the info in the context to popup because you add param 'context': context ( see -> #python desde donde lanza la acción del botón). And you obtain the pass value in this line: record_id = context.get('delivery_line_id') ( see -> #modelo temporal para popup.). May the Force be with you !!!

Jose M. González
on 2/12/16, 4:51 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/12/16, 1:03 AM
Seen: 618 times
Last updated: 2/12/16, 4:12 AM