ok, so I've been stuck with this for a while now. I'm trying to create a current date field (date_added) in model stock.location.lock.code.rel (which is a relational model for stock.location.lock.code and stock.location models). My problem is that the table and field gets created in postgres db but its not getting populated and I'm getting error (mentioned below code). My code is below (I'm a beginner in odoo, so please do suggest correct way of doing)
in stock.location class :
class StockLocation(models.Model):
_name = 'stock.location'
_inherit = 'stock.location'
@api.multi
def write(self, vals):
#I've overriden this method because I need to edit a form view and this method will be called when I press save button
now = datetime.now()
current_time = now.strftime('%m/%d/%Y %H:%M:%S')
vals = ({'date_added': current_time, 'active': True})
http.request.env['stock.location.lock.codes.rel'].create(vals)
return super(StockLocation, self).write(vals)
level = fields.Char('Level', size=1, default=None)
position = fields.Char('Position', size=1, default=None)
lock_code_ids = fields.Many2many('stock.location.lock.codes','stock_location_lock_code_rel','location_ids','lock_code_ids','Lock Code to apply', ondelete="cascade", default=None)
not_on_hand = fields.Boolean('not_on_hand', readonly=True, default=False)
class StockLocationLockCodeRel(models.Model):
_name = "stock.location.lock.code.rel"
location_ids = fields.Many2one('stock.location', 'Lock code location', required=True, ondelete="cascade")
lock_code_ids = fields.Many2one('stock.location.lock.codes', 'Lock code', required=True, ondelete="cascade")
active = fields.Boolean('Active', default=True)
date_added = fields.Datetime('Date Added')
id = fields.Char('id')
@api.multi
def create(self, vals):
return super(StockLocationLockCodeRel, self).create(vals)
Now my code for stock.location.lock.codes is :
from openerp import models, fields
class StockLocationLockCodes(models.Model):
_name = 'stock.location.lock.codes'
code = fields.Char('Code', size=2)
name = fields.Char('Name', size=100)
description = fields.Text('Description')
not_on_hand = fields.Boolean('On Hand', default=None)
unavailable = fields.Boolean('Available', default=None)
lock_in = fields.Boolean('Put', default=None)
lock_out = fields.Boolean('Pull', default=None)
active = fields.Boolean('Active', default=None)
show = fields.Boolean('Show in Location', default=None)
location_ids = fields.Many2many('stock.location','stock_location_lock_code_rel','lock_code_ids','location_ids','Lock code location', ondelete="cascade", default=None)
The error on logs is :
Traceback (most recent call last):
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 551, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 588, in dispatch
result = self._call_function(**self.params)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 324, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 321, in checked_call
return self.endpoint(*a, **kw)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 817, in __call__
return self.method(*args, **kw)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/http.py", line 417, in response_wrap
response = f(*args, **kw)
File "/home/rohitupadhyay/git/odoo-IC-32/addons/web/controllers/main.py", line 944, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/rohitupadhyay/git/odoo-IC-32/addons/web/controllers/main.py", line 936, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 399, in old_api
result = method(recs, *args, **kwargs)
File "/home/rohitupadhyay/git/odoo-IC-32/staples-addons/wms_stock/models/stock_location.py", line 167, in write
http.request.env['stock.location.lock.code.rel'].create(vals)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/home/rohitupadhyay/git/odoo-IC-32/staples-addons/wms_stock/models/stock_location.py", line 275, in create
return super(StockLocationLockCodeRel, self).create(vals)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/models.py", line 4094, in create
record = self.browse(self._create(old_vals))
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/api.py", line 508, in new_api
result = method(self._model, cr, uid, *args, **old_kwargs)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/models.py", line 4232, in _create
tuple([u[2] for u in updates if len(u) > 2])
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/sql_db.py", line 158, in wrapper
return f(self, *args, **kwargs)
File "/home/rohitupadhyay/git/odoo-IC-32/openerp/sql_db.py", line 234, in execute
res = self._obj.execute(query, params)
ProgrammingError: column "id" of relation "stock_location_lock_code_rel" does not exist
LINE 1: INSERT INTO "stock_location_lock_code_rel" ("id", "active", ...