Odoo Help


Add method on invoice validation workflow - Odoo 8

Alejandro Perez Cosio
on 12/4/14, 5:51 PM 4,250 views


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




| 6 5 7
Lodz, Poland

On 12/5/14, 8:03 AM

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)


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

Alejandro Perez Cosio
on 12/5/14, 5:41 PM

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?

Alejandro Perez Cosio
on 12/5/14, 5:46 PM

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

on 12/5/14, 6:10 PM

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

Alejandro Perez Cosio
on 12/5/14, 6:22 PM

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__)

on 12/5/14, 6:28 PM

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

Alejandro Perez Cosio
on 12/5/14, 6:45 PM

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):
            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)

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 12/4/14, 5:51 PM
Seen: 4250 times
Last updated: 8/10/15, 1:20 PM