0
votes

I am creating a button on the sale.order.line model when pressed open a popup window, this view is in stock.picking.form. The problem is that when I open the popup shows the blank form. And what I want is that the popup displays the data I enter in the sale.order.line form. For example : product name , quantity, customer name , etc...enter image description hereenter image description here

This is my button in my view.xml:

<button name="action_stock_picking" string="Inventario" type="object" icon="fa-arrow-right"/>

And this is my button function that opens the popup:

@api.multi
def action_stock_picking(self):
    self.ensure_one()
    picking_form = self.env.ref('stock.view_picking_form', False)
    ctx = dict(
        default_model='stock.picking',
        default_res_id=self.id,
        default_composition_mode='comment',
        mark_invoice_as_sent=True,
    )
    return {
        'name': _('Formulario de Inventario: Recepciones'),
        'type': 'ir.actions.act_window',
        'view_type': 'form',
        'view_mode': 'form',
        'res_model': 'stock.picking',
        'views': [(picking_form.id, 'form')],
        'view_id': picking_form.id,
        'target': 'new',
        'context': ctx,
    }

I was researching, and I think you should use the context attribute to pass data between views, but do not know much how to do this.

1

1 Answers

0
votes

Indeed you can set default data using context. The syntax is simple :

default_fieldx : val

Example to set the default product name in your wizard add this line to your code

ctx = dict(
    default_name : self.name,
    default_model='stock.picking',
    default_res_id=self.id,
    default_composition_mode='comment',
    mark_invoice_as_sent=True,
)