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 _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 button_create_evaluation(self): self.ensure_one() academic_year_obj = self.env["education.academic_year"] academic_year = (self.academic_year_id or academic_year_obj.search([("current", "=", True)], limit=1)) if (academic_year and (not academic_year.date_start or not academic_year.date_end)): msg = _("Academic year must have defined start and end dates.") action = self.env.ref("education.action_education_academic_year") action_msg = _("Configure Academic Year") raise RedirectWarning(msg, action.id, action_msg) for line in self.line_ids: academic_year.create_evaluations(line.center_id, line.course_id, self.evaluation_number, self.final_evaluation) action = self.env.ref( "education.action_education_academic_year_evaluation") action_dict = action and action.read()[0] or {} action_dict["context"] = safe_eval(action_dict.get("context", "{}")) action_dict["context"].update({ "default_academic_year_id": academic_year.id, "search_default_groupby_eval_type": True, }) domain = expression.AND([[ ("academic_year_id", "=", academic_year.id), ("center_id", "in", self.mapped("line_ids.center_id").ids), ("course_id", "in", self.mapped("line_ids.course_id").ids) ], safe_eval(action.domain or "[]")]) action_dict.update({"domain": domain}) return action_dict
def test_calendar_survey(self): real_id = calendar_id2real_id(self.event.id) self.assertFalse(self.event.user_input_ids) wizard = self.wizard_obj.with_context({ 'active_id': self.event.id, 'active_model': 'calendar.event' }).create({}) self.assertEqual(self.event, wizard.event_id) self.assertIn(self.survey, wizard.survey_ids) self.assertIn(self.partner, wizard.partner_ids) wizard.create_survey_response() self.assertTrue(self.event.user_input_ids) self.assertEqual( self.event.user_input_count, len(self.event.user_input_ids)) action_dict = self.event.button_open_user_input() domain = expression.AND([ [('event_id', '=', real_id)], safe_eval(self.action.domain or '[]')]) self.assertEquals(action_dict.get('domain'), domain) wizard = self.wizard_obj.with_context({ 'active_id': self.event.id, 'active_model': 'calendar.event' }).create({ 'survey_ids': [], 'partner_ids': [], }) with self.assertRaises(UserError): wizard.create_survey_response()
def duplicate_picking(self): picking_obj = self.env['stock.picking'] picking_lst = [] date_code = '{}{}{}'.format(self.scheduled_date.year, self.scheduled_date.month, self.scheduled_date.day) for picking in picking_obj.search([('id', 'in', self.env.context['active_ids'])]): pk = picking.copy({ 'scheduled_date': self.scheduled_date, 'is_template': False }) picking_lst.append(pk.id) pk.action_confirm() for move in pk.move_lines: if move.product_id.tracking == 'serial': i = 1 for move_line in move.move_line_ids: move_line.lot_name = '{}.{}-{}'.format( i, date_code, picking.partner_id.name) i += 1 if picking_lst: action = self.env.ref('stock.action_picking_tree_all') action_dict = action.read()[0] if action else {} domain = expression.AND([[('id', 'in', picking_lst)], safe_eval(action.domain or '[]')]) action_dict.update({'domain': domain}) return action_dict return {'type': 'ir.actions.act_window_close'}
def create_sale_order_for_student(self): current_year = self.env["education.academic_year"].search([ ("current", "=", True) ]) if not current_year: raise UserError(_("There should be current academic year")) next_year = current_year._get_next() if not next_year: raise UserError(_('There is no next academic year defined.')) sales = self.env['sale.order'] futures = self.mapped('future_student_ids').filtered( lambda l: l.child_id and not l.sale_order_id and l.academic_year_id == next_year) if not futures: raise UserError(_('There are not future student to register.')) for future in futures: vals = future.crm_lead_id.sudo()._get_vals_for_sale_order(future) future.sale_order_id = sales.create(vals) future.child_id.educational_category = 'student' future.crm_lead_id._put_payer_information_in_sale_order( future, future.sale_order_id) sales += future.sale_order_id action = self.env.ref('sale.action_quotations_with_onboarding') action_dict = action.read()[0] if action else {} domain = expression.AND([[('id', 'in', sales.ids)], safe_eval(action.domain or '[]')]) action_dict.update({ 'domain': domain, }) return action_dict
def _create_enrollment_history(self): students = self.search([ ("educational_category", "=", "student"), ]) current_year = self.env["education.academic_year"].search([ ("current", "=", True)]) if not current_year: return next_year = current_year._get_next() enrollment_obj = self.env["res.partner.enrollment"] for student in students: history = student.enrollment_history_ids.filtered( lambda e: e.academic_year_id == next_year) if not history: new_history = enrollment_obj.new({ "academic_year_id": next_year.id, "partner_id": student.id, "enrollment_action": "pass", }) for onchange_method in new_history._onchange_methods[ "partner_id"]: onchange_method(new_history) for onchange_method in new_history._onchange_methods[ "enrollment_action"]: onchange_method(new_history) enrolment_dict = new_history._convert_to_write( new_history._cache) enrollment_obj.create(enrolment_dict) action = self.env.ref("sale_school.action_res_partner_enrollment") action_dict = action and action.read()[0] domain = expression.AND([ [("academic_year_id", "=", next_year.id)], safe_eval(action.domain or "[]")]) action_dict.update({"domain": domain}) return action_dict
def button_open_programme(self): self.ensure_one() action = self.env.ref('education.action_education_subject_center') action_dict = action.read()[0] if action else {} courses = self.mapped("group_ids.course_id") programme_domain = [ ("center_id", "=", self.center_id.id), ("subject_id", "=", self.subject_id.id), ("level_id", "in", courses.mapped("level_id").ids), ("course_id", "in", courses.ids) ] programmes = self.env["education.subject.center"].search( programme_domain) action_dict["context"] = safe_eval( action_dict.get("context", "{}")) action_dict["context"].update({ "default_center_id": self.center_id.id, "default_subject_id": self.subject_id.id, "default_level_id": courses[:1].mapped("level_id").id, "default_course_id": courses[:1].id, }) if len(programmes) == 1: action_dict['views'] = [ (self.env.ref( 'education.education_subject_center_view_form').id, 'form')] action_dict['res_id'] = programmes.id else: action_dict['domain'] = expression.AND([ programme_domain, safe_eval(action.domain or '[]')]) action_dict.update({ 'display_name': _('Subject Programmes'), }) return action_dict
def open_calendar_event(self): action = self.env.ref('calendar.action_calendar_event') action_dict = action.read()[0] if action else {} res_model_id = self.env['ir.model']._get_id(self._name) domain = expression.AND([[('res_id', '=', self.id), ('res_model_id', '=', res_model_id)], safe_eval(action.domain or '[]')]) action_dict.update({'domain': domain}) return action_dict
def button_show_student_records(self): self.ensure_one() action = self.env.ref( "education_evaluation_notebook.education_record_action") action_dict = action.read()[0] if action else {} domain = expression.AND([[("student_id", "=", self.id)], safe_eval(action.domain or "[]")]) action_dict.update({"domain": domain}) return action_dict
def button_show_partners(self): self.ensure_one() partners = self._find_partner_ids() action = self.env.ref("contacts.action_contacts") action_dict = action.read()[0] if action else {} domain = expression.AND([[("id", "in", partners.ids)], safe_eval(action.domain or "[]")]) action_dict.update({"domain": domain}) return action_dict
def action_view_sepa_from_sale_order(self): self.ensure_one() action = self.env.ref('account_banking_mandate.mandate_action') action_dict = action and action.read()[0] domain = expression.AND([[('id', 'in', self._find_payer_mandates().ids) ], safe_eval(action.domain or '[]')]) action_dict.update({'domain': domain}) return action_dict
def button_open_classroom(self): self.ensure_one() if self.educational_category != "school": return action = self.env.ref("education.action_education_classroom") action_dict = action and action.read()[0] domain = expression.AND([[("center_id", "in", self.ids)], safe_eval(action.domain or "[]")]) action_dict.update({"domain": domain}) return action_dict
def action_view_contracts(self): self.ensure_one() action = self.env.ref("contract.action_customer_contract") action_dict = action.read()[0] if action else {} domain = expression.AND([[("sale_id", "in", self.ids)], safe_eval(action.domain or "[]")]) action_dict.update({ "domain": domain, }) return action_dict
def action_bom_import_boms(self): action = self.env.ref("mrp.mrp_bom_form_action") action_dict = action and action.read()[0] lines = self._get_import_lines() domain = expression.AND([ [("id", "in", lines.mapped("bom_id").ids)], safe_eval(action.domain or "[]"), ]) action_dict.update({"domain": domain}) return action_dict
def button_open_schedule(self): action = self.env.ref('education.action_education_schedule_from_group') action_dict = action.read()[0] if action else {} domain = expression.AND([[('id', 'in', self.mapped('schedule_ids').ids) ], safe_eval(action.domain or '[]')]) action_dict.update({ 'domain': domain, }) return action_dict
def button_open_current_student(self): self.ensure_one() if self.educational_category != "school": return action = self.env.ref('contacts.action_contacts') action_dict = action and action.read()[0] domain = expression.AND([[("current_center_id", "=", self.id)], safe_eval(action.domain or "[]")]) action_dict.update({"domain": domain}) return action_dict
def open_students(self, action): action_dict = action.read()[0] if action else {} domain = expression.AND([[('id', 'in', self.mapped('student_ids').ids) ], safe_eval(action.domain or '[]')]) action_dict.update({ 'display_name': _('Students'), 'domain': domain, }) return action_dict
def button_open_enrollment_order(self): self.ensure_one() action = self.env.ref("sale.action_quotations_with_onboarding") action_dict = action.read()[0] if action else {} domain = expression.AND([[("child_id", "=", self.partner_id.id), ("academic_year_id", "=", self.academic_year_id.id)], safe_eval(action.domain or "[]")]) action_dict.update({"domain": domain}) return action_dict
def button_open_route_issues(self): self.ensure_one() action = self.env.ref("fleet_route_support.action_fleet_route_support") action_dict = action.read()[0] if action else {} domain = expression.AND([[ "|", ("high_stop_route_id", "=", self.id), ("low_stop_route_id", "=", self.id) ], safe_eval(action.domain or "[]")]) action_dict.update({"domain": domain}) return action_dict
def button_show_meetings(self): self.ensure_one() action = self.env.ref('calendar.action_calendar_event') action_dict = action.read()[0] if action else {} action_dict['context'] = safe_eval(action_dict.get('context', '{}')) domain = safe_eval(action.domain or '[]') if self.educational_category == 'student': action_dict['context'].update({ 'search_default_student_id': self.id, 'default_student_id': self.id, }) domain = expression.AND([[('student_id', 'in', self.ids)], domain]) elif self.educational_category == 'family': action_dict['context'].update({ 'search_default_family_id': self.id, 'default_family_id': self.id, }) domain = expression.AND([[('family_id', 'in', self.ids)], domain]) action_dict.update({'domain': domain}) return action_dict
def button_show_homework(self): self.ensure_one() action = self.env.ref( "education_evaluation_notebook.education_homework_action") action_dict = action.read()[0] if action else {} action_dict["context"] = safe_eval(action_dict.get("context", "{}")) action_dict["context"].update({"default_schedule_id": self.id}) domain = expression.AND([[("schedule_id", "=", self.id)], safe_eval(action.domain or "[]")]) action_dict.update({"domain": domain}) return action_dict
def button_open_schedule(self): self.ensure_one() action = self.env.ref( "education.action_education_group_teacher_timetable_report") action_dict = action.read()[0] if action else {} domain = expression.AND([[("professor_id", "=", self.id)], safe_eval(action.domain or "[]")]) action_dict.update({ "domain": domain, }) return action_dict
def action_view_contracts(self): self.ensure_one() action = self.env.ref('contract.action_customer_contract') action_dict = action.read()[0] if action else {} domain = expression.AND([ [('sale_id', 'in', self.ids)], safe_eval(action.domain or '[]')]) action_dict.update({ 'domain': domain, }) return action_dict
def _search(self, args, offset=0, limit=None, order=None, count=False, access_rights_uid=None): context = self.env.context if "search_center_id" in context: args = expression.AND( [args, [("company_partner_bank_id.partner_id", "=", context.get("search_center_id"))]]) result = super(AccountPaymentOrder, self)._search( args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid) return result
def button_open_students(self): action = self.env.ref('education.res_partner_education_action') action_dict = action.read()[0] if action else {} domain = expression.AND([ [('id', 'in', self.mapped('student_ids').ids)], safe_eval(action.domain or '[]') ]) action_dict.update({ 'display_name': _('Students'), 'domain': domain, }) return action_dict
def button_open_school_claims(self): self.ensure_one() action = self.env.ref('issue_education.action_school_claim') action_dict = action.read()[0] if action else {} action_dict['context'] = safe_eval(action_dict.get('context', '{}')) action_dict['context'].update({ 'default_student_id': self.id, }) domain = expression.AND([[('student_id', 'in', self.ids)], safe_eval(action.domain or '[]')]) action_dict.update({'domain': domain}) return action_dict
def done_parsing(self): """ Replace account domains by account ids in map """ for key, acc_domains in self._map_account_ids.items(): all_account_ids = set() for acc_domain in acc_domains: acc_domain_with_company = expression.AND( [acc_domain, [("company_id", "in", self.companies.ids)]]) account_ids = self._account_model.search( acc_domain_with_company).ids self._account_ids_by_acc_domain[acc_domain].update(account_ids) all_account_ids.update(account_ids) self._map_account_ids[key] = list(all_account_ids)
def button_open_bus_issues(self): self.ensure_one() action = self.env.ref("fleet_route_support.action_fleet_route_support") action_dict = action.read()[0] if action else {} action_dict["context"] = safe_eval(action_dict.get("context", "{}")) action_dict["context"].update({ "default_student_id": self.id, }) domain = expression.AND([[("student_id", "in", self.ids)], safe_eval(action.domain or "[]")]) action_dict.update({"domain": domain}) return action_dict