Odoo Help


Action before print invoice [Closed]

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

The Question has been closed

Sudhir Arya (ERP Harbor Consulting Services)
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 (ERP Harbor Consulting Services)

--Sudhir Arya (ERP Harbor Consulting Services)--
| 6 8 8
Ahmedabad, India
--Sudhir Arya (ERP Harbor Consulting Services)--

• Co-Founder & Co-Owner at ERP Harbor Consulting Services

• ERP Consultant / ERP Customization / TechnoFunctional Expert

• Sound knowledge in Python, Odoo (Open ERP), XML, PostgreSQL

• Domain knowledge of Sale Management, Purchase Management, Warehouse Management, Manufacturing, Multi Company Configuration & Management, HR Management, Medical Management, Construction Management, Education Management, Point of Sale, Third Party Integrations

• Positive attitude and quick Learner

• Good analytical skill, quick bug and issue tracing and find the solution

• Good knowledge and experience in payment gateway integration with Odoo

• Ready to accept new challenges

• Active Memeber On Stackoverflow 




Sudhir Arya
ERP Harbor Consulting Services
Sudhir Arya (ERP Harbor Consulting Services)
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: 2426 times
Last updated: 3/16/15, 8:10 AM