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

i have created a sheduale action with this function

for rec in records:
quant_obj = rec.env['stock.quant']
hq_location = rec.env.ref('stock.stock_location_stock')
quant_qty_available = quant_obj._get_available_quantity(rec, hq_location)
if rec.website_block:
    rec.write({'is_published': False})
elif rec.inventory_availability == 'never':
    rec.write({'is_published': True})
else:
    if quant_qty_available <= rec.available_threshold:
        rec.write({'is_published': False})
    else:
        rec.write({'is_published': True})

it is supposed to check availability in main location and unpublish if not available.


it doent work when i try to run it manually in scheduled action screen but it work perfectly if i changed it to server action and activate it from action button,


Does any one know what am doing wrong?

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

kindly share the erro log

Лучший ответ

Hello Mohamed,

Hope you are doing well.

Here, the records contains empty object so the loop doesn't iterate. You can use records.search([]) for fetching records and then iterate loop.

records = records.search([])
for rec in records:
quant_obj = rec.env['stock.quant']
hq_location = rec.env.ref('stock.stock_location_stock')
quant_qty_available = quant_obj._get_available_quantity(rec, hq_location)
if rec.website_block:
rec.write({'is_published': False})
elif rec.inventory_availability == 'never':
rec.write({'is_published': True})
else:
if quant_qty_available <= rec.available_threshold:
rec.write({'is_published': False})
else:
rec.write({'is_published': True})

Thanks & Regards,

Email: odoo@aktivsoftware.com

Skype: kalpeshmaheshwari

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
мая 15
9364
1
авг. 22
7487
5
июн. 25
189
1
июн. 25
604
1
мая 25
734