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.

1

Action before print invoice [Closed]

By
klacus
on 4/28/13, 11:21 PM 1,753 views

The Question has been closed

by
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.

1

Sudhir Arya (SA)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

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)
    self.localcontext.update({
        '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!

klacus
on 4/29/13, 2:30 AM

About This Community

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

Question tools

0 follower(s)

Stats

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