This question has been flagged
8 Replies
7814 Views

Hello, 

I need to add some auto-calculated values to the invoice when the user validates it but I'm not sure how to embed my 'custom_module' which has the news fields and methods in the invoice workflow from the code.

I found that account_invoice_workflow.xml calls action_date_assign(), action_move_create(), action_number(), invoice_validate() which changes some values which I need to calculate my new fields.

So, basically I need to overwite the invoices workflow to add my set_new_values() method from my custom module when the user presses the validate button. Do you know how can I do that?

Thank you for your time and responses.

Best regards
Alejandro

 

Avatar
Discard
Best Answer

You inherit, in your module, class account_invoice, like this:

class account_invoice(osv.osv):
    _inherit = 'account.invoice'
    
    def set_new_values(self, cr, uid, ids, context=None):
        ....
        return ...
    
    def invoice_validate(self, cr, uid, ids, context=None):
        self.set_new_values(cr, uid, ids, context=context)
        return super(account_invoice,self).invoice_validate(cr, uid, ids, context=context)

 

or like this, dependent on what is to be first
        
        
    def invoice_validate(self, cr, uid, ids, context=None):
        super(account_invoice,self).invoice_validate(cr, uid, ids, context=context)
        return self.set_new_values(cr, uid, ids, context=context)
        

 

Avatar
Discard
Author

Hello zbik, I tried with your code with a "print '>>>>UPDATE VALUES

Author

Sorry, the last comment was wrongly posted. I got the following python error: global name 'account_invoice' is not defined. Which should be the value for account_invoice?

Hmmm, strange. You have, in your module, in __openerp__.py: 'depends': [ 'account' ],

Author

Yes, I have account as a dependency, do you know how to import that class into my custom module?

My class header: import time import openerp.addons.decimal_precision as dp from openerp import models, fields, api, _ from openerp.osv import fields, osv import openerp.exceptions import logging _logger = logging.getLogger(__name__)

Author

I solved it.. I was wrongly referencing another class.. Thank you to be patient zbit! your response worked for me

Best Answer


Try this

This code works for us :)

def invoice_validate(self, cr, uid, ids, context=None):
    for invoice in self.browse(cr, uid, ids, context=context):
        try:
            if not invoice.custom_field:
                raise openerp.exceptions.Warning("Custom error")
        except ValueError:
            raise openerp.exceptions.Warning("Custom")
    super(account_invoice,self).invoice_validate(cr, uid, ids, context=context)

Avatar
Discard