def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): """ Override to set the `inventory_quantity` field if we're in "inventory mode" as well as to compute the sum of the `available_quantity` field. """ if 'available_quantity' in fields: if 'quantity' not in fields: fields.append('quantity') if 'reserved_quantity' not in fields: fields.append('reserved_quantity') result = super(StockQuant, self).read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy) for group in result: if self._is_inventory_mode(): group['inventory_quantity'] = group.get('quantity', 0) if 'available_quantity' in fields: group['available_quantity'] = group['quantity'] - group[ 'reserved_quantity'] return result
def _sms_get_partner_fields(self): """ This method returns the fields to use to find the contact to link whensending an SMS. Having partner is not necessary, having only phone number fields is possible. However it gives more flexibility to notifications management when having partners. """ fields = [] if hasattr(self, 'partner_id'): fields.append('partner_id') if hasattr(self, 'partner_ids'): fields.append('partner_ids') return fields
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): if all('on_time_rate' not in field for field in fields): res = super().read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy) return res for field in fields: if 'on_time_rate' not in field: continue fields.remove(field) agg = field.split(':')[1:] if agg and agg[0] != 'sum': raise NotImplementedError( 'Aggregate functions other than \':sum\' are not allowed.') qty_total = field.replace('on_time_rate', 'qty_total') if qty_total not in fields: fields.append(qty_total) qty_on_time = field.replace('on_time_rate', 'qty_on_time') if qty_on_time not in fields: fields.append(qty_on_time) break res = super().read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy) for group in res: if group['qty_total'] == 0: on_time_rate = 100 else: on_time_rate = group['qty_on_time'] / group['qty_total'] * 100 group.update({'on_time_rate': on_time_rate}) return res
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): if 'on_time_rate' not in fields: res = super().read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy) return res fields.remove('on_time_rate') if 'qty_total' not in fields: fields.append('qty_total') if 'qty_on_time' not in fields: fields.append('qty_on_time') res = super().read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy) for group in res: if group['qty_total'] == 0: on_time_rate = 100 else: on_time_rate = group['qty_on_time'] / group['qty_total'] * 100 group.update({'on_time_rate': on_time_rate}) return res