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

Hi

I have two models:

class Pharmacy(models.Model):
    _inherit = 'res.partner'
     medicine_ids = fields.Many2many('product.template', string="Existing Medicines") 


class Medicine(models.Model):
    _inherit = 'product.template'
    pharmacy_ids = fields.Many2many('res.partner', string="Pharmacieis")

def add_pharmacies(self):

some logic

I need in form view of Medicine by pushing a button the function add_pharmacies be called and 1 pharmacy be added to the list of the pharmacies that have that product and the product to be added to specific pharmacy.

What Should I write in my function?

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

To your goal you should apply the special operators configured for many2many fields. In this case it is 'add': [(4, ID)]. The example to add a new pharmacy to the field 'pharmacy_ids':

@api.multi
def add_pharmacies(self):
for record in self:
id_to_add = 1 # put here your logic of how this pharmacy should be added
record.pharmacy_ids = [(4, id_to_add)]


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
ธ.ค. 22
3697
How to make sign up menu in website? แก้ไขแล้ว
2
เม.ย. 20
4649
1
เม.ย. 20
3603
2
ก.ย. 19
9189
0
ส.ค. 19
2702