Odoo Help


Action before print invoice [Closed]

on 4/28/13, 11:21 PM 2,199 views

The Question has been closed

Sudhir Arya (SA)
on 05/01/2013 01:34:58

Hi All!

I want to run the following python code before the invoice is printed.

Def inv_chk(self, cr, uid, name, context):  
sz = '''inv_spec'''  
if name == sz:
        idk = context.get('active_id',False) 
        cr.execute('''SELECT printed FROM account_invoice WHERE id =  %s ''', (idk,))
        for item in cr.dictfetchall():
            if item['printed'] == 'printed':
                cr.execute('''Update account_invoice Set printed = 'copy' WHERE id = %s''', (idk,))
            if item['printed'] == 'Blank':                                     
                cr.execute('''Update account_invoice Set printed = 'master' WHERE id = %s''', idk)

Where can I put that? I try to put inside the account_print_invoice.py but this is cause some error.

The goal is to put the info about the printing history. Now simply is enough, that document is printed or not... Thanks in advance.

Sudhir Arya (SA)
On 4/29/13, 2:21 AM

You can put you code either in __init__ of the report parsing py like this:

class account_invoice(report_sxw.rml_parse):
    def __init__(self, cr, uid, name, context):
        #Your code goes here
        super(account_invoice, self).__init__(cr, uid, name, context=context)
        'time': time,

Or you can write your code in set_context method. For that first you have to define set_context method in report parsing py like this:

    def set_context(self, objects, data, ids, report_type=None):
        #Your code goes here
        return super(contribution_register_report, self).set_context(objects, data, ids, report_type=report_type)

See How to define .set_context

Thank you!

on 4/29/13, 2:30 AM

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

0 follower(s)


Asked: 4/28/13, 11:21 PM
Seen: 2199 times
Last updated: 3/16/15, 8:10 AM