تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2518 أدوات العرض

I have a field where you get to pick a value from stock picking type value:

What I want, is to filter the list to not show already used values of stock picking value in the records of the model.

I want something like this:

so_receipt_location=fields.Many2one('stock.picking.type','Picking Location',domain=['id','not in' so_receipt_location.ids)

In a few words, don't display stock picking type option that has already been selected in any recordset of the model.


How can I achieve this?

 

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Managed to find a solution:

so_receipt_location=fields.Many2one('stock\.picking\.type','Τοποθεσία\ Παραλαβής'\)\ 
 \  \
def\ _available_locations\(self\):
 \  \  \ locations=self\.sudo\(\)\.search_read\(\[\('id','!=',self._origin.id)],{"so_receipt_location"})
     locations_list=[]
      for r in locations:
          if (r["so_receipt_location"]):
              locations_list.append(r["so_receipt_location"][0])
     return locations_list

@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False,submenu=False):
      res = super(SoftOneBranch, self).fields_view_get(
                view_id=view_id,view_type=view_type,toolbar=toolbar,submenu=submenu)                            locations_list=self._available_locations()
      if ('so_receipt_location' in res['fields']):
            res['fields']['so_receipt_location']['domain']=[('id','not in',locations_list)]
      return res           

@api.onchange('so_receipt_location')   
def _get_locations(self):
      locations_list=self._available_locations()
     return {'domain':{'so_receipt_location':[('id','not in',locations_list)]}}   

Domain for so_receipt_location gets updated when form loads and every time the user picks another option from the list. Available values exclude current id's value.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
3
سبتمبر 20
71895
1
سبتمبر 19
3132
2
سبتمبر 23
9597
Many2One Domain تم الحل
1
يوليو 20
5688
0
مارس 15
4796