İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
4405 Görünümler

Origianl code :

class Inventory(models.Model):
_name = "stock.inventory"
_description = "Inventory"
_order = "date desc, id desc"

@api.model
def _default_location_id(self):
company_user = self.env.user.company_id
warehouse = self.env['stock.warehouse'].search([('company_id', '=', company_user.id)], limit=1)
if warehouse:
return warehouse.lot_stock_id.id
else:
raise UserError(_('You must define a warehouse for the company: %s.') % (company_user.name,))

My overriding :

class Inventory(models.Model):
_inherit = 'stock.inventory'

print("test")
@api.model
def _default_location_id(self):
print("pass")
res = super(Inventory, self)._default_location_id()
if self.env.user.context_default_warehouse_id:
res['location_id'] = self.env.user.context_default_warehouse_id.\
lot_stock_id.id
return res

I don't understand why it didn't work !

Avatar
Vazgeç
En İyi Yanıt

As you can see in original _default_location_id method, it's not returned any value and in your code you call super method and set it to res and that's why it's not working, try to use self.update

Please try the below:

@api.model
def _default_location_id(self):
    super(Inventory, self)._default_location_id()
    if self.env.user.context_default_warehouse_id:
        self.update({'location_id': self.env.user.context_default_warehouse_id.lot_stock_id.id})
Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Ağu 24
155
0
Oca 22
3429
0
Mar 15
3605
2
Mar 15
4035
0
Ağu 24
859