Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Function calling on button click in OpenERP

    • 0
    • 4
    • 4
    • 1
    • 0
    • 0
    • 0
    • 0
    • 3.45k
    Comment on it

    Adding a button on an OpenERP view is very easy and calling a function on it too. For example I created a function to add cartage amount on the sales order, I created a field to add cartage amount on it and then on button click it will be added to the total amount of the invoice. Lets see how:

    Create a function

    1. def get_cartage(self, cr, uid, ids, invoice_id, context=None):
    2. res = {}
    3. acc_id = 39
    4. name = 'Cartage'
    5. amount = 0.0
    6. quantity = 1
    7. disc = 0.00
    8. val = 'TRUE'
    9. order = self.pool.get('sale.order')
    10. line = self.pool.get('account.invoice.line')
    11. for invoice in self.browse(cr,uid,ids):
    12. if invoice.cflag is False:
    13. amount = invoice.cartage
    14. if amount == 0.0:
    15. raise osv.except_osv(_('No Value !')_('You must add cartage'))
    16. if amount > 0.0:
    17. cr.execute('insert into account_invoice_line (invoice_id,name,account_id,origin,price_unit,quantity,discount,partner_id,uos_id,price_subtotal,company_id) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',(invoice.id,name,acc_id,invoice.origin,amount,quantity,disc,invoice.partner_id.id,quantity,amount,invoice.company_id.id))
    18. cr.execute('update account_invoice set cflag = %s where id = %s',(val,invoice.id))
    19. if invoice.cflag is True and invoice.cartage > 0.0:
    20. raise osv.except_osv(_('Message'),_('Cartage already added'))
    21. #raise osv.except_osv(_('No Value !'),_(str(invoice.cflag)))
    22. return res

    Add a button in view

    1. <button name="get_cartage" string="Add Cartage" type="object" />

    Note the name attribute, I used name of the function to be called and type as object. This is all you have to do for a function call on a button.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: