def _compute_student_issue_ids(self): context = self.env.context for student in self: cond = [] school_id = context.get('school_id', student.current_center_id.id) schedule_id = context.get('education_schedule_id', False) # group_id = context.get('education_group_id', False) if school_id: classroom_site = self.env.ref( 'issue_education.classroom_school_issue_site') cond = [('affect_to', '=', 'student'), ('school_id', '=', school_id)] level_id = student.current_course_id.level_id level_cond = [("education_level_id", "=", False)] if level_id: level_cond = expression.OR([ [("education_level_id", "=", level_id.id)], level_cond]) cond = expression.AND([level_cond, cond]) if schedule_id and classroom_site: cond = expression.AND([ [('issue_type_id.site_id', '=', classroom_site.id)], cond]) issue_types = self.env['school.college.issue.type'] if cond: issue_types = issue_types.search(cond, order='sequence') student_issues = self.env['student.issue'] for issue_type in issue_types: student_issue_vals = { 'student_id': student.id, 'education_schedule_id': schedule_id, 'college_issue_type_id': issue_type.id, } student_issues |= student_issues.create(student_issue_vals) student.student_issue_ids = [(6, 0, student_issues.ids)]
def name_search(self, name="", args=None, operator="ilike", limit=100): # TODO maybe implement negative search operators, although # there is not really a use case for that domain = args or [] splitted_name = name.split(".", 2) name_search_domain = [] if "." in name: kpi_name, subkpi_name = splitted_name[0], splitted_name[1] name_search_domain = osv_expression.AND( [ name_search_domain, [ "|", "|", "&", ("kpi_id.name", "=", kpi_name), ("subkpi_id.name", operator, subkpi_name), ("kpi_id.description", operator, name), ("subkpi_id.description", operator, name), ], ] ) name_search_domain = osv_expression.OR( [ name_search_domain, [ "|", ("kpi_id.name", operator, name), ("kpi_id.description", operator, name), ], ] ) domain = osv_expression.AND([domain, name_search_domain]) return self.search(domain, limit=limit).name_get()
def name_search(self, name='', args=None, operator='ilike', limit=100): # TODO maybe implement negative search operators, although # there is not really a use case for that domain = args or [] splitted_name = name.split('.', 2) name_search_domain = [] if '.' in name: kpi_name, subkpi_name = splitted_name[0], splitted_name[1] name_search_domain = osv_expression.AND([ name_search_domain, [ '|', '|', '&', ('kpi_id.name', '=', kpi_name), ('subkpi_id.name', operator, subkpi_name), ('kpi_id.description', operator, name), ('subkpi_id.description', operator, name), ] ]) name_search_domain = osv_expression.OR([ name_search_domain, [ '|', ('kpi_id.name', operator, name), ('kpi_id.description', operator, name), ] ]) domain = osv_expression.AND([domain, name_search_domain]) return self.search(domain, limit=limit).name_get()
def get_aml_domain_for_expr(self, expr, date_from, date_to, target_move, account_id=None): """ Get a domain on account.move.line for an expression. Prerequisite: done_parsing() must have been invoked. Returns a domain that can be used to search on account.move.line. """ aml_domains = [] date_domain_by_mode = {} for mo in self._ACC_RE.finditer(expr): field, mode, account_codes, domain = self._parse_match_object(mo) aml_domain = list(domain) account_ids = set() for account_code in account_codes: account_ids.update(self._account_ids_by_code[account_code]) if not account_id: aml_domain.append(('account_id', 'in', tuple(account_ids))) else: # filter on account_id if account_id in account_ids: aml_domain.append(('account_id', '=', account_id)) else: continue if field == 'crd': aml_domain.append(('credit', '>', 0)) elif field == 'deb': aml_domain.append(('debit', '>', 0)) aml_domains.append(expression.normalize_domain(aml_domain)) if mode not in date_domain_by_mode: date_domain_by_mode[mode] = \ self.get_aml_domain_for_dates(date_from, date_to, mode, target_move) assert aml_domains # TODO we could do this for more precision: # AND(OR(aml_domains[mode]), date_domain[mode]) for each mode return expression.OR(aml_domains) + \ expression.OR(date_domain_by_mode.values())
def _account_codes_to_domain(self, account_codes): """Convert a comma separated list of account codes (possibly with wildcards) to a domain on account.account. """ elems = [] for account_code in account_codes.split(","): account_code = account_code.strip() if "%" in account_code: elems.append([("code", "=like", account_code)]) else: elems.append([("code", "=", account_code)]) return tuple(expression.OR(elems))