This question has been flagged
2 Replies
6451 Views

I'm getting the following error when executing an Automated Action in Odoo: ValueError: : "can't adapt type 'product.template'" while evaluating

I'm trying to update the 'sequence' value in model 'product.supplierinfo' so that when the supplier's price are updated from a purchase order, that supplier is prioritized to calculate the replenishment cost. To achive that, it must set the lowest 'sequence' value for that product.

I'm getting an error on a module I'm not calling in my code. Any ideas why?

product = record.product_tmpl_id
record['sequence'] = 1
val = 1
registros = env['product.supplierinfo'].search([('product_tmpl_id','=',product)],order="sequence asc")
for line in registros:
  valor = val + 1
  line['sequence'] = valor

Automated Action Settings:

  • Model: product.supplierinfo
  • Action: Execute Python code
  • Condition: Creat and update
Avatar
Discard
Best Answer

Hello Enrique,


You need to rewrite your code as below:


product = record.product_tmpl_id

record['sequence'] = 1

val = 1

registros = env['product.supplierinfo'].search([('product_tmpl_id','=',product.id)],order="sequence asc")

for line in registros:

  valor = val + 1

  line['sequence'] = valor

Regards,




Email:   odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

   

Avatar
Discard
Author

Hi Jainesh,

That just did the trick. I'm kind of a noob in this, would you mind explaining how did you know the field record.product_tmpl_id required an .id to make the search function work? I didn't think of that because the command is comparing values the from the very same field, isn't it? Thanks in advance

It seems that record.product_tmpl_id is a kind of many2one field and when we are going to serach for many2one field we need to pass the id.

Author

Oh, I didn't know that.. Thanks a lot

Best Answer

Hi,

Change this

registros = env['product.supplierinfo'].search([('product_tmpl_id','=',product.id)],order="sequence )

Aswini iWesabe 
Avatar
Discard