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 EventEvent(models.Model): """ Override Event model to add optional questions when buying tickets. """ _inherit = 'event.event' question_ids = fields.One2many('event.question', 'event_id', 'Questions') general_question_ids = fields.One2many('event.question', 'event_id', 'Questions', domain=[('is_individual', '=', False)]) specific_question_ids = fields.One2many('event.question', 'event_id', 'Questions', domain=[('is_individual', '=', True)])
class OpClassroom(models.Model): _name = 'op.classroom' name = fields.Char('Name', size=16, required=True) code = fields.Char('Code', size=4, required=True) course_id = fields.Many2one('op.course', 'Course', required=True) capacity = fields.Integer(string='No of Person') facilities = fields.One2many('op.facility.line', 'classroom_id', string='Facility Lines') asset_line = fields.One2many('op.asset', 'asset_id', 'Asset')
class HrEquipmentCategory(models.Model): _name = 'hr.equipment.category' _inherits = {"mail.alias": "alias_id"} _inherit = ['mail.thread'] _description = 'Asset Category' @api.one @api.depends('equipment_ids') def _compute_fold(self): self.fold = False if self.equipment_count else True name = fields.Char('Category Name', required=True, translate=True) user_id = fields.Many2one('res.users', 'Responsible', track_visibility='onchange', default=lambda self: self.env.uid) color = fields.Integer('Color Index') note = fields.Text('Comments', translate=True) equipment_ids = fields.One2many('hr.equipment', 'category_id', string='Equipments', copy=False) equipment_count = fields.Integer(string="Equipment", compute='_compute_equipment_count') maintenance_ids = fields.One2many('hr.equipment.request', 'category_id', copy=False) maintenance_count = fields.Integer(string="Maintenance", compute='_compute_maintenance_count') alias_id = fields.Many2one( 'mail.alias', 'Alias', ondelete='cascade', required=True, help="Email alias for this equipment category. New emails will automatically " "create new maintenance request for this equipment category.") fold = fields.Boolean(string='Folded in Maintenance Pipe', compute='_compute_fold', store=True) @api.multi def _compute_equipment_count(self): equipment_data = self.env['hr.equipment'].read_group([('category_id', 'in', self.ids)], ['category_id'], ['category_id']) mapped_data = dict([(m['category_id'][0], m['category_id_count']) for m in equipment_data]) for category in self: category.equipment_count = mapped_data.get(category.id, 0) @api.multi def _compute_maintenance_count(self): maintenance_data = self.env['hr.equipment.request'].read_group([('category_id', 'in', self.ids)], ['category_id'], ['category_id']) mapped_data = dict([(m['category_id'][0], m['category_id_count']) for m in maintenance_data]) for category in self: category.maintenance_count = mapped_data.get(category.id, 0) @api.model def create(self, vals): self = self.with_context(alias_model_name='hr.equipment.request', alias_parent_model_name=self._name) category_id = super(HrEquipmentCategory, self).create(vals) category_id.alias_id.write({'alias_parent_thread_id': category_id.id, 'alias_defaults': {'category_id': category_id.id}}) return category_id @api.multi def unlink(self): for category in self: if category.equipment_ids or category.maintenance_ids: raise UserError(_("You cannot delete an equipment category containing equipments or maintenance requests.")) res = super(HrEquipmentCategory, self).unlink() return res
class Category(models.Model): """ Channel contain various categories to manage its slides """ _name = 'slide.category' _description = "Slides Category" _order = "sequence, id" name = fields.Char('Name', translate=True, required=True) channel_id = fields.Many2one('slide.channel', string="Channel", required=True, ondelete='cascade') sequence = fields.Integer(default=10, help='Display order') slide_ids = fields.One2many('slide.slide', 'category_id', string="Slides") nbr_presentations = fields.Integer("Number of Presentations", compute='_count_presentations', store=True) nbr_documents = fields.Integer("Number of Documents", compute='_count_presentations', store=True) nbr_videos = fields.Integer("Number of Videos", compute='_count_presentations', store=True) nbr_infographics = fields.Integer("Number of Infographics", compute='_count_presentations', store=True) total = fields.Integer(compute='_count_presentations', store=True) @api.depends('slide_ids.slide_type', 'slide_ids.website_published') def _count_presentations(self): result = dict.fromkeys(self.ids, dict()) res = self.env['slide.slide'].read_group( [('website_published', '=', True), ('category_id', 'in', self.ids)], ['category_id', 'slide_type'], ['category_id', 'slide_type'], lazy=False) for res_group in res: result[res_group['category_id'][0]][res_group['slide_type']] = result[res_group['category_id'][0]].get(res_group['slide_type'], 0) + res_group['__count'] for record in self: record.nbr_presentations = result[record.id].get('presentation', 0) record.nbr_documents = result[record.id].get('document', 0) record.nbr_videos = result[record.id].get('video', 0) record.nbr_infographics = result[record.id].get('infographic', 0) record.total = record.nbr_presentations + record.nbr_documents + record.nbr_videos + record.nbr_infographics
class plm_relation_line(models.Model): _name = 'mrp.bom.line' _inherit = 'mrp.bom.line' _order = "itemnum" @api.one def _get_child_bom_lines(self): """ If the BOM line refers to a BOM, return the ids of the child BOM lines """ bom_obj = self.env['mrp.bom'] for bom_line in self: bom_id = bom_obj._bom_find( product_tmpl_id=bom_line.product_id.product_tmpl_id.id, product_id=bom_line.product_id.id, bomType=bom_line.type) if bom_id: child_bom = bom_obj.browse(bom_id) for childBomLine in child_bom.bom_line_ids: childBomLine._get_child_bom_lines() self.child_line_ids = [x.id for x in child_bom.bom_line_ids] else: self.child_line_ids = False state = fields.Selection (related="product_id.state", string=_("Status"), help=_("The status of the product in its LifeCycle."), store=False) engineering_revision = fields.Integer (related="product_id.engineering_revision", string=_("Revision"), help=_("The revision of the product."), store=False) description = fields.Text (related="product_id.description", string=_("Description"), store=False) weight_net = fields.Float (related="product_id.weight", string=_("Weight Net"), store=False) child_line_ids = fields.One2many ("mrp.bom.line",compute=_get_child_bom_lines,string=_("BOM lines of the referred bom"))
class OpResultTemplateLine(models.Model): _name = 'op.result.template.line' _rec_name = 'exam_session_id' _description = 'Result Template Line' exam_session_id = fields.Many2one('op.exam.session', 'Exam Session') detailed_report = fields.Boolean('Detailed Report') course_id = fields.Many2one('op.course', 'Course', related='exam_session_id.course_id', readonly=True) batch_id = fields.Many2one('op.batch', 'Batch', related='exam_session_id.batch_id', readonly=True) result_id = fields.Many2one('op.result.template', 'Result Template Line') exam_lines = fields.One2many('op.result.exam.line', 'result_id', 'Exam Lines') @api.onchange('exam_session_id') def onchange_exam_session(self): for exam_obj in self.exam_session_id.exam_ids: self.exam_lines += self.exam_lines.create({ 'exam_id': exam_obj.id, 'weightage': 100 })
class OpHealth(models.Model): _name = 'op.health' _rec_name = 'student_id' _description = """Health Detail for Students and Faculties""" type = fields.Selection([('student', 'Student'), ('faculty', 'Faculty')], 'Type', default='student', required=True) student_id = fields.Many2one('op.student', 'Student') faculty_id = fields.Many2one('op.faculty', 'Faculty') height = fields.Float('Height(C.M.)', required=True) weight = fields.Float('Weight', 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', required=True) physical_challenges = fields.Boolean('Physical Challenge?', default=False) physical_challenges_note = fields.Text('Physical Challenge') major_diseases = fields.Boolean('Major Diseases?', default=False) major_diseases_note = fields.Text('Major Diseases') eyeglasses = fields.Boolean('Eye Glasses?') eyeglasses_no = fields.Char('Eye Glasses', size=64) regular_checkup = fields.Boolean('Any Regular Checkup Required?', default=False) health_line = fields.One2many('op.health.line', 'health_id', 'Checkup Lines') @api.constrains('height', 'weight') def check_height_weight(self): if self.height <= 0.0 or self.weight <= 0.0: raise ValidationError("Enter proper height and weight!")
class product_template_extend(models.Model): ''' 功能:为产品增加子表:功能清单 ''' _inherit = 'product.template' must_choose=fields.Boolean(string='必选') function_ids=fields.One2many('product.template.function','product_id',string='功能清单')
class sale_order_line_extend(models.Model): ''' 功能:扩展字段,记录行对应的功能说明 ''' _inherit = 'sale.order.line' order_line_function = fields.One2many('sale.order.line.function', 'order_line_id', string='Function Lines')
class OpStudent(models.Model): _name = 'op.student' _inherits = {'res.partner': 'partner_id'} @api.one @api.depends('roll_number_line', 'batch_id', 'course_id') def _get_curr_roll_number(self): # TO_DO:: Improve the logic by adding sequence field in course. if self.roll_number_line: for roll_no in self.roll_number_line: if roll_no.course_id == self.course_id and \ roll_no.batch_id == self.batch_id: self.roll_number = roll_no.roll_number else: self.roll_number = 0 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([('m', 'Male'), ('f', 'Female'), ('o', 'Other')], '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') course_id = fields.Many2one('op.course', 'Course', required=True) batch_id = fields.Many2one('op.batch', 'Batch', required=True) roll_number_line = fields.One2many('op.roll.number', 'student_id', 'Roll Number') partner_id = fields.Many2one('res.partner', 'Partner', required=True, ondelete="cascade") roll_number = fields.Char('Current Roll Number', compute='_get_curr_roll_number', size=8, store=True) gr_no = fields.Char("GR Number", size=20) @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.onchange('course_id') def onchange_course(self): self.batch_id = False
class OauthApplication(models.Model): _inherit = 'oauth.application' client_id = fields.Char('Database UUID') last_connection = fields.Char(compute='_get_last_connection', string='Last Connection', size=64) server_db_ids = fields.One2many('saas_portal.server', 'oauth_application_id', string='Server Database') template_db_ids = fields.One2many('saas_portal.database', 'oauth_application_id', string='Template Database') client_db_ids = fields.One2many('saas_portal.client', 'oauth_application_id', string='Client Database') @api.one def _get_last_connection(self): oat = self.pool.get('oauth.access_token') to_search = [('application_id', '=', self.id)] access_token_ids = oat.search(self.env.cr, self.env.uid, to_search) if access_token_ids: access_token = oat.browse(self.env.cr, self.env.uid, access_token_ids[0]) self.last_connection = access_token.user_id.login_date
class templates(models.Model): _name = "wx.notify_templates" _rec_name = 'templates_remark' message_wx_templateid = fields.Char('微信模板ID') message_template_url = fields.Char("跳转地址") officialaccount = fields.Many2one("wx.officialaccount", '微信服务号') templates_remark = fields.Char("模板使用说明") message_templateid = fields.One2many('wx.notify_templates_value', 'templateid', '模板KEYS') model_id = fields.Many2one( 'ir.model', '应用模型', help="Base model on which the server action runs.")
class EventQuestion(models.Model): _name = 'event.question' _rec_name = 'title' _order = 'sequence,id' title = fields.Char(required=True, translate=True) event_id = fields.Many2one('event.event', required=True, ondelete='cascade') answer_ids = fields.One2many('event.answer', 'question_id', "Answers", required=True) sequence = fields.Integer(default=10) is_individual = fields.Boolean('Ask each attendee', help="If True, this question will be asked for every attendee of a reservation. If " "not it will be asked only once and its value propagated to every attendees.")
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 OauthApplication(models.Model): CLIENT_ID_CHARACTER_SET = r'_-.:;=?!@0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' _name = 'oauth.application' _rec_name = 'client_id' def generate_client_id(self): return str(uuid.uuid1()) client_id = fields.Char('Client ID', select=True, required=True, default=generate_client_id) token_ids = fields.One2many('oauth.access_token', 'application_id', 'Tokens') _sql_constraints = [ ('client_id_uniq', 'unique (client_id)', 'client_id should be unique!'), ] @api.multi def _get_access_token(self, user_id=None, create=False): self.ensure_one() if not user_id: user_id = self.env.user.id access_token = self.env['oauth.access_token'].sudo().search( [('application_id', '=', self.id), ('user_id', '=', user_id)], order='id DESC', limit=1) if access_token: access_token = access_token[0] if access_token.is_expired(): access_token = None if not access_token and create: expires = datetime.now() + timedelta(seconds=60 * 60) vals = { 'user_id': user_id, 'scope': 'userinfo', 'expires': expires.strftime(DEFAULT_SERVER_DATETIME_FORMAT), 'token': oauthlib_common.generate_token(), 'application_id': self.id, } access_token = self.env['oauth.access_token'].create(vals) # we have to commit now, because /oauth2/tokeninfo could # be called before we finish current transaction. self._cr.commit() if not access_token: return None return access_token.token
class pos_config(models.Model): _inherit = 'pos.config' @api.one @api.depends('cache_ids') def _get_oldest_cache_time(self): pos_cache = self.env['pos.cache'] oldest_cache = pos_cache.search([('config_id', '=', self.id)], order='write_date', limit=1) if oldest_cache: self.oldest_cache_time = oldest_cache.write_date # Use a related model to avoid the load of the cache when the pos load his config cache_ids = fields.One2many('pos.cache', 'config_id') oldest_cache_time = fields.Datetime(compute='_get_oldest_cache_time', string='Oldest cache time', readonly=True) def _get_cache_for_user(self): pos_cache = self.env['pos.cache'] cache_for_user = pos_cache.search([('id', 'in', self.cache_ids.ids), ('compute_user_id', '=', self.env.uid)]) if cache_for_user: return cache_for_user[0] else: return None @api.multi def get_products_from_cache(self, fields, domain): cache_for_user = self._get_cache_for_user() if cache_for_user: return cache_for_user.get_cache(domain, fields) else: pos_cache = self.env['pos.cache'] pos_cache.create({ 'config_id': self.id, 'product_domain': str(domain), 'product_fields': str(fields), 'compute_user_id': self.env.uid }) new_cache = self._get_cache_for_user() return new_cache.get_cache(domain, fields) @api.one def delete_cache(self): # throw away the old caches self.cache_ids.unlink()
class SaasPortalClient(models.Model): _inherit = 'saas_portal.client' subscription_start = fields.Datetime(string="Subscription start", track_visibility='onchange') expiration_datetime = fields.Datetime(string="Expiration", compute='_handle_paid_invoices', store=True, help='Subscription start plus all paid days from related invoices') invoice_lines = fields.One2many('account.invoice.line', 'saas_portal_client_id') trial = fields.Boolean('Trial', help='indication of trial clients', default=False, store=True, readonly=True, compute='_handle_paid_invoices') @api.multi @api.depends('invoice_lines.invoice_id.state') def _handle_paid_invoices(self): for client_obj in self: client_obj.expiration_datetime = datetime.strptime(client_obj.create_date, DEFAULT_SERVER_DATETIME_FORMAT) + timedelta(hours=client_obj.plan_id.expiration) # for trial days = 0 for line in self.env['account.invoice.line'].search([('saas_portal_client_id', '=', client_obj.id), ('invoice_id.state', '=', 'paid')]): days += line.period * line.quantity if days != 0: client_obj.expiration_datetime = datetime.strptime(client_obj.subscription_start or client_obj.create_date, DEFAULT_SERVER_DATETIME_FORMAT) + timedelta(days=days) client_obj.trial = not bool(days) @api.multi def get_upgrade_database_payload(self): res = super(SaasPortalClient, self).get_upgrade_database_payload() res['params'].append({'key': 'saas_client.trial', 'value': 'False', 'hidden': True}) if self.invoice_lines: params = [] recent_invoice_line = self.invoice_lines.sorted(reverse=True, key=lambda r: r.create_date)[0] product_obj = recent_invoice_line.product_id attribute_value_obj = product_obj.attribute_value_ids.filtered(lambda r: r.attribute_id.saas_code == 'MAX_USERS') if attribute_value_obj and attribute_value_obj[0].saas_code_value: params.append({'key': 'saas_client.max_users', 'value': attribute_value_obj[0].saas_code_value, 'hidden': True}) attribute_value_obj = product_obj.attribute_value_ids.filtered(lambda r: r.attribute_id.saas_code == 'INSTALL_MODULES') addons = attribute_value_obj and attribute_value_obj[0].saas_code_value or '' if addons: res.update({'install_addons': addons.split(',') if addons else []}) attribute_value_obj = product_obj.attribute_value_ids.filtered(lambda r: r.attribute_id.saas_code == 'STORAGE_LIMIT') if attribute_value_obj and attribute_value_obj[0].saas_code_value: params.append({'key': 'saas_client.total_storage_limit', 'value': attribute_value_obj[0].saas_code_value, 'hidden': True}) res['params'].extend(params) return res
class OpResultExamLine(models.Model): _name = 'op.result.exam.line' _description = 'Result Exam Line' _rec_name = "exam_id" result_id = fields.Many2one('op.result.template.line', 'Session Template') exam_id = fields.Many2one('op.exam', 'Exam') pass_marks = fields.Float('Passing Marks', related='exam_id.min_marks', readonly=True) total_marks = fields.Float('Total Marks', related='exam_id.total_marks', readonly=True) weightage = fields.Float('Weightage') result_lines = fields.One2many('op.result.line', 'exam_tmpl_id', 'Result Lines')
class crm_lead(models.Model): _inherit = ['crm.lead'] @api.one @api.depends('order_ids') def _get_sale_amount_total(self): total = 0.0 nbr = 0 for order in self.order_ids: if order.state == 'draft': nbr += 1 if order.state not in ('draft', 'cancel'): total += order.currency_id.compute(order.amount_untaxed, self.company_currency) self.sale_amount_total = total self.sale_number = nbr sale_amount_total= fields.Float(compute='_get_sale_amount_total', string="Sum of Orders", readonly=True, digits=0) sale_number = fields.Integer(compute='_get_sale_amount_total', string="Number of Quotations", readonly=True) order_ids = fields.One2many('sale.order', 'opportunity_id', string='Orders') def retrieve_sales_dashboard(self, cr, uid, context=None): res = super(crm_lead, self).retrieve_sales_dashboard(cr, uid, context=None) res['invoiced'] = { 'this_month': 0, 'last_month': 0, } account_invoice_domain = [ ('state', 'in', ['open', 'paid']), ('user_id', '=', uid), ('date', '>=', date.today().replace(day=1) - relativedelta(months=+1)), ('type', 'in', ['out_invoice', 'out_refund']) ] invoice_ids = self.pool.get('account.invoice').search_read(cr, uid, account_invoice_domain, ['date', 'amount_untaxed_signed'], context=context) for inv in invoice_ids: if inv['date']: inv_date = datetime.strptime(inv['date'], tools.DEFAULT_SERVER_DATE_FORMAT).date() if inv_date <= date.today() and inv_date >= date.today().replace(day=1): res['invoiced']['this_month'] += inv['amount_untaxed_signed'] elif inv_date < date.today().replace(day=1) and inv_date >= date.today().replace(day=1) - relativedelta(months=+1): res['invoiced']['last_month'] += inv['amount_untaxed_signed'] res['invoiced']['target'] = self.pool('res.users').browse(cr, uid, uid, context=context).target_sales_invoiced return res
class OpMarksheetLine(models.Model): _name = 'op.marksheet.line' _rec_name = 'student_id' marksheet_reg_id = fields.Many2one('op.marksheet.register', 'Marksheet Register') exam_session_id = fields.Many2one('op.result.template.line', 'Session Template') student_id = fields.Many2one('op.student', 'Student', required=True) result_line = fields.One2many('op.result.line', 'result_id', 'Results') total_marks = fields.Float("Total Marks") total_per = fields.Float("Total Percentage") result = fields.Char("Result", size=256) @api.constrains('total_marks', 'total_per') def _check_marks(self): if (self.total_marks < 0.0) or (self.total_per < 0.0): raise ValidationError("Enter proper marks or percentage!")
class ResUsers(models.Model): _inherit = "res.users" user_line = fields.One2many('op.student', 'user_id', 'User Line') @api.multi def create_user(self, records, user_group=None): for rec in records: if not rec.user_id: user_vals = { 'name': rec.name, 'login': rec.email or (rec.name + rec.last_name), 'partner_id': rec.partner_id.id } user_id = self.create(user_vals) rec.user_id = user_id if user_group: user_group.users = user_group.users + user_id
class SaasPortalCategory(models.Model): @api.multi def name_get(self): res = [] for record in self: res.append((record.id, record.display_name)) return res @api.one @api.depends('name') def _name_get_fnc(self): name = self.name if self.parent_id: name = self.parent_id.name + ' / ' + name self.display_name = name _name = "saas.portal.category" _description = "SaaS Client Category" name = fields.Char("Employee Tag", required=True) display_name = fields.Char('Name', compute='_name_get_fnc', store=True, readonly=True) parent_id = fields.Many2one('saas.portal.category', 'Parent Employee Tag', index=True) child_ids = fields.One2many('saas.portal.category', 'parent_id', 'Child Categories') @api.constrains('parent_id') @api.multi def _check_recursion(self): level = 100 cr = self.env.cr ids = self.ids while len(ids): cr.execute( 'select distinct parent_id from saas_portal_category where id IN %s', (tuple(ids), )) ids = filter(None, map(lambda x: x[0], cr.fetchall())) if not level: raise Warning('Error! You cannot create recursive Categories') level -= 1 return True
class wx_notify_message_record(models.Model): _inherit = 'wx.message_record' _name = 'wx.notify_message_record' message_type = fields.Many2one( 'wx.messagetype', string='消息类型', readonly=True, default=lambda self: _messagetype_get(self, self.env.cr, self.env.user. id, 'template')) message_msgid = fields.Char("消息ID") message_template = fields.Many2one('wx.notify_message_template', string="通知消息模板") #toUserName = fields.Many2one('wx.membership',string="接收方/发送方") qy_toUserName = fields.Many2one('hr.employee', string="企业应用接收方/发送方") message_templateid = fields.One2many('wx.notify_record_value', 'templateid', '模板记录') model_id = fields.Many2one( 'ir.model', '应用模型', help="Base model on which the server action runs.") association_order = fields.Char("关联实体编码或单号")
class wx_mpnews_message_record(models.Model): _inherit = 'wx.message_record' _name = 'wx.mpnews_message_record' message_type = fields.Many2one( 'wx.messagetype', string='消息类型', default=lambda self: _messagetype_get(self, self.env.cr, self.env.user. id, 'imagetext')) message_news = fields.One2many('wx.message_mpnews_record', 'news_id', string="图文消息") #toUserName = fields.Many2one('wx.membership',string="接收方/发送方") message_template = fields.Many2one('wx.mpnews_message_template', string="链接消息模板") message_title = fields.Text(string="图文消息标题") message_description = fields.Char(string="图文消息描述") message_picurl = fields.Char(string="图片链接") # 较好的效果为大图360*200,小图200*200 message_url = fields.Char(string="消息跳转链接") isList = fields.Boolean("是否列表") association_order = fields.Char('关联实体编码或单号') qy_toUserName = fields.Many2one('hr.employee', string="企业应用接收方/发送方")
class wx_mpnews_message_template(models.Model): _inherit = 'wx.message_template_base' _name = 'wx.mpnews_message_template' message_type = fields.Many2one( 'wx.messagetype', string='消息类型', default=lambda self: _messagetype_get(self, self.env.cr, self.env.user. id, 'imagetext')) message_news = fields.One2many('wx.message_mpnews_template', 'news_id', string="图文消息") message_title = fields.Text(string="图文消息标题") message_description = fields.Char(string="图文消息描述") message_picurl = fields.Char(string="图片链接") # 较好的效果为大图360*200,小图200*200 message_url = fields.Char(string="消息跳转链接") message_imagedata = fields.Binary(string="图片信息") model_id = fields.Many2one( 'ir.model', '应用模型', ondelete='cascade', copy=False, help="Base model on which the server action runs.")
class OpBookUnit(models.Model): _name = 'op.book.unit' _inherit = 'mail.thread' _description = 'Book Unit' name = fields.Char('Name', required=True) book_id = fields.Many2one('op.book', 'Book', required=True, track_visibility='onchange') barcode = fields.Char('Barcode', size=20) movement_lines = fields.One2many('op.book.movement', 'book_unit_id', 'Movements') state = fields.Selection(unit_states, 'State', default='available', track_visibility='onchange') _sql_constraints = [ ('unique_name_barcode', 'unique(barcode)', 'Barcode must be unique per book unit!'), ]
class OpExamSession(models.Model): _name = 'op.exam.session' _description = 'Exam Session' name = fields.Char('Exam', size=256, required=True) course_id = fields.Many2one('op.course', 'Course', required=True) batch_id = fields.Many2one('op.batch', 'Batch', required=True) exam_code = fields.Char('Exam Code', size=8, required=True) start_date = fields.Date('Start Date', required=True) end_date = fields.Date('End Date', required=True) room_id = fields.Many2one('op.exam.room', 'Room', required=True) exam_ids = fields.One2many('op.exam', 'session_id', 'Exam(s)') @api.constrains('start_date', 'end_date') def _check_date_time(self): if self.start_date > self.end_date: raise ValidationError( 'End Date cannot be set before Start Date.') @api.onchange('course_id') def onchange_course(self): self.batch_id = False
class OpMarksheetRegister(models.Model): _name = 'op.marksheet.register' exam_session_id = fields.Many2one( 'op.exam.session', 'Exam', required=True) marksheet_line = fields.One2many( 'op.marksheet.line', 'marksheet_reg_id', 'Marksheets') generated_date = fields.Date( 'Generated Date', required=True, default=fields.Date.today()) generated_by = fields.Many2one( 'res.users', 'Generated By', default=lambda self: self.env.uid, required=True) status = fields.Selection( [('draft', 'Draft'), ('validated', 'Validated'), ('cancelled', 'Cancelled')], 'Status', default="draft", required=True) total_pass = fields.Float('Total Pass') total_failed = fields.Float('Total Fail') name = fields.Char('Marksheet Register', size=256, required=True) @api.constrains('total_pass', 'total_failed') def _check_marks(self): if (self.total_pass < 0.0) or (self.total_failed < 0.0): raise ValidationError('Enter proper pass or fail!')
class OpAttendanceSheet(models.Model): _name = 'op.attendance.sheet' @api.one @api.depends('attendance_line.present') def _total_present(self): self.total_present = len( self.attendance_line.filtered(lambda self: self.present)) @api.one @api.depends('attendance_line.present') def _total_absent(self): self.total_absent = len( self.attendance_line.filtered(lambda self: self.present is False)) name = fields.Char('Name', required=True, size=32) register_id = fields.Many2one('op.attendance.register', 'Register', required=True) course_id = fields.Many2one('op.course', related='register_id.course_id', store=True, readonly=True) batch_id = fields.Many2one('op.batch', 'Batch', related='register_id.batch_id', store=True, readonly=True) attendance_date = fields.Date('Date', required=True, default=lambda self: fields.Date.today()) attendance_line = fields.One2many('op.attendance.line', 'attendance_id', 'Attendance Line') total_present = fields.Integer('Total Present', compute='_total_present') total_absent = fields.Integer('Total Absent', compute='_total_absent') faculty_id = fields.Many2one('op.faculty', 'Faculty')