2017-08-17 2 views
0

ボタン継承された 'product.template' モデルに 'action_open_quants' を追加 - 私は私のクラスにこれらのフィールドを持っているOdooのV8

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 

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") 

もともと、stockモジュールにあなたがこの機能を持ってし

私は自分のカスタムモジュールにproduct.templateを継承して以来、私は私のビューでこの非常に同じ機能を表示したいので、このように宣言しました:

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

もともと(stockモジュール上)、それはこのように宣言されています。今

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

私はMany2oneおよび関連分野から選ぶ製品に関連したクオンツを視覚化することができるので、それは、部分的に取り組んでいるが、それは私が私の意見でdinamically選択する製品に関連していません。

したがって、stockモジュールと同じように動作する方法はありますか?

私は自分自身を説明してくれることを願っています。

答えて

1

モジュールの_get_products関数を変更して、クオンツビューに表示する製品を返すことができます。

<field name="product_id" context="{'product_tmpl_id': product_id}"/> 

そして、あなたの_get_products機能で:

def _get_products(self, cr, uid, ids, context=None): 
    products = [] 
    context = context or {} 
    product_tmpl_id = context.get('product_tmpl_id', False) 
    if product_tmpl_id: 
     prodtmpl = self.pool.get('product.template').browse(cr, uid, product_tmpl_id, context=None) 
     if prodtmpl: 
      products += [x.id for x in prodtmpl.product_variant_ids] 
    else: 
     products = #... call super here 
    return products 
私はどうなる一つの方法は、あなたのビューに _get_products機能

へのproduct_idを渡すためにコンテキストを使用することです

関連する問題