Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3780 Widoki

I need to assign a sequence default_code to created products depending on their categories using an Automated Action.

 

My problem is that I can't access the categ_id. Does anyone know how to solve this problem?

 

Example:


code: 

if not record.default_code:
  if record.categ_id
== 1:
    record.write({
      'default_code':
env ['ir.sequence'].next_by_code('cat1')
    })
  else:
    record.write({
      'default_code':
env ['ir.sequence'].next_by_code('cat2')
    })
 

log:

 

2022-09-08 16:14:27,094 4 WARNING odoo-categories-test-5807939 odoo.models: unsupported operand type(s) for "==": 'product.category()' == '1' (None:15)


Awatar
Odrzuć
Najlepsza odpowiedź

Hi Christian Cabral, 

Your code is right, Just need to change the category comparison code for category id instead of category record set.

Just like this: 

code: 

if not record.default_code:
if record.categ_id.id == 1:
record.write({
'default_code': env ['ir.sequence'].next_by_code('cat1')
})
else:
record.write({
'default_code':env ['ir.sequence'].next_by_code('cat2')
})

Hope it will help you. 

Please Vote Up.
Thanks

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
mar 22
2063
1
lis 23
2085
0
lis 23
1203
2
gru 23
5660
1
mar 23
9151