Kenly
Kenly

Reputation: 26708

How can I create and access instance variables in odoo models

My code is:

class way_bill(osv.osv):
    _name = "way_bill"
    ....
    def method1(...):
       self.ID = self.get_id_invoice_id(...)

    def method2(...):
        for item self.browse(cr, uid, self.ID, context=context):
        ....

When I try to access self.ID form method2, it raises an error.

How can I store and use self.ID?

Upvotes: 0

Views: 1053

Answers (1)

Juan Salcedo
Juan Salcedo

Reputation: 1668

First: which version are you using for coding? .v7 or .v8?

If ID is an Integer, in .v8 you can use a decorator @depends shomething like this:

@api.depends('ID')
def method2(self):
    for item self.browse(self.ID):
    ...

I hope this can be helpful for you.

EDIT

In .v7 it should be something like this:

def method1(...):
    return { 'values': { 'ID': self.get_id_invoice_id(...)}}

def method2(...):        
    record = self.browse(cr, uid, ids[0], context=context)        
    obj_inv = self.browse(cr, uid, record.ID, context=context)        
    ...

I don't know what ID are you locking for, even how you do that in get_id_invoice_id, but if you apply the changes, it should br work perfectly...

Upvotes: 1

Related Questions