在执行查询时,对象在odoo中没有属性env错误

时间:2016-04-04 11:08:10

标签: python odoo-8

我的代码如下

class slotcheck(models.Model):
_name = 'slotcheck'
_inherit = ['book.meeting']
_rec_name = 'display_total'


unit_exceed = fields.Boolean('Exceeded limit',default=False)
addnl_usage = fields.Integer('Additional usage')
display_total = fields.Integer(string='Dispaly total usage', compute='_display_slot_check')
current_company = fields.Many2one('res.company','Enter your company name')

_defaults = {

    'current_company': lambda obj, cr, uid, context: uid,

}



def _display_slot_check(self):
    _logger = logging.getLogger(__name__)
    _logger.info('#######################coming here ###########')
    currentMonth = datetime.now().month
    currentYear = datetime.now().year
    first_day = datetime(currentYear, currentMonth, 1)
    num_days = calendar.monthrange(currentYear, currentMonth)
    last_day = datetime(currentYear, currentMonth, num_days[1])
    conv_date = ((last_day.strftime('%Y-%m-%d'))+' '+'23:59:59')
    query = "select sum(units) from book_meeting where company_name=%s and end_time>=%s and end_time<=%s " #line 41

    rows_count=self._cr.execute(query,(self.current_company.id,first_day,conv_date))
    data1=self._cr.fetchall()
    for row in data1:
        total = row
    monthly = total[0]
    _logger.info('#######################coming here ###########')
    self.display_total = monthly

它给出了错误:slotcheck对象在评估时没有属性env         你在第41行的'self._display_slot_check()'

如何克服属性env not found error

的错误

Stacktrace:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\http.py", line 537, in _handle_exception
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\http.py", line 574, in dispatch
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\http.py", line 310, in _call_function
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\service\model.py", line 118, in wrapper
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\http.py", line 307, in checked_call
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\http.py", line 803, in __call__
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\http.py", line 403, in response_wrap
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\openerp\addons\web\controllers\main.py", line 1255, in run
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\http.py", line 908, in proxy
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\api.py", line 250, in wrapper
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\openerp\addons\base\ir\ir_actions.py", line 1002, in run
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\api.py", line 250, in wrapper
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\openerp\addons\base\ir\ir_actions.py", line 836, in run_action_code_multi
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\tools\safe_eval.py", line 314, in safe_eval
  File "", line 1, in <module>
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\openerp\addons\stpi\models\slot_manage.py", line 39, in _display_slot_check
  File "C:\Program Files (x86)\Odoo 8.0-20151015\server\.\openerp\models.py", line 5289, in <lambda>
ValueError: "'slotcheck' object has no attribute 'env'" while evaluating
u'self._display_slot_check()'

1 个答案:

答案 0 :(得分:1)

我认为你做错了。您的模型名称为slotcheck,但您正在book_meeting数据库上执行查询select sum(units) from book_meeting where company_name=%s and end_time>=%s and end_time<=%s

如果您正在使用其他型号对模型执行查询请勿使用

  

self._cr.execute()

而只使用

  

cr.execute()