Search code examples
odoo-8

How can i combine warning message and update value at the same time inside of action button (odoo 8)


my question is how to update the field until action button

Here's my code

if self.partner_id.credit_limit != 0.00 and self.is_checked == True:
        if self.amount_total > available_credit:
            self.write({'state_block':2})
            msg = 'La commande ne peut pas être confirmée, le client a atteint sa limite de crédit.\
             La commande ne peut être confirmée que suite à  un payment ou dérogation par le responsable commerciale,\
             Merci d"informer le responsable commerciale'
            raise Warning(_(msg))
            return False
        else:
            return True

Solution

  • You can raise warning when the user clicks the button (Front-end), using the confirm attribute. In this case you can't do calculations and the warning is always raised.

    check this question

    But

    if you need to do some calculations and decide if a warning should be raised or not, you must use a Wizard, your workflow should be as following:

    1. User clicks the action button and call the validation method
    2. The validation method does the calculations and make the decision, if warning required go to (3) otherwise go to (4)
    3. a warning wizard is returned, the user will decide to cancel his/her request or continue. if user click the confirm button go to (4), otherwise go to (5)
    4. proceed with user request (call the actual method that do the business).
    5. do the cleaning job if required and exit

    Also check this question