Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
1743 Lượt xem


class A has a One2many field Wproductlist which points to Class B. i want to update the quantity field of stock.quant class by subtracting quantity_needed field of classB. how can i acheive this. I tried the below code, but it shows singeton error when the class B has multiple records.

class A
wproductlist = fields.One2many(comodel_name="class a",    inverse_name="ppp", string="Product List")

  api.multi
  def update
   d =  self.env['stock.quant'].search([('product_id', '=', 
    self.wproductlist.productname)])
   for record in d:
         record.write({'quantity':quantity'})


class B
_name = "classa"
productname = fields.Char(string="Product Name")
quantity = fields.Char(string="Product Available"


Ảnh đại diện
Huỷ bỏ
Tác giả

@sudhir arya : partially worked brother.. Now singelton error vanishes but how to include the quantity filed in the write function

Brother, that depends on your logic. You have to think about your object structure and business logic.

Câu trả lời hay nhất

You have to use loop to access the O2m field or similar to that. 

Try following code: 

productname = [prod.productname for prod in self.wproductlist]
d = self.env['stock.quant'].search([('product_id', 'in', productname)])


Ảnh đại diện
Huỷ bỏ