creating a function to set default value of a Many2one field (thanks 2 @Kiran Mohan), odoo says NameError: name 'default_categry' is not defined , please help, using Pycharm as IDE, screenshot is here:
regards
creating a function to set default value of a Many2one field (thanks 2 @Kiran Mohan), odoo says NameError: name 'default_categry' is not defined , please help, using Pycharm as IDE, screenshot is here:
regards
Hi,
1. Usually .ids is used only for returning ids to many2many fields and not for many2one field.
2. default works when a record is newly created , when you select create button to create a form or when you select add a line , It works on the go.
3. Here on the go, there is no data filled in items_id. Only if items_id is available you can check the category of the item.
3. So i guess default wont work in your case.
or
you can have your categry_id field as a related one like,
categry_id = fields.Many2one('product.category', string='Category', related='items_id.categ_id', store=True)
Related fields wont be stored in database unless you give store = True
or
Try api.onchange
@api.onchange('items_id')
def onchange_items_id(self):
if self.items_id:
self.categry_id = self.items_id.categ_id and self.items_id.categ_id or False
else:
self.categry_id = False
Hope it helps,
Thanks
thanks @Karthikeyan, for feedback and to help other through your Answer, i have to mention that your code below works fine... :)
categry_id = fields.Many2one('product.category', string='Category', related='items_id.categ_id', store=True)
Hi,
For you information, if you change the category of that product in product category master, then in your transaction form, the category of the product will get changed.
I suggest you to make sure you don't change anything in the reference field (category) when it is used as a related field.
If this is your requirement ( If any change made in master to be reflected in all of your old transactions then you can use related in your development.)
So i always suggest you to go with the last one....api.onchange
Thanks
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj się| Powiązane posty | Odpowiedzi | Widoki | Czynność | |
|---|---|---|---|---|
|
2
kwi 23
|
4322 | |||
|
2
lut 25
|
43092 | |||
|
2
lis 22
|
4192 | |||
|
1
lut 22
|
9205 | |||
|
2
gru 21
|
5768 |
1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.