This question has been flagged

I have these fields on my class:

class bsi_production_order(models.Model):
    _name = 'bsi.production.order'
    _inherit = ['mail.thread','text.paper','product.template']

    product_id = fields.Many2one('product.template', string="Product")
    qty_available = fields.Float(string="Qty Available", related="product_id.qty_available")

Originally, on stock module You got this function:

class product_template(osv.osv):
    _name = 'product.template'
    _inherit = 'product.template'

    def action_open_quants(self, cr, uid, ids, context=None):
        products = self._get_products(cr, uid, ids, context=context)
        result = self._get_act_window_dict(cr, uid, 'stock.product_open_quants', context=context)
        result['domain'] = "[('product_id','in',[" + ','.join(map(str, products)) + "])]"
        result['context'] = "{'search_default_locationgroup': 1, 'search_default_internal_loc': 1}"
        return result

Since I've inherited product.template on my custom module, I want to show this very same function on my view, so I just declared like this:

       <field name="product_id"/>
       <field name="qty_available"/>
       <button class="oe_stat_button"
            name="action_open_quants"
            icon="fa-building-o"
            type="object">

Originally (on stock module), it is declared like this:

   <button class="oe_stat_button"
        name="action_open_quants"
        icon="fa-building-o"
        type="object"  attrs="{'invisible':[('type', '=', 'service')]}" groups="stock.group_locations">
        <div><field name="qty_available_text"/></div>
        </button>

Right now, it is partially working, since I can visualize the quants associated with the product I choose from Many2one and related fields, but it is not related to the product I dinamically choose on my view.

So, is there a way o get it work exactly as it is on stock module?

I hope I've explained myself.

Avatar
Discard