This question has been flagged
1 Reply
9393 Views

Hello all,

I'm in odoo 8.

I have inherited the stock.quant model with new api code.

When I call the get_warehouse method (old api) defined in model stock.location, I get an error.

How should I call this method?


My code :

from openerp import models, fields, api, _

class stock_Quant(models.Model):
    _inherit = 'stock.quant'
       
    warehouse_id = fields.Many2one(compute='get_warehouse_id', comodel_name='stock.warehouse', string='Warehouse of this quant', readonly=True, store=True)
       
    @api.one
    @api.depends('location_id')
    def get_warehouse_id(self):
        location_obj = self.env['stock.location']
        for quant in self.browse(self.ids):
            the_warehouse = location_obj.get_warehouse(self._cr, self._uid, quant.location_id, context=self._context)
        self.warehouse_id = the_warehouse


I get this error :

TypeError: get_warehouse() takes at most 5 arguments (7 given)



Avatar
Discard
Best Answer

You could do it like this:

from openerp import models, fields, api, _
class stock_Quant(models.Model):
    _inherit = 'stock.quant'
    warehouse_id = fields.Many2one(compute='get_warehouse_id', comodel_name='stock.warehouse', string='Warehouse of this quant', readonly=True, store=True)

    @api.one
    @api.depends('location_id')
    def get_warehouse_id(self):
        for quant in self:
            quant.warehouse_id = self.env['stock.location'].get_warehouse(quant.location_id)

The idea in the new api is to be able to call methods on a recordset browse objects, maybe the .id part is not needed or the method returns a list just test it

#Edited:

As pointed here:

https://www.odoo.com/documentation/8.0/reference/orm.html#reference-orm-oldapi

You could call old api methods using new api call style and they will be bridged

Avatar
Discard
Author

Thanks Axel.

I now get error : "TypeError: get_warehouse() takes at least 4 arguments (4 given)"

Weird error!

Author

This line worked for me instead : quant.warehouse_id = quant.location_id.get_warehouse(quant.location_id)

May be you want to correct your answer? Do you agree? THank for your help.

then this should be better

quant.warehouse_id = self.env['stock.location'].get_warehouse(quant.location_id)