Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1522 Visualizzazioni

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




Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
feb 24
1275
1
feb 24
3524
0
lug 23
1471
1
giu 23
2706
1
apr 23
128