2016-05-18 7 views
0

私はsales.order.formのボタン(Confirm Sales)を変更しています。これを押すとすぐに在庫が取られます(stock.picking.form )。これは完全に機能します。しかし、私はいつ製品が在庫があるタイプのための機能を検証したい。注文した製品を1つだけ選択した場合にのみ動作します。このエラーで何ができますか? ValueError:予想されるシングルトン:sale.order.line(26,27)

私は複数の製品を選択する際の問題は、以下の画像のように、次のとおりです。

enter image description here

これは「販売を確認」ボタンの関数です。誰かがこの問題で私を助けることができる場合

@api.multi 
def action_confirm(self): 
    for order in self: 
     order.state = 'sale' 
     if self.env.context.get('send_email'): 
      self.force_quotation_send() 
     order.order_line._action_procurement_create() 
     if not order.project_id: 
      for line in order.order_line: 
       if line.product_id.invoice_policy == 'cost': 
        order._create_analytic_account() 
        break 
    if self.env['ir.values'].get_default('sale.config.settings', 'auto_done_setting'): 
     self.action_done() 

は**** HERE変更機能****************

if self.order_line.product_id.product_tmpl_id.type in 'product':   

    action = self.env.ref('stock.action_picking_tree_all') 

    result = { 
     'name': action.name, 
     'help': action.help, 
     'type': action.type, 
     'view_type': action.view_type, 
     'view_mode': action.view_mode, 
     'target': action.target, 
     'context': action.context, 
     'res_model': action.res_model, 
    } 

    pick_ids = sum([order.picking_ids.ids for order in self], []) 

    if len(pick_ids) > 1: 
     result['domain'] = "[('id','in',["+','.join(map(str, pick_ids))+"])]" 
    elif len(pick_ids) == 1: 
     form = self.env.ref('stock.view_picking_form', False) 
     form_id = form.id if form else False 
     result['views'] = [(form_id, 'form')] 
     result['res_id'] = pick_ids[0] 
    return result 

を開始します。システムが複数の製品を注文順に受け入れることを検証する方法は?ご助力ありがとうございます。

+0

なぜ 'sum()'を使用していますか? – Tony

+0

これは、一方で抽出された関数です。デフォルトではそうです。 私がしたのは、ifループに含めることだけでした。 **「製品」のself.order_line.product_id.product_tmpl_id.typeの場合:** – beriliox

答えて

0

私は、あなたがシングルトンとして自分自身を使用しているということですが、メソッドに@ api.multiデコレータがあるので、それはリストになる可能性があります。

... 
if order.order_line.product_id.product_tmpl_id.type in 'product':  
... 

編集:あなたがself.order_lineにアクセスしたとき

例外も上げることができ、私はあなたがあなたのコードを変更した場合、あなたの変更は、ループの最初の下にある場合、それは仕事ができる、ということだと思います同じ行。まるでそれが単一の要素であるかのようにしているし、それもリストである可能性があります。あなたはself.order_lineリストを繰り返し処理する必要があります:

... 
for line in self.order_line: 
    if line.product_id.product_tmpl_id.type in 'product': 
... 
関連する問題