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

Hello, In sale.order.line I have a set a warning message. It pop-ups when the stock level is less than the requested quantity of product in the sale order. The message works perfectly. But the problem is even if the user is warnned that there is not enough stock the order can be confirmed. This should not happen.the order must not get confirmed. How can I do this? Someone please help. this is my warning message code: It is written in def product_id_change

if (qty > product_obj.available_qty):
    warn_msg = _('You requested %.2f.The available stock is %.2f !') %(qty,product_obj.available_qty)
    warning_msgs += _("Not enough stock ! : ") + warn_msg +"\n\n"
Аватар
Отменить
Лучший ответ

If you really want to stop the flow, you have to override product_id_change and write osv.except_osv instead of warning.

For example:

raise osv.except_osv(_('Error!'),_("Your Warning/Error Message."))

It will stop the execution and won't allow to proceed further until you solve it.

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

i did this but the result was the exception raised succesfully but the products description field went blank. and when I filled the description the everything worked normally. the order got confirmed even if there is no stock

It is because onchange is called when you change either product or quantity. But you are changing description only then onchange won't work and exception won't raise.

Автор

so wat should i do now? Is there any way?

You can make product_id mandatory.

Автор

is there any way i can do it on the confirm button defenition?

Yes, you can check is there product_id or not, if not then you can raise exception "Please Select Product".

Автор Лучший ответ

Just add

def action_wait(self, cr, uid, ids, context=None):
context = context or {}
for order in self.browse(cr, uid, ids):
    if not order.order_line:
        raise osv.except_osv(_('Error!'),_('You cannot confirm a sales order which has no line.'))
    # Raising exception to inform the user about the stock level before confirming the sale order
    for product in order.order_line:
        if (product.product_uom_qty > product.product_id.available_qty):
            raise osv.except_osv(_('Not enough stock !'), _('You requested %.2f.The available stock is %s !') %(product.product_uom_qty, product.product_id.available_qty))

in sale.py. The def action_wait is already defined. just add the code to into it. My problem got solved.

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

You should create your custom module Instead of changing core modules.

Автор

Yeah i have inherited sale.order and sale.order.line to do this

where did you get the available_qty?? because i got the same problem..

Лучший ответ

There is a module called warning. Please check it

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

Warning messages can be displayed for objects like sale order, purchase order, picking and invoice. The message is triggered by the form's onchange event.

http://1tour.vn

http://1tour.vn/khach-san/

http://1tour.vn/tour/

http://tainghebeats.vn

http://thuocla-dientu.com

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
апр. 23
13285
0
дек. 21
2529
0
мар. 15
3613
1
янв. 25
3424
2
авг. 24
5853