class AgedPartnerBalanceReportPartner(models.TransientModel): _name = 'report_aged_partner_balance_partner' _inherit = 'account_financial_report_abstract' report_account_id = fields.Many2one( comodel_name='report_aged_partner_balance_account', ondelete='cascade', index=True) # Data fields, used to keep link with real object partner_id = fields.Many2one('res.partner', index=True) # Data fields, used for report display name = fields.Char() # Data fields, used to browse report data move_line_ids = fields.One2many( comodel_name='report_aged_partner_balance_move_line', inverse_name='report_partner_id') line_ids = fields.One2many(comodel_name='report_aged_partner_balance_line', inverse_name='report_partner_id') @api.model def _generate_order_by(self, order_spec, query): """Custom order to display "No partner allocated" at last position.""" return """
class ReportJournalLedgerJournal(models.TransientModel): _name = 'report_journal_ledger_journal' _inherit = 'account_financial_report_abstract' name = fields.Char(required=True, ) code = fields.Char() report_id = fields.Many2one(comodel_name='report_journal_ledger', required=True, ondelete='cascade') journal_id = fields.Many2one( comodel_name='account.journal', required=True, ondelete='cascade', ) report_move_ids = fields.One2many( comodel_name='report_journal_ledger_move', inverse_name='report_journal_ledger_id', ) report_tax_line_ids = fields.One2many( comodel_name='report_journal_ledger_journal_tax_line', inverse_name='report_journal_ledger_id', ) debit = fields.Float(digits=DIGITS, ) credit = fields.Float(digits=DIGITS, ) company_id = fields.Many2one(comodel_name='res.company', required=True, ondelete='cascade') currency_id = fields.Many2one(comodel_name='res.currency', )
class OpMedia(models.Model): _name = 'op.media' 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') movement_line = fields.One2many('op.media.movement', 'media_id', 'Movements') subject_ids = fields.Many2many('op.subject', string='Subjects') internal_code = fields.Char('Internal Code', size=64) queue_ids = fields.One2many('op.media.queue', 'media_id', 'Media Queue') unit_ids = fields.One2many('op.media.unit', 'media_id', 'Units') media_type_id = fields.Many2one('op.media.type', 'Media Type') _sql_constraints = [ ('unique_name_isbn', 'unique(isbn)', 'ISBN code must be unique per media!'), ('unique_name_internal_code', 'unique(internal_code)', 'Internal Code must be unique per media!'), ]
class Employee(models.Model): _inherit = 'hr.employee' resume_line_ids = fields.One2many('hr.resume.line', 'employee_id', string="Resumé lines") employee_skill_ids = fields.One2many('hr.employee.skill', 'employee_id', string="Skills") @api.model_create_multi def create(self, vals_list): res = super(Employee, self).create(vals_list) resume_lines_values = [] for employee in res: line_type = self.env.ref('hr_skills.resume_type_experience', raise_if_not_found=False) resume_lines_values.append({ 'employee_id': employee.id, 'name': employee.company_id.name or '', 'date_start': employee.create_date.date(), 'description': employee.job_title or '', 'line_type_id': line_type and line_type.id, }) self.env['hr.resume.line'].create(resume_lines_values) return res
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', copy=True) general_question_ids = fields.One2many('event.question', 'event_id', 'General Questions', domain=[('is_individual', '=', False)]) specific_question_ids = fields.One2many('event.question', 'event_id', 'Specific Questions', domain=[('is_individual', '=', True)]) @api.onchange('event_type_id') def _onchange_type(self): super(EventEvent, self)._onchange_type() if self.event_type_id.use_questions and self.event_type_id.question_ids: self.question_ids = [(5, 0, 0)] + [ (0, 0, { 'title': question.title, 'sequence': question.sequence, 'is_individual': question.is_individual, }) for question in self.event_type_id.question_ids ]
class EducationPlan(models.Model): _name = 'education.plan' _inherit = 'education.data' _description = 'Education Plan' level_ids = fields.One2many( comodel_name='education.level', string='Levels', inverse_name='plan_id') course_ids = fields.One2many( comodel_name='education.course', string='Courses', inverse_name='plan_id') _sql_constraints = [ ('education_code_unique', 'unique(education_code)', 'Education code must be unique!'), ] @api.multi def write(self, vals): res = super(EducationPlan, self).write(vals) if vals else True if 'active' in vals: # archiving/unarchiving a plan does it on its levels, too self.with_context(active_test=False).mapped('level_ids').write( {'active': vals['active']}) if 'active' in vals: # archiving/unarchiving a plan does it on its levels, too self.with_context(active_test=False).mapped('course_ids').write( {'active': vals['active']}) return res
class Discussion(models.Model): _name = 'test_new_api.discussion' _description = 'Test New API Discussion' name = fields.Char( string='Title', required=True, help="General description of what this discussion is about.") moderator = fields.Many2one('res.users') categories = fields.Many2many('test_new_api.category', 'test_new_api_discussion_category', 'discussion', 'category') participants = fields.Many2many('res.users', context={'active_test': False}) messages = fields.One2many('test_new_api.message', 'discussion', copy=True) message_concat = fields.Text(string='Message concatenate') important_messages = fields.One2many('test_new_api.message', 'discussion', domain=[('important', '=', True)]) very_important_messages = fields.One2many( 'test_new_api.message', 'discussion', domain=lambda self: self._domain_very_important()) emails = fields.One2many('test_new_api.emailmessage', 'discussion') important_emails = fields.One2many('test_new_api.emailmessage', 'discussion', domain=[('important', '=', True)]) def _domain_very_important(self): """Ensure computed O2M domains work as expected.""" return [("important", "=", True)] @api.onchange('name') def _onchange_name(self): # test onchange modifying one2many field values if self.env.context.get('generate_dummy_message' ) and self.name == '{generate_dummy_message}': # update body of existings messages and emails for message in self.messages: message.body = 'not last dummy message' for message in self.important_messages: message.body = 'not last dummy message' # add new dummy message message_vals = self.messages._add_missing_default_values({ 'body': 'dummy message', 'important': True }) self.messages |= self.messages.new(message_vals) self.important_messages |= self.messages.new(message_vals) @api.onchange('moderator') def _onchange_moderator(self): self.participants |= self.moderator @api.onchange('messages') def _onchange_messages(self): self.message_concat = "\n".join( ["%s:%s" % (m.name, m.body) for m in self.messages])
class ResPartner(models.Model): _inherit = 'res.partner' school_issue_ids = fields.One2many( string='School Issues', comodel_name='school.issue', inverse_name='student_id') school_claim_ids = fields.One2many( string='School Claims', comodel_name='school.claim', inverse_name='student_id') school_issue_count = fields.Integer( string='School Issue Count', compute='_compute_school_issue_count', store=True) school_claim_count = fields.Integer( string='School Claim Count', compute='_compute_school_claim_count', store=True) @api.multi @api.depends('school_issue_ids') def _compute_school_issue_count(self): for partner in self.filtered('school_issue_ids'): partner.school_issue_count = len(partner.school_issue_ids) @api.multi @api.depends('school_claim_ids') def _compute_school_claim_count(self): for partner in self.filtered('school_claim_ids'): partner.school_claim_count = len(partner.school_claim_ids) @api.multi def button_open_school_issues(self): self.ensure_one() action = self.env.ref('issue_education.action_school_issue') 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 @api.multi 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
class MaintenanceTeam(models.Model): _name = 'maintenance.team' _description = 'Maintenance Teams' name = fields.Char(required=True, translate=True) active = fields.Boolean(default=True) company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.user.company_id) member_ids = fields.Many2many('res.users', 'maintenance_team_users_rel', string="Team Members") color = fields.Integer("Color Index", default=0) request_ids = fields.One2many('maintenance.request', 'maintenance_team_id', copy=False) equipment_ids = fields.One2many('maintenance.equipment', 'maintenance_team_id', copy=False) # For the dashboard only todo_request_ids = fields.One2many('maintenance.request', string="Requests", copy=False, compute='_compute_todo_requests') todo_request_count = fields.Integer(string="Number of Requests", compute='_compute_todo_requests') todo_request_count_date = fields.Integer( string="Number of Requests Scheduled", compute='_compute_todo_requests') todo_request_count_high_priority = fields.Integer( string="Number of Requests in High Priority", compute='_compute_todo_requests') todo_request_count_block = fields.Integer( string="Number of Requests Blocked", compute='_compute_todo_requests') todo_request_count_unscheduled = fields.Integer( string="Number of Requests Unscheduled", compute='_compute_todo_requests') @api.one @api.depends('request_ids.stage_id.done') def _compute_todo_requests(self): self.todo_request_ids = self.request_ids.filtered( lambda e: e.stage_id.done == False) self.todo_request_count = len(self.todo_request_ids) self.todo_request_count_date = len( self.todo_request_ids.filtered(lambda e: e.schedule_date != False)) self.todo_request_count_high_priority = len( self.todo_request_ids.filtered(lambda e: e.priority == '3')) self.todo_request_count_block = len( self.todo_request_ids.filtered( lambda e: e.kanban_state == 'blocked')) self.todo_request_count_unscheduled = len( self.todo_request_ids.filtered(lambda e: not e.schedule_date)) @api.one @api.depends('equipment_ids') def _compute_equipment(self): self.equipment_count = len(self.equipment_ids)
class Fees_Structure(models.Model): """ Fees structure """ _name = 'fees.structure' _description = 'Fees Structure' name = fields.Char('Name',required=True) code = fields.Char('Code',required=True) course_id= fields.Many2one('course', string='Class', required=True) academic_year_id=fields.Many2one('batch','Academic Year') fee_line_ids = fields.One2many('fees.line','fees_id','Fees Lines') type=fields.Selection([('reg','Registration'),('academic','Academic')]) fee_history_line = fields.One2many('fee.history.line','fee_structure_id',string="Fee History") _sql_constraints = [ ('code_uniq','unique(code)', 'The code of the Fees Structure must be unique !') ] @api.onchange('type','course_id','academic_year_id') def name_code_generate(self): name = '' if self.course_id and self.academic_year_id and self.type: name = self.type.upper() + '/' +\ self.course_id.name+ '/' + \ self.academic_year_id.name self.name = name self.code = name @api.model def create(self,vals): old_rec=self.search([('type','=',vals['type']),('course_id','=',vals['course_id']),('academic_year_id','=',vals['academic_year_id'])]) if len(old_rec) != 0: raise except_orm(_('Warning!'), _("Fee structute already exist")) return super(Fees_Structure,self).create(vals) @api.multi def write(self,vals): if ('type' in vals) or ('course_id' in vals) or ('academic_year_id' in vals): if ('type' in vals): type=vals['type'] else: type=self.type if ('course_id' in vals): course_id=vals['course_id'] else: course_id=self.course_id.id if ('academic_year_id' in vals): academic_year_id=vals['academic_year_id'] else: academic_year_id=self.academic_year_id.id old_rec=self.search([('type','=',type),('course_id','=',course_id),('academic_year_id','=',academic_year_id)]) if len(old_rec) != 0: raise except_orm(_('Warning!'), _("Fee structute already exist")) return super(Fees_Structure,self).write(vals)
class One2ManyMultiple(models.Model): _name = 'export.one2many.multiple' _description = 'Export One To Many Multiple' parent_id = fields.Many2one('export.one2many.recursive') const = fields.Integer(default=36) child1 = fields.One2many('export.one2many.child.1', 'parent_id') child2 = fields.One2many('export.one2many.child.2', 'parent_id')
class EducationSubject(models.Model): _name = 'education.subject' _inherit = 'education.data' _description = 'Education Subject' min_description = fields.Char(string='Min. Description') type_id = fields.Many2one(comodel_name='education.subject.type', string='Type') subject_type = fields.Selection(selection=SUBJECT_TYPE, string='Subject Type', related='type_id.type', store=True) level_field_ids = fields.One2many( comodel_name='education.level.field.subject', inverse_name='subject_id', string='Fields by Level') level_course_ids = fields.One2many( comodel_name='education.level.course.subject', inverse_name='subject_id', string='Courses by Level') level_ids = fields.Many2many(comodel_name='education.level', string='Levels', compute='_compute_level_ids', store=True, relation='edu_subject_level') field_ids = fields.Many2many(comodel_name='education.field', string='Study Fields', compute='_compute_field_ids', store=True, relation='edu_subject_field') course_ids = fields.Many2many(comodel_name='education.course', string='Courses', compute='_compute_course_ids', store=True, relation='edu_subject_course') @api.depends('level_field_ids', 'level_field_ids.field_id') def _compute_field_ids(self): for record in self: record.field_ids = record.mapped('level_field_ids.field_id') @api.depends('level_field_ids', 'level_field_ids.level_id', 'level_course_ids', 'level_course_ids.level_id') def _compute_level_ids(self): for record in self: record.level_ids = (record.mapped('level_field_ids.level_id') | record.mapped('level_course_ids.level_id')) @api.depends('level_course_ids', 'level_course_ids.course_id') def _compute_course_ids(self): for record in self: record.course_ids = record.mapped('level_course_ids.course_id') _sql_constraints = [ ('education_code_unique', 'unique(education_code)', 'Education code must be unique!'), ]
class EmployeePublic(models.Model): _inherit = 'hr.employee.public' resume_line_ids = fields.One2many('hr.resume.line', 'employee_id', string="Resumé lines") employee_skill_ids = fields.One2many('hr.employee.skill', 'employee_id', string="Skills")
class ProductProduct(models.Model): _inherit = "product.product" variant_bom_ids = fields.One2many('mrp.bom', 'product_id', 'BOM Product Variants') bom_line_ids = fields.One2many('mrp.bom.line', 'product_id', 'BoM Components') bom_count = fields.Integer('# Bill of Material', compute='_compute_bom_count') used_in_bom_count = fields.Integer('# BoM Where Used', compute='_compute_used_in_bom_count') mrp_product_qty = fields.Float('Manufactured', compute='_compute_mrp_product_qty') def _compute_bom_count(self): for product in self: product.bom_count = self.env['mrp.bom'].search_count(['|', ('product_id', '=', product.id), '&', ('product_id', '=', False), ('product_tmpl_id', '=', product.product_tmpl_id.id)]) @api.multi def _compute_used_in_bom_count(self): for product in self: product.used_in_bom_count = self.env['mrp.bom'].search_count([('bom_line_ids.product_id', '=', product.id)]) @api.multi def action_used_in_bom(self): self.ensure_one() action = self.env.ref('mrp.mrp_bom_form_action').read()[0] action['domain'] = [('bom_line_ids.product_id', '=', self.id)] return action def _compute_mrp_product_qty(self): date_from = fields.Datetime.to_string(fields.datetime.now() - timedelta(days=365)) #TODO: state = done? domain = [('state', '=', 'done'), ('product_id', 'in', self.ids), ('date_planned_start', '>', date_from)] read_group_res = self.env['mrp.production'].read_group(domain, ['product_id', 'product_uom_qty'], ['product_id']) mapped_data = dict([(data['product_id'][0], data['product_uom_qty']) for data in read_group_res]) for product in self: product.mrp_product_qty = float_round(mapped_data.get(product.id, 0), precision_rounding=product.uom_id.rounding) @api.multi def action_view_bom(self): action = self.env.ref('mrp.product_open_bom').read()[0] template_ids = self.mapped('product_tmpl_id').ids # bom specific to this variant or global to template action['context'] = { 'default_product_tmpl_id': template_ids[0], 'default_product_id': self.ids[0], } action['domain'] = ['|', ('product_id', 'in', self.ids), '&', ('product_id', '=', False), ('product_tmpl_id', 'in', template_ids)] return action @api.multi def action_view_mos(self): action = self.env.ref('mrp.mrp_production_report').read()[0] action['domain'] = [('state', '=', 'done'), ('product_id', 'in', self.ids)] action['context'] = { 'search_default_last_year_mo_order': 1, 'search_default_status': 1, 'search_default_scheduled_month': 1, 'graph_measure': 'product_uom_qty', } return action
class ModuleCategory(models.Model): _name = "ir.module.category" _description = "Application" _order = 'name' @api.depends('module_ids') def _compute_module_nr(self): cr = self._cr cr.execute( 'SELECT category_id, COUNT(*) \ FROM ir_module_module \ WHERE category_id IN %(ids)s \ OR category_id IN (SELECT id \ FROM ir_module_category \ WHERE parent_id IN %(ids)s) \ GROUP BY category_id', {'ids': tuple(self.ids)}) result = dict(cr.fetchall()) for cat in self.filtered('id'): cr.execute('SELECT id FROM ir_module_category WHERE parent_id=%s', (cat.id, )) cat.module_nr = sum([result.get(c, 0) for (c, ) in cr.fetchall()], result.get(cat.id, 0)) name = fields.Char(string='Name', required=True, translate=True, index=True) parent_id = fields.Many2one('ir.module.category', string='Parent Application', index=True) child_ids = fields.One2many('ir.module.category', 'parent_id', string='Child Applications') module_nr = fields.Integer(string='Number of Apps', compute='_compute_module_nr') module_ids = fields.One2many('ir.module.module', 'category_id', string='Modules') description = fields.Text(string='Description', translate=True) sequence = fields.Integer(string='Sequence') visible = fields.Boolean(string='Visible', default=True) exclusive = fields.Boolean(string='Exclusive') xml_id = fields.Char(string='External ID', compute='_compute_xml_id') def _compute_xml_id(self): xml_ids = defaultdict(list) domain = [('model', '=', self._name), ('res_id', 'in', self.ids)] for data in self.env['ir.model.data'].sudo().search_read( domain, ['module', 'name', 'res_id']): xml_ids[data['res_id']].append("%s.%s" % (data['module'], data['name'])) for cat in self: cat.xml_id = xml_ids.get(cat.id, [''])[0]
class Product_Discount_Category(models.Model): _name = 'discount.category' name = fields.Char('Name') code = fields.Char('Code') discount_category_line = fields.One2many('discount.category.line', 'discount_category_id', string='Discount Line') discount_history_line = fields.One2many('discount.history.line', 'discount_category_id', string='Discount History Line')
class ResPartner(models.Model): _inherit = 'res.partner' student_meeting_ids = fields.One2many( comodel_name='calendar.event', inverse_name='student_id', string='Tutoring meetings (student)') student_count_meetings = fields.Integer( string='# Tutoring meetings (student)', compute='_compute_student_count_meetings') family_meeting_ids = fields.One2many( comodel_name='calendar.event', inverse_name='family_id', string='Tutoring meetings (family)') family_count_meetings = fields.Integer( string='# Tutoring meetings (family)', compute='_compute_family_count_meetings') def _compute_student_count_meetings(self): calendar_obj = self.env['calendar.event'] for partner in self: partner.student_count_meetings = calendar_obj.search_count([ ('student_id', '=', partner.id)]) def _compute_family_count_meetings(self): calendar_obj = self.env['calendar.event'] for partner in self: partner.family_count_meetings = calendar_obj.search_count([ ('family_id', '=', partner.id)]) @api.multi 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
class SkillType(models.Model): _name = 'hr.skill.type' _description = "Skill Type" name = fields.Char(required=True) skill_ids = fields.One2many('hr.skill', 'skill_type_id', string="Skills", ondelete='cascade') skill_level_ids = fields.One2many('hr.skill.level', 'skill_type_id', string="Levels", ondelete='cascade')
class ProductAttribute(models.Model): _name = "product.attribute" _description = "Product Attribute" # if you change this _order, keep it in sync with the method # `_sort_key_attribute_value` in `product.template` _order = 'sequence, id' name = fields.Char('Attribute', required=True, translate=True) value_ids = fields.One2many('product.attribute.value', 'attribute_id', 'Values', copy=True) sequence = fields.Integer('Sequence', help="Determine the display order", index=True) attribute_line_ids = fields.One2many('product.template.attribute.line', 'attribute_id', 'Lines') create_variant = fields.Selection([ ('no_variant', 'Never'), ('always', 'Always'), ('dynamic', 'Only when the product is added to a sales order')], default='always', string="Create Variants", help="Check this if you want to create multiple variants for this attribute.", required=True) @api.multi def _without_no_variant_attributes(self): return self.filtered(lambda pa: pa.create_variant != 'no_variant') @api.multi def write(self, vals): """Override to make sure attribute type can't be changed if it's used on a product template. This is important to prevent because changing the type would make existing combinations invalid without recomputing them, and recomputing them might take too long and we don't want to change products without the user knowing about it.""" if 'create_variant' in vals: products = self._get_related_product_templates() if products: message = ', '.join(products.mapped('name')) raise UserError(_('You are trying to change the type of an attribute value still referenced on at least one product template: %s') % message) invalidate_cache = 'sequence' in vals and any(record.sequence != vals['sequence'] for record in self) res = super(ProductAttribute, self).write(vals) if invalidate_cache: # prefetched o2m have to be resequenced # (eg. product.template: attribute_line_ids) self.invalidate_cache() return res @api.multi def _get_related_product_templates(self): return self.env['product.template'].with_context(active_test=False).search([ ('attribute_line_ids.attribute_id', 'in', self.ids), ])
class OpStudent(models.Model): _inherit = "op.student" fees_detail_ids = fields.One2many('op.student.fees.details', 'student_id', string='Fees Collection Details', track_visibility='onchange') def action_view_invoice(self): ''' This function returns an action that display existing invoices of given student ids and show a invoice" ''' result = self.env.ref('account.action_move_out_invoice_type') fees = result and result.id or False result = self.env['ir.actions.act_window'].browse(fees).read()[0] inv_ids = [] for student in self: inv_ids += [invoice.id for invoice in student.invoice_ids] result['context'] = {'default_partner_id': student.partner_id.id} if len(inv_ids) > 1: result['domain'] = \ "[('id','in',[" + ','.join(map(str, inv_ids)) + "])]" else: res = self.env.ref('account.view_move_form') result['views'] = [(res and res.id or False, 'form')] result['res_id'] = inv_ids and inv_ids[0] or False return result
class AccountPaymentMethod(models.Model): _inherit = 'account.payment.method' code = fields.Char( string='Code (Do Not Modify)', help="This code is used in the code of the Eagle module that handles " "this payment method. Therefore, if you change it, " "the generation of the payment file may fail.") active = fields.Boolean(string='Active', default=True) bank_account_required = fields.Boolean( string='Bank Account Required', help="Activate this option if this payment method requires you to " "know the bank account number of your customer or supplier.") payment_mode_ids = fields.One2many(comodel_name='account.payment.mode', inverse_name='payment_method_id', string='Payment modes') @api.multi @api.depends('code', 'name', 'payment_type') def name_get(self): result = [] for method in self: result.append((method.id, u'[%s] %s (%s)' % (method.code, method.name, method.payment_type))) return result _sql_constraints = [ ('code_payment_type_unique', 'unique(code, payment_type)', 'A payment method of the same type already exists with this code') ]
class SMSGateway(models.Model): _name = "eagle.smsgateway" name = fields.Char("SMS Gateway Provider") model_id = fields.Char("Model Name") parameter_ids = fields.One2many('eagle.smsgateway.parameters', "sms_gateway_id", "Parameters") _sql_constraints = [ ('model_id_unique', 'unique(model_id)', 'SMS model Must Be Unique'), ('getway_name_unique', 'unique(name)', 'SMS Provider Must Be Unique'), ] # base_endpoint=fields.Char("Base EndPoint") # api_key=fields.Char("API Key") # def __init__(self, "api_key"): # self.api_key = api_key @api.multi def _get_headers(self): return {'Authorization': self.api_key} @api.multi def _make_post(self, endpoint, body): url = self.base_endpoint + endpoint return requests.post(url, json=body, headers=self._get_headers()).json() def _make_get(self, endpoint): url = self.base_endpoint + endpoint return requests.get(url, headers=self._get_headers()).json()
class ks_brand(models.Model): _name = 'ks_product_manager.ks_brand' _description = 'Ks Model' """This model is create brand and their info""" name = fields.Char(string='Brand Name', required='true') ks_image = fields.Binary(string='Image') ks_product_ids = fields.One2many('product.template', 'ks_product_brand_id', widget='binary') ks_products_count = fields.Integer(string='Number of products', compute='ks_get_products_count') ks_brand_discount = fields.Integer(string='Discount Percentage') ks_brand_logo = fields.Binary(string='Brand Logo', widget='binary') ks_brand_url = fields.Char(invisible=True) ks_is_checked_on_shop = fields.Boolean(default=False) ks_is_published = fields.Boolean(default=False, string="Published") # @api.multi @api.depends('ks_product_ids') def ks_get_products_count(self): """This method is used to count no. of product under a brand""" for brand in self: brand.ks_products_count = len(brand.ks_product_ids) # @api.multi def ks_get_brand_url(self, name): for rec in self: base_url = rec.env['ir.config_parameter'].sudo().get_param( 'web.base.url') if rec.name: return 'shop?filter=' + str(name) else: return ""
class SaleOrderLine(models.Model): _inherit = "sale.order.line" name_short = fields.Char(compute="_compute_name_short") linked_line_id = fields.Many2one('sale.order.line', string='Linked Order Line', domain="[('order_id', '!=', order_id)]", ondelete='cascade') option_line_ids = fields.One2many('sale.order.line', 'linked_line_id', string='Options Linked') @api.multi @api.depends('product_id.display_name') def _compute_name_short(self): """ Compute a short name for this sale order line, to be used on the website where we don't have much space. To keep it short, instead of using the first line of the description, we take the product name without the internal reference. """ for record in self: record.name_short = record.product_id.with_context( display_default_code=False).display_name def get_description_following_lines(self): return self.name.splitlines()[1:]
class Event(models.Model): _inherit = 'event.event' event_ticket_ids = fields.One2many( 'event.event.ticket', 'event_id', string='Event Ticket', copy=True) @api.onchange('event_type_id') def _onchange_type(self): super(Event, self)._onchange_type() if self.event_type_id.use_ticketing: self.event_ticket_ids = [(5, 0, 0)] + [ (0, 0, { 'name': self.name and _('Registration for %s') % self.name or ticket.name, 'product_id': ticket.product_id.id, 'price': ticket.price, }) for ticket in self.event_type_id.event_ticket_ids] @api.multi def _is_event_registrable(self): self.ensure_one() if not self.event_ticket_ids: return True return all(self.event_ticket_ids.with_context(active_test=False).mapped(lambda t: t.product_id.active))
class CODPaymentTransaction(models.Model): _name = 'cod.config' name = fields.Char('Name', required=True) min_amt = fields.Float('Minimum Order Amount', required=True) max_amt = fields.Float('Maximum Order Amount', required=True) excl_product = fields.Many2many('product.template', string="COD Unavailable for the Products") cod_msg = fields.Char("COD Availability Alert") delivery_date = fields.Boolean('Display Expected Delivery Date') exp_delivery_interval = fields.Integer('Expected Delivery Interval') cod_unavailable_msg = fields.Char('COD Unavailable Message') cod_unavailable_msg_payment = fields.Char( 'COD Unavailable Message Payment') cod_poilicy = fields.Text("COD Policy") cod_state = fields.Many2many("res.country.state", string="Allow States") cod_zip = fields.One2many('res.zip', 'cod_id', 'Allow Zip') @api.model def create(self, value): cod = super(CODPaymentTransaction, self).create(value) for products in cod.excl_product: products.update({'cod_available': False}) return cod @api.multi def write(self, value): cod = super(CODPaymentTransaction, self).write(value) for products in self.excl_product: products.update({'cod_available': False}) return cod
class SaleOrderLine(models.Model): _inherit = "sale.order.line" purchase_line_ids = fields.One2many('purchase.order.line', 'sale_line_id') def _get_qty_procurement(self, previous_product_uom_qty): # People without purchase rights should be able to do this operation purchase_lines_sudo = self.sudo().purchase_line_ids if purchase_lines_sudo.filtered(lambda r: r.state != 'cancel'): qty = 0.0 for po_line in purchase_lines_sudo.filtered( lambda r: r.state != 'cancel'): qty += po_line.product_uom._compute_quantity( po_line.product_qty, self.product_uom, rounding_method='HALF-UP') return qty else: return super(SaleOrderLine, self)._get_qty_procurement( previous_product_uom_qty=previous_product_uom_qty) def _compute_is_mto(self): super(SaleOrderLine, self)._compute_is_mto() for line in self: if not line.display_qty_widget or line.is_mto: continue product_routes = line.route_id or ( line.product_id.route_ids + line.product_id.categ_id.total_route_ids) for pull_rule in product_routes.mapped('rule_ids'): if pull_rule.picking_type_id.sudo().default_location_src_id.usage == 'supplier' and\ pull_rule.picking_type_id.sudo().default_location_dest_id.usage == 'customer': line.is_mto = True break
class CountryState(models.Model): _inherit = 'res.country.state' city_ids = fields.One2many('res.city','state_id') def get_website_sale_cities(self, mode='billing'): return self.sudo().city_ids
class ResCompany(models.Model): _inherit = 'res.company' resource_calendar_ids = fields.One2many( 'resource.calendar', 'company_id', 'Working Hours') resource_calendar_id = fields.Many2one( 'resource.calendar', 'Default Working Hours', ondelete='restrict') @api.model def _init_data_resource_calendar(self): self.search([('resource_calendar_id', '=', False)])._create_resource_calendar() def _create_resource_calendar(self): for company in self: company.resource_calendar_id = self.env['resource.calendar'].create({ 'name': _('Standard 40 hours/week'), 'company_id': company.id }).id @api.model def create(self, values): company = super(ResCompany, self).create(values) if not company.resource_calendar_id: company.sudo()._create_resource_calendar() # calendar created from form view: no company_id set because record was still not created if not company.resource_calendar_id.company_id: company.resource_calendar_id.company_id = company.id return company
class EventType(models.Model): _inherit = 'event.type' @api.model def _get_default_event_ticket_ids(self): product = self.env.ref('event_sale.product_product_event', raise_if_not_found=False) if not product: return False return [(0, 0, { 'name': _('Registration'), 'product_id': product.id, 'price': 0, })] use_ticketing = fields.Boolean('Ticketing') event_ticket_ids = fields.One2many( 'event.event.ticket', 'event_type_id', string='Tickets', default=_get_default_event_ticket_ids) @api.onchange('name') def _onchange_name(self): if self.name: self.event_ticket_ids.filtered(lambda ticket: ticket.name == _('Registration')).update({ 'name': _('Registration for %s') % self.name })