Skip to Content
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1517 Представления

Hello, 

I want raise a warning via a wizard in the create function and continue with the transaction when the proceed button is clicked.
What am I missing?


Here is my code which checks whether the overdraft account limit has been exceeded, raises a message/warning and allows a transaction to continue.


@api.model
def create(self, vals):
credit = 0
debit = 0
if "line_ids" in vals.keys():
for line in vals['line_ids']:
if line[2]['credit']:
account = self.env['account.account'].browse(line[2]['account_id'])
account_lines = self.env['account.move.line'].search([('account_id', '=', account.id)])
for lines in account_lines:
credit += lines.credit
debit += lines.debit
new_account_credit_limit = (credit + line[2]['credit'] - debit)
if account.account_credit_limit:
if new_account_credit_limit > account.account_credit_limit:
try:
wizrd_action_id = self.env.ref('overdraft_limit.view_warning_wizard_form')
msg = 'Making this transaction will exceed the Overdraft limit defined for " %s " account.' % account.name
raise RedirectWarning(msg, wizrd_action_id.id, _('Are sure you want to proceed?'), {'active_id': self.id, })
finally:
account.account_credit_limit = new_account_credit_limit
self.state = 'posted'

result = super(AccountMove, self).create(vals)
return result




Аватар
Отменить
Related Posts Ответы Просмотры Активность
0
февр. 24
1269
1
февр. 24
3517
0
июл. 23
1469
1
июн. 23
2694
1
апр. 23
128