콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
10916 화면

Am trying to prevent selecting of the same value in one2many field, when the 'select an item' button is clicked .For example when trying to select the same product that has been already selected in sale order.

아바타
취소
베스트 답변

I have done the same requirement in my project. I restricted duplication of product addition at o2m in sales form. (v7)

sale.py

 def onchange_one2many(self, cr, uid, ids, order_line):

mylist = []

if order_line != []:

    for line in order_line:

        for loop in line:

            if isinstance(loop, dict):

                mylist.append(loop['product_id'])

if len(mylist) != len(set(mylist)):

    raise osv.except_osv(_('Warning'),_('Product Should be Unique'))

return True

.xml

<field name="order_line" on_change="onchange_one2many(order_line)" />

Thanks Rifakat Haradwala

Note: Correct me if anyone has better answer

아바타
취소
베스트 답변

you can get the idea by this code .... just get unique ids of each many2one field ...in my case i had 2...


def onchange_line_course(self):

lists_course=self.courselines.mapped('field1.id')
lists_assesment=self.courselines.mapped('field2.id')
for rec in lists_assesment:
for crs in lists_course:
record_count = self.courseline.filtered(lambda rex: rex.course.id == crs and rex.assessment.id == rec)

if len(record_count) >1:
print(cannot select duplicate values


if you have only one many2one filed then only one for loop would be required
아바타
취소
베스트 답변

Hi,

Well you need specific development for that. It's not something you could configure.

You need to override write() of the main model and in write() you can iterate on the IDs of o2m field and put a check on the Product if it repeats and raise warning. Write() will be called when you save main form, so you won't be notified while you actually inserting line items. I am not sure onchange of o2m field would help because ID of newly inserted line item is not yet created while you add it, but you can give it onchange(o2m) also try.

Regards,

아바타
취소
관련 게시물 답글 화면 활동
2
5월 19
4257
0
5월 16
4870
1
3월 15
5315
1
3월 23
2407
0
12월 22
3036