Hi,
I am trying to validate credit limit of customer when click on Confirm button in sale.order view
A warning is showed when self.amount_total > partner.credit_limit * 80%, however it is not block the working flow
Here is my source code
@api.one
def show_credit_warning(self, total, credit_limit):
if total > credit_limit * 0.8:
message = _('Message content')
warning_mess = {
'title': _('Credit limit is over 80%!'),
'message': message
}
return {'warning': warning_mess}
return {}
@api.multi
def action_confirm(self):
self.ensure_one()
# Check credit limit
partner = self.partner_id
if self.amount_total > partner.credit_limit:
# Block when over 100%
raise exceptions.ValidationError(
_('Credit Limit Exceeded! You need to increase the credit limit of this customer to proceed'))
else:
# Show warning when over 80% credit limit
# TODO: Not work, display nothing here
self.show_credit_warning(self.amount_total, partner.credit_limit)
res = super(SaleOrder, self).action_confirm()
return res
Thank you for your help!