Odoo Help

Welcome!

This community 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.

0

Add method on invoice validation workflow - Odoo 8

By
Alejandro Perez Cosio
on 12/4/14, 5:51 PM 2,656 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

 

1

zbik

--zbik--
5976
| 6 4 7
Lodz, Poland
--zbik--


zbik
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' ],

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

zbik
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
0


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)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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