Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
8 Odpovědi
9027 Zobrazení

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

 

Avatar
Zrušit
Nejlepší odpověď

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)
        

 

Avatar
Zrušit
Autor

Hello zbik, I tried with your code with a "print '>>>>UPDATE VALUES

Autor

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?

Hmmm, strange. You have, in your module, in __openerp__.py: 'depends': [ 'account' ],

Autor

Yes, I have account as a dependency, do you know how to import that class into my custom module?

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

Autor

I solved it.. I was wrongly referencing another class.. Thank you to be patient zbit! your response worked for me

Nejlepší odpověď


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)

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
zář 17
5592
1
čvn 16
4081
0
bře 15
5825
9
bře 17
10161
1
bře 15
4681