2017-10-12 15 views
0

마법사의 Many2many 유형 필드 ('pack_ids')와 sale.order.line의 Many2many ('pack_id') 유형 필드가 있습니다. 그리고 나는 Many2many 유형의 마법사 필드 ('pack_ids')의 값이 sales.order.line 필드 ('pack_id')로 반환되기를 바랍니다. 이 내 코드에 대한 Odoov10의 마법사에서 sales.order.line의 반환 값

은 여기에 있습니다 :

class SalePackWizard(models.TransientModel): 
    _name = "sale.pack.wizard" 
    _description = "Sale Pack Wizard" 

    @api.onchange('product_id') 
    def _onchange_product_pack_name(self): 
     print"A:", self.product_id.product_pack 
     res = self.product_id.product_pack 
     a = {} 
     print "res:", res 
     if res: 
      domain = {'pack_ids': [('id', 'in', [v.id for v in res])]} 
      a= res 
      print "a:", a 
      return {'domain': domain} 

    product_id = fields.Many2one('product.product', string="Product Pack", required=True, domain="[('is_pack','=',True)]") 
    qty = fields.Float(string='Quantity', digits=dp.get_precision('Product Unit of Measure'), required=True, default=1.0) 

    pack_ids = fields.Many2many('product.pack', string='Pack Products', change_default=True, 
           default=_onchange_product_pack_name) 


    @api.multi 
    def action_salepack_add(self): 
     rec = self._context.get('active_ids', []) 
     print "REC", rec, self.product_id.categ_id #product_uom 
     if rec: 
      line_values = {'product_id': self.product_id.id, 
          #'design_id':self.design_id.id, 
          'pack_id': self.product_id.product_pack, 
          'category_id':self.product_id.categ_id.id, 
          'order_id':rec[0], 
          'product_uom_qty':self.qty, 
          } 
      sale_order_line = self.env['sale.order.line'].create(line_values) 
+0

안녕하세요, ** ** 미리 product.product 필드 ** product_pack **의 유형은 무엇입니까? –

+0

It 's Many2one type 필드 –

답변

1

는 해당하여 코드를 업데이트 할 수 있습니다

@api.multi 
    def action_salepack_add(self): 
     order_id = self._context.get('active_id',False) 

     if order_id: 
      line_values = {'product_id': self.product_id.id, 
          'pack_id': [ (6, 0, [self.product_id.product_pack.id]) ], 
          'category_id':self.product_id.categ_id.id, 
          'order_id':order_id, 
          'product_uom_qty':self.qty, 
          } 
      sale_order_line = self.env['sale.order.line'].create(line_values) 

당신은 단지 그것을 ID를주는 many2many 분야에서 가치를 창출하지 못할 (이 many2one에만 해당). 필드가 one2many 또는 many2many 인 경우 :

(0, 0, { values }) link to a new record that needs to be created with the given values dictionary 
(1, ID, { values }) update the linked record with id = ID (write values on it) 
(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well) 
(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself) 
(4, ID) link to existing record with id = ID (adds a relationship) 
(5) unlink all (like using (3,ID) for all linked records) 
(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs) 
+0

다음과 같은 오류가 표시됩니다 : "ValueError : Expected singleton : product.pack (1, 2, 10)". 나는 또한 루프를 신청했다. –

+0

** product_pack **은 (는) many2one입니까? –

+0

가능한 경우 더 많은 오류를 표시 할 수 있습니다. –

0

오류가 수정되었습니다. 다음은 오류의 솔루션입니다 :

@api.multi 
    def action_salepack_add(self): 
     rec = self._context.get('active_ids', []) 
     print "REC", rec, self.product_id.categ_id #product_uom 
     if rec: 
      line_values = {'product_id': self.product_id.id, 
          #'design_id':self.design_id.id, 
          'pack_id': [(6, 0, [v.id for v in self.product_id.product_pack])], 
          'category_id':self.product_id.categ_id.id, 
          'order_id':rec[0], 
          'product_uom_qty':self.qty, 
          } 
      sale_order_line = self.env['sale.order.line'].create(line_values) 

감사합니다,