def _partner_use_in(self, aggr_ids, models): """ Check if there is no occurence of this group of partner in the selected model :param aggr_ids : stringified list of partner ids separated with a comma (sql array_agg) :param models : dict mapping a model name with its foreign key with res_partner table """ return any(self.env[model].search_count([(field, 'in', aggr_ids)]) for model, field in models.items())
def _partner_use_in(self, aggr_ids, models): """ Check if there is no occurence of this group of partner in the selected model :param aggr_ids : stringified list of partner ids separated with a comma (sql array_agg) :param models : dict mapping a model name with its foreign key with res_partner table """ return any( self.env[model].search_count([(field, 'in', aggr_ids)]) for model, field in models.items() )
def process_data(self): if not self.env['enotif.settings'].get('process_notifications'): return models = {} type_by_id = {} records = self.search([], order='priority,type_id,item_id desc', limit=MAX_NUMBER_OF_RECORDS_TO_PROCESS) for r in records: models.setdefault(r.type_id.model_id.model, []).append({'type_id': r.type_id.id, 'item_id': r.item_id}) type_by_id[r.type_id.id] = r.type_id.type start_time = time.time() for m_name, items in models.items(): Model = self.env[m_name] types = {} for item in items: types.setdefault(item['type_id'], []).append(item['item_id']) for type_id, item_ids in types.items(): notification_type = type_by_id[type_id] end_time = time.time() if end_time - start_time > MAX_EXECUTION_TIME: break try: processed_ids = Model.process_notifications(notification_type, item_ids) self.delete_processed_notifications(type_id, processed_ids); except Exception as e: _logger.error("ERROR: External Notifications module cannot pocess notifications for type: %s \n item_ids: %s \n error text: %s", notification_type, item_ids, format_exception_only(type(e), e)) else: continue break