0

My code is as follows

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

It is giving error as : slotcheck object has no attribute env while evaluating u'self._display_slot_check()' in line 41

How can i overcome this error of attribute 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()'
5
  • Please post your stacktrace too. Commented Apr 4, 2016 at 11:11
  • @ Muhammed Tahir, Added stacktrace Commented Apr 4, 2016 at 11:21
  • Try @api.model decorater with your def _display_slot_check(self): method. Commented Apr 4, 2016 at 11:26
  • @MuhammadTahir When i added the decorator it is giving error as old_api needs 3 argument but 1 given Commented Apr 4, 2016 at 12:13
  • Add Decorator @api.multi Commented Apr 5, 2016 at 5:16

1 Answer 1

1

I think you have done an error. Your model name is slotcheck but you are executing query on book_meeting database as select sum(units) from book_meeting where company_name=%s and end_time>=%s and end_time<=%s

If you are executing a query on a model from a different model don't use

self._cr.execute()

instead use only

cr.execute()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.