Skip to Content
Menu
This question has been flagged
4 Replies
2973 Views

I would like to setup a job to auto unpublish a product from ecommerce if the available stock is zero. 

I tried to write the below code, but it gave error. Can you help what is wrong? Thanks

for record in records:
  if record.qty_available == 0:
  record.website_published = false
  break;

I have updated with False (big F), the error message that is shown is:

forbidden opcode(s) in "# Available variables:\n# - env: Odoo Environment on which the action is triggered\n# - model: Odoo Model of the record on which the action is triggered; is a void recordset\n# - record: record on which the action is triggered; may be be void\n# - records: recordset of all records on which the action is triggered in multi-mode; may be void\n# - time, datetime, dateutil, timezone: useful Python libraries\n# - log: log(message, level='info'): logging function to record debug information in ir.logging table\n# - Warning: Warning Exception to use with raise\n# To return an action, assign: action = {...}\nfor record in records:\n if record.qty_available == 0:\n record.website_published = False\n break;": STORE_ATTR


Avatar
Discard

can you update the question with the error message that you are getting

Best Answer

Hi,

You can try the below code,

products = env['product.product'].search([])
for prod in products:
   if .qty_available == 0:
       prod.write({'website_published': False})


Thanks


Avatar
Discard
Best Answer

For flexible and instantaneous solution, cron job may not be the best solution as you have to wait for some hours (depending on frequency) for it to kick in; and may have to manually handle some tasks.

A more flexible approach will be to include ('qty_available','>',0) in the domain when the website products are being fetched.

For more perfection, this module

 seems to handle your feature with more flexibility.

Avatar
Discard
Best Answer

for record in records:
  if record.qty_available == 0:
  record.website_published = False
  break;


Avatar
Discard
Author Best Answer

hi Haresh, I have tried, but I still find error message like below:

forbidden opcode(s) in "# Available variables:\n# - env: Odoo Environment on which the action is triggered\n# - model: Odoo Model of the record on which the action is triggered; is a void recordset\n# - record: record on which the action is triggered; may be be void\n# - records: recordset of all records on which the action is triggered in multi-mode; may be void\n# - time, datetime, dateutil, timezone: useful Python libraries\n# - log: log(message, level='info'): logging function to record debug information in ir.logging table\n# - Warning: Warning Exception to use with raise\n# To return an action, assign: action = {...}\nfor record in records:\n if record.qty_available == 0:\n record.website_published = False\n break;": STORE_ATTR

Avatar
Discard