跳至內容
選單
此問題已被標幟
2 回覆
1869 瀏覽次數

I need to make different sequence name if maintenance_team_id = 1 or 2, etc

Here is my sequence code in bold. For now my sequence is applied to all maintenance_team_id

But i want to make different sequence based on each of maintenance_team_id


@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
vals['name'] = self.env['ir.sequence'].next_by_code(
'maintenance_id_1') or _("New")
# context: no_log, because subtype already handle this
maintenance_requests = super().create(vals_list)
for request in maintenance_requests:
if request.owner_user_id or request.user_id:
request._add_followers()
if request.equipment_id and not request.maintenance_team_id:
request.maintenance_team_id = request.equipment_id.maintenance_team_id
if request.close_date and not request.stage_id.done:
request.close_date = False
if not request.close_date and request.stage_id.done:
request.close_date = fields.Datetime.now()
maintenance_requests.activity_update()
return maintenance_requests


頭像
捨棄
最佳答案

Hey Ricky, 
You can try below code , 
 
for vals in vals_list: 
​maintenance_team_id = vals.get('maintenance_team_id', False) 

​​if maintenance_team_id: 
​​# Define a naming convention based on maintenance_team_id

​sequence_code = f'maintenance_id_{maintenance_team_id}'
​# Use the sequence based on the maintenance_team_id

​vals['name'] = ​  self.env['ir.sequence'].next_by_code(sequence_code) or _("New") 

​else: 
​# Handle the case when maintenance_team_id is not present

​vals['name'] = _("New")

頭像
捨棄
最佳答案

Hello Ricky,

In that case you can check the conditions and based on that you can execute the sequence.

For Eg. you can try like.


for vals in vals_list:
    if 'maintenance_team_id' in vals and vals['maintenance_team_id'] ==1"
        vals['name'] = self.env['ir.sequence'].next_by_code('maintenance_id_1') or _("New")
    else:
    vals['name'] = self.env['ir.sequence'].next_by_code('maintenance_id_2') or _("New"
頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
8月 25
222
4
5月 25
2763
2
5月 25
6181
1
3月 25
1838
4
3月 25
4754