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

Hello,

I need to create a certain model that has these fields among others:

- employee_id (self explaining)

- year (which corresponds to a year between the date employee_id's contract started and now)

I need to be able to select a year within said range, but I can't use Selection because it can't be populated via onchange, and using Many2one would require creating a whole model that only contains the field 'year', plus populating the new model's table with an arbitrary range, which doesn't make a lot of sense.

Is there any other way to achieve what I want?

Thanks a lot.

อวตาร
ละทิ้ง

need more explanation ....

Selection can be populated onchange. there are many examples in source code.

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

Hi,

If i had to do it, i would do what you suggest :

- create a simple year model that contains 1 Integer field year

- populate it with relevant range, e.g. with a csv file or with xml data

- add a many2one field to year_id in your model

- then add a dynamic domain on the Many2one field set with a 'onchange' depending of the employee_id e.g :

@api.onchange('employee_id')
def _onchange_employee_id(self):
if self.employee_id:
    your_domain = []
    contract_year = ... get contract year from employee
    your_domain += [('year','>', contract_year)] ... or whatever you need
    domain = {'year_id': [
            your_domain
    ]}

        return {'domain': domain}



อวตาร
ละทิ้ง

and then don't forget to add access rules to this simple model... it is true that is a bit heavy. If there is better solution, i'd also be curious to know !

I would also use widget='selection' in the view for the field year_id, to avoid creation/modification

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ก.ย. 23
3793
many to one domain field แก้ไขแล้ว
1
ก.พ. 22
2781
1
พ.ย. 21
2515
3
มี.ค. 15
5760
2
มิ.ย. 25
3469