class OpBook(models.Model): _name = 'op.book' name = fields.Char('Title', size=128, required=True) isbn = fields.Char('ISBN Code', size=64) tags = fields.Many2many('op.tag', string='Tag(s)') author_ids = fields.Many2many( 'op.author', string='Author(s)', required=True) edition = fields.Char('Edition') description = fields.Text('Description') publisher_ids = fields.Many2many( 'op.publisher', string='Publisher(s)', required=True) course_ids = fields.Many2many('op.course', string='Course', required=True) movement_line = fields.One2many('op.book.movement', 'book_id', 'Movements') subject_ids = fields.Many2many( 'op.subject', string='Subjects', required=True) internal_code = fields.Char('Internal Code', size=64) queue_ids = fields.One2many('op.book.queue', 'book_id', 'Book Queue') unit_ids = fields.One2many('op.book.unit', 'book_id', 'Units') _sql_constraints = [ ('unique_name_isbn', 'unique(isbn)', 'ISBN code must be unique per book!'), ('unique_name_internal_code', 'unique(internal_code)', 'Internal Code must be unique per book!'), ]
class OpTransportation(models.Model): _name = 'op.transportation' name = fields.Char('Name', size=64, required=True) stop_ids = fields.Many2many('op.stop', string='Stops') cost = fields.Float('Cost') vehicle_id = fields.Many2one('op.vehicle', 'Vehicle', required=True) start_time = fields.Float('Start Time', required=True) end_time = fields.Float('End Time', required=True) from_stop_id = fields.Many2one('op.stop', 'From', required=True) to_stop_id = fields.Many2one('op.stop', 'To', required=True) student_ids = fields.Many2many('op.student', string='Student(s)') @api.constrains('student_ids', 'vehicle_id') def check_capacity(self): if len(self.student_ids) > self.vehicle_id.capacity: raise ValidationError('Students over than vehicle capacity.') @api.constrains('from_stop_id', 'to_stop_id') def check_places(self): if self.from_stop_id == self.to_stop_id: raise ValidationError('To place cannot be equal to From place.') @api.constrains('start_time', 'end_time') def _check_date_time(self): if self.start_time < 0 or self.end_time < 0: raise ValidationError("Enter proper Time.") elif self.start_time > 24 or self.end_time > 24: raise ValidationError("Time can't be greater than 24 hours.") elif self.start_time >= self.end_time: raise ValidationError( 'End Time cannot be set before or equal to Start Time.')
class plm_component(models.Model): _name = 'product.product' _inherit = 'product.product' @api.multi def _father_part_compute(self, name='', arg={}): """ Gets father bom. @param self: The object pointer @param cr: The current row, from the database cursor, @param uid: The current user ID for security checks @param ids: List of selected IDs @param name: Name of the field @param arg: User defined argument @param context: A standard dictionary for contextual values @return: Dictionary of values """ bom_line_objType = self.env['mrp.bom.line'] prod_objs = self.browse(self.ids) for prod_obj in prod_objs: prod_ids=[] bom_line_objs = bom_line_objType.search([('product_id','=',prod_obj.id)]) for bom_line_obj in bom_line_objs: prod_ids.extend([bom_line_obj.bom_id.product_id.id]) prod_obj.father_part_ids = self.env['product.product'].browse(list(set(prod_ids))) linkeddocuments = fields.Many2many ('plm.document', 'plm_component_document_rel','component_id','document_id', _('Linked Docs')) tmp_material = fields.Many2one ('plm.material',_('Raw Material'), required=False, change_default=True, help=_("Select raw material for current product")) #tmp_treatment = fields.Many2one('plm.treatment',_('Thermal Treatment'), required=False, change_default=True, help=_("Select thermal treatment for current product")) tmp_surface = fields.Many2one ('plm.finishing',_('Surface Finishing'), required=False, change_default=True, help=_("Select surface finishing for current product")) father_part_ids = fields.Many2many ('product.product', compute = _father_part_compute, string=_("BoM Hierarchy"), store =False) def on_change_tmpmater(self, cr, uid, ids, tmp_material=False): values = {'engineering_material': ''} if tmp_material: thisMaterial = self.pool.get('plm.material') thisObject = thisMaterial.browse(cr, uid, tmp_material) if thisObject.name: values['engineering_material'] = unicode(thisObject.name) return {'value': values} def on_change_tmptreatment(self, cr, uid, ids, tmp_treatment=False): values = {'engineering_treatment': ''} if tmp_treatment: thisTreatment = self.pool.get('plm.treatment') thisObject = thisTreatment.browse(cr, uid, tmp_treatment) if thisObject.name: values['engineering_treatment'] = unicode(thisObject.name) return {'value': values} def on_change_tmpsurface(self, cr, uid, ids, tmp_surface=False): values = {'engineering_surface': ''} if tmp_surface: thisSurface = self.pool.get('plm.finishing') thisObject = thisSurface.browse(cr, uid, tmp_surface) if thisObject.name: values['engineering_surface'] = unicode(thisObject.name) return {'value': values}
class wx_message_record(models.AbstractModel): _name = 'wx.message_record' message_event = fields.Selection([('receive', '收'), ('send', '发')], require=True, string="消息事件类型") association_user = fields.Many2one('res.partner', string="关联用户") message_type = fields.Many2one('wx.messagetype', string='消息类型') officialaccount = fields.Many2one('wx.officialaccount', '微信服务号/企业号应用') createTime = fields.Datetime("消息创建时间") session_id = fields.Char("会话ID") message_status = fields.Selection([('draft', '草稿'), ('approving', '审核中'), ('approved', '审核通过'), ('sending', '发送中'), ('use_sucess', '已接受'), ('use_block', '已拒绝'), ('system_fail', '发送失败')], require=True, string="消息状态", default='draft') usergroup = fields.Many2many('res.users', 'usergroup_id', 'user_id', string="群发企业用户") official_username = fields.Many2one('wx.customer', string="接收方/发送方") send_event = fields.Many2one('wx.message.send_event', string="消息发送事件")
class OpExamResAllocation(models.Model): _name = 'op.exam.res.allocation' exam_session_ids = fields.Many2many( 'op.exam.session', string='Select Exam Session') exam_ids = fields.Many2many('op.exam', string='Exam(s)') faculty_ids = fields.Many2many('op.faculty', string='Faculty') student_ids = fields.Many2many('op.student', string='Student') @api.onchange('exam_session_ids') def onchange_exam_session_res(self): for session in self.exam_session_ids: students = self.env['op.student'].search( [('course_id', '=', session.course_id.id)]) self.exam_ids = session.exam_ids.ids self.student_ids = students.ids
class FindPaymentsWizard(models.TransientModel): _name = 'saas_portal.find_payments_wizard' invoice_lines = fields.Many2many('account.invoice.line') @api.model def default_get(self, fields): res = super(FindPaymentsWizard, self).default_get(fields) client_obj = self.env['saas_portal.client'].browse( self._context.get('active_id')) lines = self.find_partner_payments(client_obj.partner_id.id, client_obj.plan_id.id) res.update({'invoice_lines': [(6, 0, lines.ids)]}) return res @api.model def find_partner_payments(self, partner_id, plan_id): lines = self.env['account.invoice.line'].search([ ('partner_id', '=', partner_id), ('product_id.plan_id', '=', plan_id), ('period', '!=', False), ('saas_portal_client_id', '=', False) ]) return lines @api.multi def apply_invoice_lines(self): client_obj = self.env['saas_portal.client'].browse( self._context.get('active_id')) self.invoice_lines.write({'saas_portal_client_id': client_obj.id})
class OpHostelRoomAllocation(models.Model): _name = 'op.hostel.room' hostel_id = fields.Many2one('op.hostel', 'Hostel', required=True) name = fields.Many2one('op.room', 'Room', required=True) student_ids = fields.Many2many('res.partner', string='Allocated Students') students_per_room = fields.Integer('Students per Room', required=True) rent = fields.Float('Rent') allocated_date = fields.Date('Allocated Date', default=fields.Date.today()) @api.constrains('students_per_room') def check_capacity(self): if self.students_per_room <= 0: raise ValidationError("Enter proper Student Per Room") @api.onchange('hostel_id') def onchange_hostel(self): if self.hostel_id: self.name = False @api.onchange('name') def onchange_name(self): if self.name: self.students_per_room = self.name.capacity @api.one @api.constrains('student_ids', 'students_per_room') def _check_student_capacity(self): if len(self.student_ids) > self.students_per_room: raise ValidationError('Room capacity Over')
class OpExamRoom(models.Model): _name = 'op.exam.room' name = fields.Char('Name', size=256, required=True) classroom_id = fields.Many2one('op.classroom', 'Classroom', required=True) capacity = fields.Integer('Capacity', required=True) course_ids = fields.Many2many('op.course', string='Course(s)') student_ids = fields.Many2many('op.student', string='Student(s)') @api.constrains('capacity') def check_capacity(self): if self.capacity < 0: raise ValidationError('Enter proper Capacity') elif self.capacity > self.classroom_id.capacity: raise ValidationError('Capacity over Classroom capacity!') @api.onchange('classroom_id') def onchange_classroom(self): self.capacity = self.classroom_id.capacity
class plm_document(models.Model): _name = 'plm.document' _inherit = ['mail.thread','plm.document'] linkedcomponents = fields.Many2many('product.product', 'plm_component_document_rel','document_id','component_id', _('Linked Parts')) _defaults = { 'state': lambda *a: 'draft', 'res_id': lambda *a: False, }
class SaasPortalPlan(models.Model): _name = 'saas_portal.plan' _inherit = 'saas_portal.plan' page_url = fields.Char('Plan URL', placeholder='some-name') yuancloud_version = fields.Char('yuancloud Version', placeholder='9.0') app_store_module_ids = fields.Many2many('saas_portal.module', 'saas_portal_plan_module', 'plan_id', 'module_id', 'Modules')
class event_track_tag(models.Model): _name = "event.track.tag" _description = 'Track Tag' _order = 'name' name = fields.Char('Tag') track_ids = fields.Many2many('event.track', string='Tracks') _sql_constraints = [ ('name_uniq', 'unique (name)', "Tag name already exists !"), ]
class AccountInvoice(models.Model): _inherit = "account.invoice" workflow_process_id = fields.Many2one(comodel_name='sale.workflow.process', string='Sale Workflow Process') # TODO propose a merge to add this field by default in acount module sale_ids = fields.Many2many(comodel_name='sale.order', relation='sale_order_invoice_rel', column1='invoice_id', column2='order_id', string='Sale Orders')
class SaleOrderLine(models.Model): _inherit = 'sale.order.line' property_ids = fields.Many2many('mrp.property', 'sale_order_line_property_rel', 'order_id', 'property_id', 'Properties', readonly=True, states={'draft': [('readonly', False)]}) @api.multi def _get_delivered_qty(self): self.ensure_one() precision = self.env['decimal.precision'].precision_get( 'Product Unit of Measure') # In the case of a kit, we need to check if all components are shipped. We use a all or # nothing policy. A product can have several BoMs, we don't know which one was used when the # delivery was created. bom_delivered = {} for bom in self.product_id.product_tmpl_id.bom_ids: if bom.type != 'phantom': continue bom_delivered[bom.id] = False bom_exploded = self.env['mrp.bom']._bom_explode( bom, self.product_id, self.product_uom_qty)[0] for bom_line in bom_exploded: qty = 0.0 for move in self.procurement_ids.mapped('move_ids'): if move.state == 'done' and move.product_id.id == bom_line.get( 'product_id', False): qty += self.env['product.uom']._compute_qty_obj( move.product_uom, move.product_uom_qty, self.product_uom) if float_compare(qty, bom_line['product_qty'], precision_digits=precision) < 0: bom_delivered[bom.id] = False break else: bom_delivered[bom.id] = True if bom_delivered and any(bom_delivered.values()): return self.product_uom_qty elif bom_delivered: return 0.0 return super(SaleOrderLine, self)._get_delivered_qty() @api.multi def _prepare_order_line_procurement(self, group_id=False): vals = super(SaleOrderLine, self)._prepare_order_line_procurement(group_id=group_id) vals['property_ids'] = [(6, 0, self.property_ids.ids)] return vals
class SaasPortalClient(models.Model): _inherit = 'saas_portal.client' category_ids = fields.Many2many('saas.portal.category', string='Tags') @api.model @api.returns('self', lambda value: value.id) def create(self, vals): if vals.get('plan_id'): plan = self.env['saas_portal.plan'].browse(vals['plan_id']) vals['category_ids'] = [(6, 0, plan.category_ids.ids)] return super(SaasPortalClient, self).create(vals)
class OpFaculty(models.Model): _name = 'op.faculty' _inherits = {'res.partner': 'partner_id'} partner_id = fields.Many2one('res.partner', 'Partner', required=True, ondelete="cascade") middle_name = fields.Char('Middle Name', size=128) last_name = fields.Char('Last Name', size=128, required=True) birth_date = fields.Date('Birth Date', required=True) blood_group = fields.Selection([('A+', 'A+ve'), ('B+', 'B+ve'), ('O+', 'O+ve'), ('AB+', 'AB+ve'), ('A-', 'A-ve'), ('B-', 'B-ve'), ('O-', 'O-ve'), ('AB-', 'AB-ve')], 'Blood Group') gender = fields.Selection([('male', 'Male'), ('female', 'Female')], 'Gender', required=True) nationality = fields.Many2one('res.country', 'Nationality') emergency_contact = fields.Many2one('res.partner', 'Emergency Contact') visa_info = fields.Char('Visa Info', size=64) id_number = fields.Char('ID Card Number', size=64) photo = fields.Binary('Photo') login = fields.Char('Login', related='partner_id.user_id.login', readonly=1) last_login = fields.Datetime('Latest Connection', related='partner_id.user_id.login_date', readonly=1) faculty_subject_ids = fields.Many2many('op.subject', string='Subject(s)') emp_id = fields.Many2one('hr.employee', 'Employee') @api.one @api.constrains('birth_date') def _check_birthdate(self): if self.birth_date > fields.Date.today(): raise ValidationError( "Birth Date can't be greater than current date!") @api.one def create_employee(self): vals = { 'name': self.name + ' ' + (self.middle_name or '') + ' ' + self.last_name, 'country_id': self.nationality.id, 'gender': self.gender, 'address_home_id': self.partner_id.id } emp_id = self.env['hr.employee'].create(vals) self.write({'emp_id': emp_id.id}) self.partner_id.write({'supplier': True, 'employee': True})
class OpAssignment(models.Model): _name = 'op.assignment' _inherit = 'mail.thread' _description = 'Assignment' name = fields.Char('Name', size=16, required=True) course_id = fields.Many2one('op.course', 'Course', required=True) batch_id = fields.Many2one('op.batch', 'Batch', required=True) subject_id = fields.Many2one('op.subject', 'Subject', required=True) faculty_id = fields.Many2one( 'op.faculty', 'Faculty', default=lambda self: self.env[ 'op.faculty'].search([('user_id', '=', self.env.uid)]), required=True) assignment_type_id = fields.Many2one( 'op.assignment.type', 'Assignment Type', required=True) marks = fields.Float('Marks', track_visibility='onchange') description = fields.Text('Description', required=True) state = fields.Selection( [('draft', 'Draft'), ('publish', 'Published'), ('finish', 'Finished')], 'State', required=True, default='draft', track_visibility='onchange') issued_date = fields.Datetime( 'Issued Date', required=True, default=lambda self: fields.Datetime.now()) submission_date = fields.Datetime( 'Submission Date', required=True, track_visibility='onchange') allocation_ids = fields.Many2many('op.student', string='Allocated To') assignment_sub_line = fields.One2many( 'op.assignment.sub.line', 'assignment_id', 'Submissions') reviewer = fields.Many2one('op.faculty', 'Reviewer') @api.one @api.constrains('issued_date', 'submission_date') def check_dates(self): issued_date = fields.Date.from_string(self.issued_date) submission_date = fields.Date.from_string(self.submission_date) if issued_date > submission_date: raise ValidationError( "Submission Date cannot be set before Issue Date.") @api.onchange('course_id') def onchange_course(self): self.batch_id = False @api.one def act_publish(self): self.state = 'publish' @api.one def act_finish(self): self.state = 'finish'
class OpParent(models.Model): _name = 'op.parent' name = fields.Many2one('res.partner', 'Name', default=lambda self: self.env['res.partner'].search( [('user_id', '=', self.env.uid)]), required=True) student_ids = fields.Many2many('op.student', string='Student(s)') user_id = fields.Many2one('res.users', 'User', default=lambda self: self.env.uid, required=True)
class training(models.Model): ''' 实体:培训记录 ''' _name = 'hr.training.record' lession_id = fields.Many2one( 'hr.training.lession', string='培训课程', required=True, ) date = fields.Date(required=True, string='培训日期') time = fields.Char(required=True, string='培训时间') address = fields.Char(required=True, string='培训地点') teacher = fields.Char(required=True, string='培训讲师') student = fields.Many2many('hr.employee', 'training_employee_rel', 'training_id', 'employee_id', required=True, string='培训学员') price = fields.Float(digits=(16, 2), string='培训费用', default=0.0) description = fields.Text(string='培训描述') @api.onchange('lession_id') def change_lession(self): ''' 功能:默认根据课程获取培训费用、培训讲师 :return: ''' if self.lession_id: self.price = self.lession_id.price teachers = '' if self.lession_id.external_teacher: teachers = self.lession_id.external_teacher + ',' #取内聘讲师 sql_str = '''select emp.name_related from lession_teacher_rel as r join hr_employee as emp on r.teacher_id=emp.id where r.lession_id=%s ''' % (self.lession_id.id) _logger.info('根据培训课程ID,查找讲师=%s' % sql_str) self._cr.execute(sql_str) res = self._cr.fetchall() for r in res: teachers += r[0] + ',' if len(teachers) > 0: teachers = teachers[0:-1] self.teacher = teachers self.description = self.lession_id.description
class SaleOrder(models.Model): _inherit = 'sale.order' tasks_ids = fields.Many2many('project.task', compute='_compute_tasks_ids', string='Tasks associated to this sale') tasks_count = fields.Integer(string='Tasks', compute='_compute_tasks_ids') @api.multi @api.depends('order_line.product_id.project_id') def _compute_tasks_ids(self): for order in self: order.tasks_ids = self.env['project.task'].search([ ('sale_line_id', 'in', order.order_line.ids) ]) order.tasks_count = len(order.tasks_ids) @api.multi def action_view_task(self): self.ensure_one() imd = self.env['ir.model.data'] action = imd.xmlid_to_object('project.action_view_task') list_view_id = imd.xmlid_to_res_id('project.view_task_tree2') form_view_id = imd.xmlid_to_res_id('project.view_task_form2') result = { 'name': action.name, 'help': action.help, 'type': action.type, 'views': [[list_view_id, 'tree'], [False, 'kanban'], [form_view_id, 'form'], [False, 'graph'], [False, 'calendar'], [False, 'pivot'], [False, 'graph']], 'target': action.target, 'context': action.context, 'res_model': action.res_model, } if len(self.tasks_ids) > 1: result['domain'] = "[('id','in',%s)]" % self.tasks_ids.ids elif len(self.tasks_ids) == 1: result['views'] = [(form_view_id, 'form')] result['res_id'] = self.tasks_ids.id else: result = {'type': 'ir.actions.act_window_close'} return result
class TemplatePreview(models.TransientModel): _inherit = "mail.template" _name = "email_template.preview" _description = "Email Template Preview" @api.model def _get_records(self): """ Return Records of particular Email Template's Model """ template_id = self._context.get('template_id') default_res_id = self._context.get('default_res_id') if not template_id: return [] template = self.env['mail.template'].browse(int(template_id)) records = self.env[template.model_id.model].search([], limit=10) records |= records.browse(default_res_id) return records.name_get() @api.model def default_get(self, fields): result = super(TemplatePreview, self).default_get(fields) if 'res_id' in fields and not result.get('res_id'): records = self._get_records() result['res_id'] = records and records[0][ 0] or False # select first record as a Default if self._context.get( 'template_id' ) and 'model_id' in fields and not result.get('model_id'): result['model_id'] = self.env['mail.template'].browse( self._context['template_id']).model_id.id return result res_id = fields.Selection(_get_records, 'Sample Document') partner_ids = fields.Many2many('res.partner', string='Recipients') @api.onchange('res_id') @api.multi def on_change_res_id(self): mail_values = {} if self.res_id and self._context.get('template_id'): template = self.env['mail.template'].browse( self._context['template_id']) self.name = template.name mail_values = template.generate_email(self.res_id) for field in [ 'email_from', 'email_to', 'email_cc', 'reply_to', 'subject', 'body_html', 'partner_to', 'partner_ids', 'attachment_ids' ]: setattr(self, field, mail_values.get(field, False))
class ImLivechatChannelRule(models.Model): """ Channel Rules Rules defining access to the channel (countries, and url matching). It also provide the 'auto pop' option to open automatically the conversation. """ _name = 'im_livechat.channel.rule' _description = 'Channel Rules' _order = 'sequence asc' regex_url = fields.Char('URL Regex', help="Regular expression identifying the web page on which the rules will be applied.") action = fields.Selection([('display_button', 'Display the button'), ('auto_popup', 'Auto popup'), ('hide_button', 'Hide the button')], string='Action', required=True, default='display_button', help="* Select 'Display the button' to simply display the chat button on the pages.\n"\ "* Select 'Auto popup' for to display the button, and automatically open the conversation window.\n"\ "* Select 'Hide the button' to hide the chat button on the pages.") auto_popup_timer = fields.Integer('Auto popup timer', default=0, help="Delay (in seconds) to automatically open the converssation window. Note : the selected action must be 'Auto popup', otherwise this parameter will not be take into account.") channel_id = fields.Many2one('im_livechat.channel', 'Channel', help="The channel of the rule") country_ids = fields.Many2many('res.country', 'im_livechat_channel_country_rel', 'channel_id', 'country_id', 'Country', help="The actual rule will match only for this country. So if you set select 'Belgium' and 'France' and you set the action to 'Hide Buttun', this 2 country will not be see the support button for the specified URL. This feature requires GeoIP installed on your server.") sequence = fields.Integer('Matching order', default=10, help="Given the order to find a matching rule. If 2 rules are matching for the given url/country, the one with the lowest sequence will be chosen.") def match_rule(self, channel_id, url, country_id=False): """ determine if a rule of the given channel match with the given url :param channel_id : the identifier of the channel_id :param url : the url to match with a rule :param country_id : the identifier of the country :returns the rule that match the given condition. False otherwise. :rtype : im_livechat.channel.rule """ def _match(rules): for rule in rules: if re.search(rule.regex_url, url): return rule return False # first, search the country specific rules (the first match is returned) if country_id: # don't include the country in the research if geoIP is not installed domain = [('country_ids', 'in', [country_id]), ('channel_id', '=', channel_id)] rule = _match(self.search(domain)) if rule: return rule # second, fallback on the rules without country domain = [('country_ids', '=', False), ('channel_id', '=', channel_id)] return _match(self.search(domain))
class lunch_order_line(models.TransientModel): _name = 'lunch.order.line.lucky' def _default_supplier(self): suppliers_obj = self.env['lunch.product'].search([]).mapped("supplier") return [(4, supplier.id) for supplier in suppliers_obj] product_id = fields.Many2one('lunch.product', 'Product', store=True) supplier_ids = fields.Many2many( comodel_name='res.partner', string='Vendor', domain=lambda self: [("id", "in", self.env['lunch.product'].search([]). mapped("supplier").ids)]) is_max_budget = fields.Boolean( "I'm not feeling rich", help="Enable this option to set a maximal budget for your lucky order.", store=True) max_budget = fields.Float('Max Budget', store=True) @api.multi def random_pick(self): """ To pick a random product from the selected suppliers, and create an order with this one """ self.ensure_one() if self.is_max_budget: products_obj = self.env['lunch.product'].search([ ('supplier', "in", self.supplier_ids.ids), ('price', '<=', self.max_budget) ]) else: products_obj = self.env['lunch.product'].search([ ('supplier', "in", self.supplier_ids.ids) ]) if len(products_obj) != 0: random_product_obj = self.env['lunch.product'].browse( [random.choice(products_obj.ids)]) order_line = self.env['lunch.order.line'].create({ 'product_id': random_product_obj.id, 'order_id': self._context['active_id'] }) else: raise UserError( _('No product is matching your request. Now you will starve to death.' ))
class StudentMigrate(models.TransientModel): """ Student Migration Wizard """ _name = 'student.migrate' date = fields.Date('Date', required=True, default=fields.Date.today()) course_from_id = fields.Many2one('op.course', 'From Course', required=True) course_to_id = fields.Many2one('op.course', 'To Course', required=True) student_ids = fields.Many2many('op.student', string='Student(s)', required=True) @api.one @api.constrains('course_from_id', 'course_to_id') def _check_admission_register(self): if self.course_from_id == self.course_to_id: raise ValidationError("From Course must not be same as To Course!") if self.course_from_id.parent_id: if self.course_from_id.parent_id != \ self.course_to_id.parent_id: raise ValidationError( "Can't migrate, As selected courses don't \ share same parent course!") else: raise ValidationError("Can't migrate, Proceed for new admission") @api.one @api.onchange('course_from_id') def onchange_course_id(self): self.student_ids = False @api.one def student_migrate_forward(self): activity_type = self.env["op.activity.type"] act_type = activity_type.search([('name', '=', 'Migration')], limit=1) if not act_type: act_type = activity_type.create({'name': 'Migration'}) for student in self.student_ids: activity_vals = { 'student_id': student.id, 'type_id': act_type.id, 'date': self.date } self.env['op.activity'].create(activity_vals) student.write({'course_id': self.course_to_id.id})
class WizardOpFaculty(models.TransientModel): _name = 'wizard.op.faculty' _description = "Create User for selected Faculty(s)" def _get_faculties(self): if self.env.context and self.env.context.get('active_ids'): return self.env.context.get('active_ids') return [] faculty_ids = fields.Many2many( 'op.faculty', default=_get_faculties, string='Faculties') @api.one def create_faculty_user(self): user_group = self.env.ref('openeducat_core.group_op_faculty') active_ids = self.env.context.get('active_ids', []) or [] records = self.env['op.faculty'].browse(active_ids) self.env['res.users'].create_user(records, user_group)
class mrp_production_workcenter_line_extend(models.Model): ''' 派工单(工票)实体扩展 ''' _inherit = 'mrp.production.workcenter.line' _description = 'Work Order' _order = 'sequence' plan_qty = fields.Float(digits=(16, 2), string='计划数量') actual_qty = fields.Float(digits=(16, 2), string='实际数量') qualified_qty = fields.Float(digits=(16, 2), string='实际合格量') finish_user = fields.Many2many('res.users', 'finish_plan_user_rel', 'finish_plan_id', 'user_id', string='操作人员') is_comp_point = fields.Boolean(string='完工报告点') is_finish_plan = fields.Boolean(string='捕捞计划') lot_id = fields.Many2one('stock.production.lot', string='批次')
class SaasTagClient(models.TransientModel): _name = 'saas_portal.tag_client' @api.model def _default_categories(self): client = self.env['saas_portal.client'].browse( self.env.context['active_id']) return client.category_ids.ids category_ids = fields.Many2many('saas.portal.category', string='Tags', default=_default_categories) @api.multi def apply(self): self.ensure_one() client = self.env['saas_portal.client'].browse( self.env.context['active_id']) client.write({'category_ids': [(6, 0, self.category_ids.ids)]}) return True
class Tags(models.Model): _name = "forum.tag" _description = "Forum Tag" _inherit = ['website.seo.metadata'] name = fields.Char('Name', required=True) create_uid = fields.Many2one('res.users', string='Created by', readonly=True) forum_id = fields.Many2one('forum.forum', string='Forum', required=True) post_ids = fields.Many2many('forum.post', 'forum_tag_rel', 'forum_tag_id', 'forum_id', string='Posts') posts_count = fields.Integer('Number of Posts', compute='_get_posts_count', store=True) _sql_constraints = [ ('name_uniq', 'unique (name, forum_id)', "Tag name already exists !"), ] @api.multi @api.depends("post_ids.tag_ids") def _get_posts_count(self): for tag in self: tag.posts_count = len(tag.post_ids)
class RecruitmentStage(models.Model): _name = "hr.recruitment.stage" _description = "Stage of Recruitment" _order = 'sequence' name = fields.Char("Stage name", required=True, translate=True) sequence = fields.Integer( "Sequence", default=1, help="Gives the sequence order when displaying a list of stages.") job_ids = fields.Many2many( 'hr.job', 'job_stage_rel', 'stage_id', 'job_id', string='Job Stages', default=lambda self: [(4, self._context['default_job_id'])] if self._context.get('default_job_id') else None) requirements = fields.Text("Requirements") template_id = fields.Many2one( 'mail.template', "Use template", help="If set, a message is posted on the applicant using the template when the applicant is set to the stage.") fold = fields.Boolean( "Folded in Recruitment Pipe", help="This stage is folded in the kanban view when there are no records in that stage to display.")
class tip(models.Model): _name = 'web.tip' _description = 'Tips' @api.one @api.depends('user_ids') def _is_consumed(self): self.is_consumed = self.env.user in self.user_ids title = fields.Char('Tip title') description = fields.Html('Tip Description', required=True) action_id = fields.Many2one('ir.actions.act_window', string="Action", help="The action that will trigger the tip") model = fields.Char( "Model", help="Model name on which to trigger the tip, e.g. 'res.partner'.") type = fields.Char( "Type", help="Model type, e.g. lead or opportunity for crm.lead") mode = fields.Char("Mode", help="Mode, e.g. kanban, form") trigger_selector = fields.Char( 'Trigger selector', help= 'CSS selectors used to trigger the tip, separated by a comma (ANDed).') highlight_selector = fields.Char( 'Highlight selector', help='CSS selector for the element to highlight') end_selector = fields.Char('End selector', help='CSS selector used to end the tip') end_event = fields.Char('End event', help='Event to end the tip', default='click') placement = fields.Char( 'Placement', help='Popover placement, bottom, top, left or right', default='auto') user_ids = fields.Many2many('res.users', string='Consumed by') is_consumed = fields.Boolean(string='Tip consumed', compute='_is_consumed') @api.multi def consume(self): self.write({'user_ids': [(4, self.env.uid)]})
class training_lession(models.Model): ''' 实体:培训课程 ''' _name = 'hr.training.lession' type = fields.Selection([('Internal', '内部培训'), ('External', '外部培训')], default='Internal', required=True, string='课程类型') code = fields.Char(required=True, string='课程编号') name = fields.Char(required=True, string='课程名称') teacher = fields.Many2many('hr.employee', 'lession_teacher_rel', 'lession_id', 'teacher_id', string='内聘讲师') external_teacher = fields.Char(string='外聘讲师') price = fields.Float(digits=(16, 2), string='培训费用', default=0.0) description = fields.Text(string='课程描述') _sql_constraints = [('code_uniq', 'unique(code)', '课程编号必须唯一!')]