Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
8 ตอบกลับ
6234 มุมมอง

how i can update attribute value if product is already in database ..


Code Preview

อวตาร
ละทิ้ง

What is the value inside the template_id variable?

If it is the product record, tell me what is the problem you are facing.

If it is not a product record, try to take the product record in that variable.

Like this: self.env[product.template].browse(id_of_record).write(values)

ผู้เขียน

yes template_id is product.template

ผู้เขียน

but write method is not working

You can show me the full function?

for better understanding please update your code

คำตอบที่ดีที่สุด

Hi Usman,

Please find below the code 

exist_attr = attr_line_obj.search([('product_tmpl_id', '=', template_id.id), ('attribute_id', '=', att_id.id)], limit=1)
if exist_attr:
     variant_Vals.append((1, exist_attr.id, {'value_ids': [(4, a_v_id)]}))
else:
     variant_Vals.append((0, 0, {'attribute_id': att_id.id, 'value_ids': [(4, a_v_id)]}))

Hope it is work.


อวตาร
ละทิ้ง
ผู้เขียน

you are just amazing love it thank you sooo much for solving my prlbm ......

คำตอบที่ดีที่สุด

When I make a custom app, I use the custom view to update a record's value. So whenever I wanted to edit an existing record, I just click Edit Button in the top left page to edit it. So sorry if this isn't the answer you need.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi Usman,

Here is an example of code for updating product template attributes.

Check this and try to fix your problem, while considering this

@api.multi
def test_test(self):
self.env['product.template'].browse(product_id).write({
'attribute_line_ids': [(0, 0, {
'attribute_id': attribute_id,
'value_ids': [(6, 0, [value_id_1, value_id_2])],
})]
})


Thanks & Regards

Avinash N K

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ส.ค. 23
2643
1
ก.ค. 23
2813
0
ก.ค. 23
2355
0
ก.ค. 23
2276
0
ม.ค. 21
3255