2
votes

I'm stuck to populate a wizard since a week know, and I'm completely lost on the way to do that.

Until know, I've created a custom button on the stock module, view_picking_form record with an inherited model (see views.xml). I also know how to create a custom wizard (wizard.py wizard.xml).

But what I do not know is how to populate it with the list of products fields product_id, product_qty, qty_done that are linked to to the parent view. I'm working with the new API on Odoo 10 and couln't find the method to do that. Odoo always tells me it doesn't know the fields I want to pass and nothing display on the wizard.

Can anyone help me on that ?

views.xml

    <?xml version="1.0" encoding="utf-8"?>
    <odoo>
        <data>
            <record id="view_picking_form_inherit" model="ir.ui.view">
                <field name="name">stock.picking.form.inherit</field>
                <field name="model">stock.picking</field>
                <field name="inherit_id" ref="stock.view_picking_form"/>
                <field name="arch" type="xml">

                    <xpath expr="//form/sheet/h1[@class='hidden-xs']" position="inside">
                        <div class="oe_right oe_button_box">

                            <button string="Open Wizard" name="%(action_wizard)d"
                                    type="action" class="oe_button oe_form_button oe_highlight"/>
                        </div>
                    </xpath>
                </field>
            </record>
        </data>
    </odoo>

wizard.py

# -*- coding: utf-8 -*-
from odoo import _, api, fields, models

class MyClass(models.TransientModel):
    _name = 'stock.picking.wizard'
    _inherit = ['stock.picking', 'stock.pack.operation']

    def _default_products(self):
        active_id = self.env.context.get('active_id')
        if active_id:
            product = self.env['stock.picking'].browse(active_id)
            return product.product_id
        return False

    product_id = fields.Many2one('product.product', string='Product', default=_default_products)

wizard.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="view_wizard" model="ir.ui.view">
            <field name="name">stock_picking_wizard</field>
            <field name="model">stock.picking.wizard</field>
            <field name="arch" type="xml">
                <form string="Stock Products">
                    <field name="picking_id"/>
                    <tree string="Product list">
                        <field name="product_id"/>
                        <field name="product_qty"/>
                    </tree>
                </form>
            </field>
        </record>

        <record id="action_wizard" model="ir.actions.act_window">
            <field name="name">Wizard</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">stock.picking.wizard</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="view_id" ref="view_wizard"/>
            <field name="target">new</field>
        </record>
    </data>
</odoo>
1

1 Answers

1
votes

You need to pass the active_id through context: context="{'default_active_id': active_id}"

  <button string="Open Wizard" name="%(action_wizard)d"
                                        type="action" context="{'default_active_id': active_id}" class="oe_button oe_form_button oe_highlight"/>