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

Override status in a class

By
Anders Wallenquist
on 8/22/14, 3:24 AM 1,428 views

I want to add a new status to account,invoice - class. I have done this by a new module with a class that inherit from accounnt.invoice and redefine the state-column:

class account_invoice(osv.osv):
    _inherit = "account.invoice"
    _columns = {

        'state': fields.selection([
            ('draft','Draft'),
            ('submitted','Submitted'),
            ('proforma','Pro-forma'),
            ('proforma2','Pro-forma'),
            ('open','Open'),
            ('paid','Paid'),
            ('cancel','Cancelled'),
            ],'Status', select=True, readonly=True, track_visibility='onchange',
            help=' * The \'Draft\' status is used when a user is encoding a new and unconfirmed Invoice. \
            \n* The \'Submitted\' when invoice is in submitted status,invoice does not have an invoice number and waits for approval. \
            \n* The \'Pro-forma\' when invoice is in Pro-forma status,invoice does not have an invoice number. \
            \n* The \'Open\' status is used when user create invoice,a invoice number is generated.Its in open status till user does not pay invoice. \
            \n* The \'Paid\' status is set automatically when the invoice is paid. Its related journal entries may or may not be reconciled. \
            \n* The \'Cancelled\' status is used when user cancel invoice.'),
    }

 

    def invoice_submitted(self, cr, uid, ids, context=None,):
        for inv in self.browse(cr, uid, ids, context=context):
            self.pool.get('account.invoice').write(cr, uid, [inv.id], {'status': 'submitted'})
        return True

 

This works sometimes and sometimes not when I install the module in a fresh database. I have in other modules created a function that returns a list to the fields.selection and used inheritance to override that list. What is best practice?

 

 

Can you explain more the situation where this doesn't work?

IBS
on 8/23/14, 10:24 AM

There are two problems a) when I create a new database and install my module it does not add the new status "submitted" every time - maybe it depends on what order I install the modules b) If there are more than one module that want to add status stages to the same term the last one will overwrite additions that other modules has done.

Anders Wallenquist
on 8/24/14, 10:23 AM

"I have in other modules created a function that returns a list to the fields.selection and used inheritance to override that list.". This is a really good way to do this ! About your problem, you should maybe try to check if another module also overrides the state field?

Cyril Sester
on 8/25/14, 3:32 AM

Add all the modules that override the state field to your module's dependencies list and see if this resolves the problem.

IBS
on 8/27/14, 12:17 PM

I have done a dependency to account in __openerp__.py. I also corrected the error in the invoice_submitted method (status -> state). But I still got an error, that state does not have the state submited.

Anders Wallenquist
on 8/27/14, 4:39 PM

There must be another module modifying the state, add it to the dependency list.

IBS
on 8/27/14, 5:03 PM
1
Anders Wallenquist
On 8/29/14, 11:21 AM

I found the problem, the new account_invoice-class are a models.Model, not osv.osv:

class account_invoice(models.Model):
    _inherit = "account.invoice"
    
    
    state = fields.Selection([
            ('draft','Draft'),
            ('submitted','Submitted'),
            ('proforma','Pro-forma'),
            ('proforma2','Pro-forma'),
            ('open','Open'),
            ('paid','Paid'),
            ('cancel','Cancelled'),
        ], string='Status', index=True, readonly=True, default='draft',
        track_visibility='onchange', copy=False,
        help=" * The 'Draft' status is used when a user is encoding a new and unconfirmed Invoice.\n"
             " * The 'Submitted' status when invoice is in submitted status,invoice does not have an invoice number and waits for approval. \n"
             " * The 'Pro-forma' when invoice is in Pro-forma status,invoice does not have an invoice number.\n"
             " * The 'Open' status is used when user create invoice,a invoice number is generated.Its in open status till user does not pay invoice.\n"
             " * The 'Paid' status is set automatically when the invoice is paid. Its related journal entries may or may not be reconciled.\n"
             " * The 'Cancelled' status is used when user cancel invoice.")

Now it works!

 

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

2 follower(s)

Stats

Asked: 8/22/14, 3:24 AM
Seen: 1428 times
Last updated: 3/16/15, 8:10 AM