我的代码如下
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.\u display”“slot”“check()”
如何克服属性env not found错误的错误
堆栈跟踪:
^{pr2}$
我认为你犯了个错误。您的模型名是
slotcheck
,但您将对book_meeting
数据库执行select sum(units) from book_meeting where company_name=%s and end_time>=%s and end_time<=%s
查询如果您正在对来自不同模型的模型执行查询,请不要使用
只使用
相关问题 更多 >
编程相关推荐