Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
4203 Представления

Hello everyone,

- I'm trying to adding a default record in product pricelist items. So I do that in model product.pricelist

Here my code :

class Product_pricelist(models.Model):    

_inherit = "product.pricelist"

@api.model    

def default_get(self, fields_list):        

defaults = super(Product_pricelist, self).default_get(fields_list)        

new_product = self.env['product.product'].create({'name': 'Phí dịch vụ khác', 'type': 'service'})        

defaults.update({'item_ids': (0, 0, {'applied_on': '0_product_variant',                                         

'product_id': new_product.id,})})        

return defaults

and it throws an error:

Uncaught TypeError: Cannot read property '1' of undefined
http://localhost:8069/web/content/807-218fe6c/web.assets_backend.js:1460
Traceback:
TypeError: Cannot read property '1' of undefined
    at http://localhost:8069/web/content/807-218fe6c/web.assets_backend.js:1460:561
    at Function._.each._.forEach (http://localhost:8069/web/content/711-afeafc2/web.assets_common.js:12:558)
    at Class._parseServerData (http://localhost:8069/web/content/807-218fe6c/web.assets_backend.js:1460:290)
    at http://localhost:8069/web/content/807-218fe6c/web.assets_backend.js:1476:450
    at Function._.each._.forEach (http://localhost:8069/web/content/711-afeafc2/web.assets_common.js:12:558)
    at Object.<anonymous> (http://localhost:8069/web/content/807-218fe6c/web.assets_backend.js:1476:37)
    at Object.<anonymous> (http://localhost:8069/web/content/711-afeafc2/web.assets_common.js:802:681)
    at fire (http://localhost:8069/web/content/711-afeafc2/web.assets_common.js:796:299)
    at Object.fireWith [as resolveWith] (http://localhost:8069/web/content/711-afeafc2/web.assets_common.js:801:198)
    at Object.deferred.<computed> [as resolve] (http://localhost:8069/web/content/711-afeafc2/web.assets_common.js:803:56)
Can anyone have solution for this? 
Thanks
Аватар
Отменить
Лучший ответ

Hi,

You've missing brackets, when adding values in one2many field you must add list of tuples not a tuples.

e.g.:

defaults.update({'item_ids': [(0, 0, {'applied_on': '0_product_variant', 'product_id': new_product.id, })]})

Best regards!

Аватар
Отменить
Автор

It's working! Thanks a lot.

Related Posts Ответы Просмотры Активность
1
июн. 25
603
2
апр. 25
1006
0
янв. 25
1008
1
дек. 24
2429
0
апр. 24
1066