kubaSpolsky
kubaSpolsky

Reputation: 357

attributeError: 'str' object has no attribute 'dbname'

I created a new modul to rewrite a _read_group_process_groupby method from server\openerp\modules.py and add group by hour option, but I get this error:

enter image description here

the method from my module \addons-custom\my_group_hours\models\models.py is the following

@api.model
def _read_group_process_groupby(self, gb, query, context):

   split = gb.split(':')
   field_type = self._fields[split[0]].type
   gb_function = split[1] if len(split) == 2 else None
   temporal = field_type in ('date', 'datetime')
   tz_convert = field_type == 'datetime' and context.get('tz') in pytz.all_timezones
   qualified_field = self._inherits_join_calc(self._table, split[0], query)
   if temporal:
       display_formats = {
           'hour': 'HH:mm dd MMM yyyy',
           'day': 'dd MMM yyyy',
           'week': "'W'w YYYY", 
           'month': 'MMMM yyyy',
           'quarter': 'QQQ yyyy',
           'year': 'yyyy',
       }
   time_intervals = {
       'hour': dateutil.relativedelta.relativedelta(hours=1),
       'day': dateutil.relativedelta.relativedelta(days=1),
       'week': datetime.timedelta(days=7),
       'month': dateutil.relativedelta.relativedelta(months=1),
       'quarter': dateutil.relativedelta.relativedelta(months=3),
       'year': dateutil.relativedelta.relativedelta(years=1)
   }
   if tz_convert:
           qualified_field = "timezone('%s', timezone('UTC',%s))" % (context.get('tz', 'UTC'), qualified_field)
       qualified_field = "date_trunc('%s', %s)" % (gb_function or 'month', qualified_field)
   if field_type == 'boolean':
       qualified_field = "coalesce(%s,false)" % qualified_field
   return {
       'field': split[0],
       'groupby': gb,
       'type': field_type,
       'display_format': display_formats[gb_function or 'month'] if temporal else None,
       'interval': time_intervals[gb_function or 'month'] if temporal else None,
       'tz_convert': tz_convert,
       'qualified_field': qualified_field
   }

models.BaseModel._read_group_process_groupby = _read_group_process_groupby

Upvotes: 0

Views: 1062

Answers (1)

Kenly
Kenly

Reputation: 26768

@api.model is used to expose a new-style method to the old API.

When your method is called, gb is passed as cr and it results in:

AttributeError: 'str' object has no attribute 'dbname'

You need just to remove the decorator.

Upvotes: 1

Related Questions