Skip to Content
Menu
This question has been flagged

Hello Every one...

In Odoo 8 , Expense I have a field Budget whose value is coming from onchange, now what I want is when amount i.e total expense exceeds budget amount it should throw popup and that entry should not be saved.

I have created a update button like in purchase or sale module and on if condition its showing popup. But ALL I want is how to disallow save of that entry. i.e. exceeding amount entry should not be saved. when user click on update button and if condition is true it create popup but after clicking popup ok it allows to save form.

Thanks in advance....

Avatar
Discard

You can super the create function of the model to do this. or you can do it by giving constrains

Author Best Answer

There is no create or write function in hr_expense_expense(osv.osv) in odoo 8. But only function I think that can do needfull is as below , but how to call that before save button click.

def _amount(self, cr, uid, ids, field_name, arg, context=None):
        res= {}
        for expense in self.browse(cr, uid, ids, context=context):
            total = 0.0
            for line in expense.line_ids:
                total += line.unit_amount * line.unit_quantity
            res[expense.id] = total
        return res

Avatar
Discard
Best Answer

Override the write method of that particular model and check for the condition

@api.multi

def write(self)
for rec in self:
if rec.budget > "budget":

     raise Warning(_('budget is exceded !'))
else:

return super(name_of_your_model, self).write(vals)
Avatar
Discard
Related Posts Replies Views Activity
3
Jul 17
2746
0
Jan 24
439
1
Feb 21
3788
4
Dec 19
13414
0
Dec 18
13