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

Hi everyone!


I'm coding a server action to check the available quantity of the products before booking them!

I want this server action be launched only when the user is going to save or confirm the order and not when he wants to cancel it. Could you help please?

  produit = env['product.product'].search([('default_code', '=', record.product_id.default_code)])

  if record.product_uom_qty > record.product_id.immediately_usable_qty:

    if action != model.action_cancel() or action != model.action_create_reservation():

      raise Warning(str(record.product_id.default_code) + ": Seulement " + str(record.product_id.immediately_usable_qty) + " en stock!")



Аватар
Отменить
Лучший ответ

Hi,
In this case you don’t need to write a server action. You can simply do the same thing using @api.constrains() decorator. It will trigger while save the record and you can check the conditions whatever you want and also raise a Warning.

@api.constrains('field_1', 'field2')
def _check_sequence(self):
produit = self.env['product.product'].search([('default_code', '=', record.product_id.default_code)])
if record.product_uom_qty > record.product_id.immediately_usable_qty:
raise Warning(str(record.product_id.default_code) + ": Seulement " + str(
record.product_id.immediately_usable_qty) + " en stock!")
Regards


Аватар
Отменить
Related Posts Ответы Просмотры Активность
4
июн. 20
4159
2
февр. 25
4567
3
июн. 25
2306
2
авг. 24
1398
0
янв. 25
1251