class AccountTaxTemplatePython(models.Model): _inherit = 'account.tax.template' amount_type = fields.Selection(selection_add=[('code', 'Python Code')]) python_compute = fields.Text( string='Python Code', default="result = price_unit * 0.10", help= "Compute the amount of the tax by setting the variable 'result'.\n\n" ":param base_amount: float, actual amount on which the tax is applied\n" ":param price_unit: float\n" ":param quantity: float\n" ":param product: product.product recordset singleton or None\n" ":param partner: res.partner recordset singleton or None") python_applicable = fields.Text( string='Applicable Code', default="result = True", help= "Determine if the tax will be applied by setting the variable 'result' to True or False.\n\n" ":param price_unit: float\n" ":param quantity: float\n" ":param product: product.product recordset singleton or None\n" ":param partner: res.partner recordset singleton or None") def _get_tax_vals(self, company, tax_template_to_tax): """ This method generates a dictionnary of all the values for the tax that will be created. """ self.ensure_one() res = super(AccountTaxTemplatePython, self)._get_tax_vals(company, tax_template_to_tax) res['python_compute'] = self.python_compute res['python_applicable'] = self.python_applicable return res
class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' gengo_private_key = fields.Text(string="Gengo Private Key", related="company_id.gengo_private_key", readonly=False) gengo_public_key = fields.Text(string="Gengo Public Key", related="company_id.gengo_public_key", readonly=False) gengo_comment = fields.Text( string="Comments", related="company_id.gengo_comment", help= "This comment will be automatically be enclosed in each an every request sent to Gengo" ) gengo_auto_approve = fields.Boolean( string="Auto Approve Translation ?", related="company_id.gengo_auto_approve", readonly=False, help="Jobs are Automatically Approved by Gengo.") gengo_sandbox = fields.Boolean( string="Sandbox Mode", related="company_id.gengo_sandbox", readonly=False, help= "Check this box if you're using the sandbox mode of Gengo, mainly used for testing purpose." )
class res_company(models.Model): _inherit = "res.company" gengo_private_key = fields.Text(string="Gengo Private Key", copy=False, groups="base.group_system") gengo_public_key = fields.Text(string="Gengo Public Key", copy=False, groups="base.group_user") gengo_comment = fields.Text( string="Comments", groups="base.group_user", help= "This comment will be automatically be enclosed in each an every request sent to Gengo" ) gengo_auto_approve = fields.Boolean( string="Auto Approve Translation ?", groups="base.group_user", default=True, help="Jobs are Automatically Approved by Gengo.") gengo_sandbox = fields.Boolean( string="Sandbox Mode", help= "Check this box if you're using the sandbox mode of Gengo, mainly used for testing purpose." )
class ResPartnerPermission(models.Model): _name = 'res.partner.permission' _inherit = ['portal.mixin', 'mail.thread', 'mail.activity.mixin'] _description = 'Contact Permission' _rec_name = 'partner_id' partner_id = fields.Many2one(comodel_name='res.partner', string='Student', required=True, domain=[('educational_category', 'in', ('student', 'other'))]) allowed_signer_ids = fields.Many2many( comodel_name='res.partner', string='Allowed Signers', compute='_compute_allowed_signer_ids', store=True) signer_id = fields.Many2one(comodel_name='res.partner', string='Signed by', domain="[('id', 'in', allowed_signer_ids)]") type_id = fields.Many2one(comodel_name='res.partner.permission.type', string='Type', required=True) type_description = fields.Text(string='Type Description', related='type_id.description', store=True) description = fields.Text(string='Description') state = fields.Selection(selection=[('yes', 'Yes'), ('no', 'No'), ('pending', 'Pending')], string='State', default='pending', required=True) start_date = fields.Date(string='Start Date') end_date = fields.Date(string='End Date') attachment_doc = fields.Binary(string='Attached Document') @api.depends('partner_id', 'partner_id.child2_ids', 'partner_id.child2_ids.relation', 'partner_id.child2_ids.responsible_id') def _compute_allowed_signer_ids(self): for record in self: record.allowed_signer_ids = ( record.partner_id.child2_ids.filtered(lambda l: l.relation in ( 'progenitor', 'guardian')).mapped('responsible_id')) def button_sign(self): self.ensure_one() self.write({ 'state': 'yes', 'signer_id': self.env.user.partner_id.id, }) def button_deny(self): self.ensure_one() self.write({ 'state': 'no', 'signer_id': self.env.user.partner_id.id, })
class pos_cache(models.Model): _name = 'pos.cache' _description = 'Point of Sale Cache' cache = fields.Binary(attachment=True) product_domain = fields.Text(required=True) product_fields = fields.Text(required=True) config_id = fields.Many2one('pos.config', ondelete='cascade', required=True) compute_user_id = fields.Many2one('res.users', 'Cache compute user', required=True) @api.model def refresh_all_caches(self): self.env['pos.cache'].search([]).refresh_cache() @api.one def refresh_cache(self): Product = self.env['product.product'].sudo(self.compute_user_id.id) products = Product.search(self.get_product_domain()) prod_ctx = products.with_context( pricelist=self.config_id.pricelist_id.id, display_default_code=False, lang=self.compute_user_id.lang) res = prod_ctx.read(self.get_product_fields()) datas = { 'cache': base64.encodestring(json.dumps(res).encode('utf-8')), } self.write(datas) @api.model def get_product_domain(self): return literal_eval(self.product_domain) @api.model def get_product_fields(self): return literal_eval(self.product_fields) @api.model def get_cache(self, domain, fields): if not self.cache or domain != self.get_product_domain( ) or fields != self.get_product_fields(): self.product_domain = str(domain) self.product_fields = str(fields) self.refresh_cache() return json.loads(base64.decodestring(self.cache).decode('utf-8'))
class AccountingAssertTest(models.Model): _name = "accounting.assert.test" _description = 'Accounting Assert Test' _order = "sequence" name = fields.Char(string='Test Name', required=True, index=True, translate=True) desc = fields.Text(string='Test Description', index=True, translate=True) code_exec = fields.Text(string='Python code', required=True, default=CODE_EXEC_DEFAULT) active = fields.Boolean(default=True) sequence = fields.Integer(default=10)
class grant_badge_wizard(models.TransientModel): """ Wizard allowing to grant a badge to a user""" _name = 'gamification.badge.user.wizard' _description = 'Gamification User Badge Wizard' user_id = fields.Many2one("res.users", string='User', required=True) badge_id = fields.Many2one("gamification.badge", string='Badge', required=True) comment = fields.Text('Comment') @api.multi def action_grant_badge(self): """Wizard action for sending a badge to a chosen user""" BadgeUser = self.env['gamification.badge.user'] uid = self.env.uid for wiz in self: if uid == wiz.user_id.id: raise exceptions.UserError(_('You can not grant a badge to yourself.')) #create the badge BadgeUser.create({ 'user_id': wiz.user_id.id, 'sender_id': uid, 'badge_id': wiz.badge_id.id, 'comment': wiz.comment, })._send_badge() return True
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 LunchProduct(models.Model): """ Products available to order. A product is linked to a specific vendor. """ _name = 'lunch.product' _description = 'Lunch Product' _inherit = 'image.mixin' _order = 'name' name = fields.Char('Product Name', required=True) category_id = fields.Many2one('lunch.product.category', 'Product Category', required=True) description = fields.Text('Description') price = fields.Float('Price', digits='Account', required=True) supplier_id = fields.Many2one('lunch.supplier', 'Vendor', required=True) active = fields.Boolean(default=True) company_id = fields.Many2one('res.company', related='supplier_id.company_id', store=True) currency_id = fields.Many2one('res.currency', related='company_id.currency_id') new_until = fields.Date('New Until') favorite_user_ids = fields.Many2many('res.users', 'lunch_product_favorite_user_rel', 'product_id', 'user_id')
class OpFeesTerms(models.Model): _name = "op.fees.terms" _inherit = "mail.thread" _description = "Fees Terms For Course" name = fields.Char('Fees Terms', required=True) active = fields.Boolean('Active', default=True) note = fields.Text('Description') company_id = fields.Many2one('res.company', 'Company', required=True, default=lambda s: s.env.user.company_id) no_days = fields.Integer('No of Days') day_type = fields.Selection([('before', 'Before'), ('after', 'After')], 'Type') line_ids = fields.One2many('op.fees.terms.line', 'fees_id', 'Terms') @api.model def create(self, vals): res = super(OpFeesTerms, self).create(vals) if not res.line_ids: raise exceptions.AccessError(_("Fees Terms must be Required!")) total = 0.0 for line in res.line_ids: if line.value: total += line.value if total != 100.0: raise exceptions.AccessError( _("Fees terms must be divided as such sum up in 100%")) return res
class lc_bank_branch_address(models.Model): _name = 'lc_bank_names_branch_address.model' name = fields.Char(compute='concatenate_custom_fields', store=True, string='Name') bank_name = fields.Char(required=True, string='Bank Name') bank_branch = fields.Char(required=True, string='Bank Branch') bank_address = fields.Text(required=True, string='Bank Address') created_date = fields.Date('Created Dated', default=fields.Date.today()) s_code = fields.Char(string='Swift Code') bank_short = fields.Char(string='Bank Short') @api.depends('bank_name', 'bank_branch', 'bank_address', 's_code') def concatenate_custom_fields(self): b_n = str(self.bank_name) b_brunch = str(self.bank_branch) b_addr = str(self.bank_address) # b_s_code = str(self.s_code) concate_name = b_n + ', ' + b_brunch + ', ' + b_addr if self.s_code: concate_name = b_n + ', ' + b_brunch + ', ' + b_addr + ', Swift Code: ' + str( self.s_code) else: concate_name = b_n + ', ' + b_brunch + ', ' + b_addr self.name = concate_name
class OpExamAttendees(models.Model): _name = "op.exam.attendees" _rec_name = "student_id" _description = "Exam Attendees" student_id = fields.Many2one('op.student', 'Student', required=True) status = fields.Selection( [('present', 'Present'), ('absent', 'Absent')], 'Status', default="present", required=True) marks = fields.Integer('Marks') note = fields.Text('Note') exam_id = fields.Many2one( 'op.exam', 'Exam', required=True, ondelete="cascade") course_id = fields.Many2one('op.course', 'Course', readonly=True) batch_id = fields.Many2one('op.batch', 'Batch', readonly=True) room_id = fields.Many2one('op.exam.room', 'Room') _sql_constraints = [ ('unique_attendees', 'unique(student_id,exam_id)', 'Attendee must be unique per exam.'), ] @api.onchange('exam_id') def onchange_exam(self): self.course_id = self.exam_id.session_id.course_id self.batch_id = self.exam_id.session_id.batch_id self.student_id = False @api.constrains('marks') def _check_marks(self): if self.marks < 0.0: raise ValidationError(_("Enter proper marks!"))
class EagleeduAcademicYear(models.Model): _name = 'eagleedu.academic.year' _description = 'Year Information' _rec_name = 'name' name = fields.Char(string='Year Name', required=True, help='Name of academic year') academic_year_description = fields.Text( string='Description', help="Description about the academic year") active = fields.Boolean( 'Active', default=True, help= "If unchecked, it will allow you to hide the Year Information without removing it." ) @api.model def create(self, vals): """Over riding the create method and assigning the sequence for the newly creating record""" vals['sequence'] = self.env['ir.sequence'].next_by_code( 'eagleedu.academic.year') res = super(EagleeduAcademicYear, self).create(vals) 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 LunchCashMove(models.Model): """ Two types of cashmoves: payment (credit) or order (debit) """ _name = 'lunch.cashmove' _description = 'Lunch Cashmove' _order = 'date desc' currency_id = fields.Many2one( 'res.currency', default=lambda self: self.env.company.currency_id) user_id = fields.Many2one('res.users', 'User', default=lambda self: self.env.uid) date = fields.Date('Date', required=True, default=fields.Date.context_today) amount = fields.Float('Amount', required=True) description = fields.Text('Description') def name_get(self): return [(cashmove.id, '%s %s' % (_('Lunch Cashmove'), '#%d' % cashmove.id)) for cashmove in self] @api.model def get_wallet_balance(self, user, include_config=True): result = float_round(sum( move['amount'] for move in self.env['lunch.cashmove.report'].search_read([( 'user_id', '=', user.id)], ['amount'])), precision_digits=2) if include_config: result += user.company_id.lunch_minimum_threshold return result
class RecruitmentStage(models.Model): _name = "hr.recruitment.stage" _description = "Recruitment Stages" _order = 'sequence' name = fields.Char("Stage name", required=True, translate=True) sequence = fields.Integer( "Sequence", default=10, help="Gives the sequence order when displaying a list of stages.") job_id = fields.Many2one('hr.job', string='Job Specific', ondelete='cascade', help='Specific job that uses this stage. Other jobs will not use this stage.') requirements = fields.Text("Requirements") template_id = fields.Many2one( 'mail.template', "Automated Email", 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.") legend_blocked = fields.Char( 'Red Kanban Label', default=lambda self: _('Blocked'), translate=True, required=True) legend_done = fields.Char( 'Green Kanban Label', default=lambda self: _('Ready for Next Stage'), translate=True, required=True) legend_normal = fields.Char( 'Grey Kanban Label', default=lambda self: _('In Progress'), translate=True, required=True) @api.model def default_get(self, fields): if self._context and self._context.get('default_job_id') and not self._context.get('hr_recruitment_stage_mono', False): context = dict(self._context) context.pop('default_job_id') self = self.with_context(context) return super(RecruitmentStage, self).default_get(fields)
class SchoolIssueProof(models.Model): _name = 'school.issue.proof' _inherit = ['portal.mixin', 'mail.thread', 'mail.activity.mixin'] _description = 'Issue Proof' name = fields.Char(string='Description', required=True) student_id = fields.Many2one( comodel_name='res.partner', name='Student', required=True, domain=[('educational_category', '=', 'student')]) allowed_partner_ids = fields.Many2many( comodel_name='res.partner', relation='rel_proof_progenitor', column1='proof_id', column2='progenitor_id', compute='_compute_progenitor_ids', store=True) person_id = fields.Many2one( comodel_name='res.partner', name='Progenitor/Tutor') date_from = fields.Datetime(string='Date From') date_to = fields.Datetime(string='Date To') college_issue_type_id = fields.Many2one( comodel_name='school.college.issue.type', string='Issue Type') school_id = fields.Many2one( comodel_name='res.partner', name='Education Center', related='college_issue_type_id.school_id', store=True) issue_ids = fields.One2many( comodel_name='school.issue', inverse_name='proof_id', string='Issues') notes = fields.Text(string='Notes') @api.depends('student_id', 'student_id.child2_ids', 'student_id.child2_ids.relation', 'student_id.child2_ids.responsible_id') def _compute_progenitor_ids(self): for proof in self: proof.allowed_partner_ids = proof.student_id.child2_ids.filtered( lambda f: f.relation == 'progenitor').mapped('responsible_id')
class ConverterTest(models.Model): _name = 'web_editor.converter.test' _description = 'Web Editor Converter Test' # disable translation export for those brilliant field labels and values _translate = False char = fields.Char() integer = fields.Integer() float = fields.Float() numeric = fields.Float(digits=(16, 2)) many2one = fields.Many2one('web_editor.converter.test.sub') binary = fields.Binary() date = fields.Date() datetime = fields.Datetime() selection = fields.Selection([ (1, "réponse A"), (2, "réponse B"), (3, "réponse C"), (4, "réponse <D>"), ]) selection_str = fields.Selection( [ ('A', "Qu'il n'est pas arrivé à Toronto"), ('B', "Qu'il était supposé arriver à Toronto"), ('C', "Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?"), ('D', "La réponse D"), ], string=u"Lorsqu'un pancake prend l'avion à destination de Toronto et " u"qu'il fait une escale technique à St Claude, on dit:") html = fields.Html() text = fields.Text()
class ResPartnerPermissionType(models.Model): _name = 'res.partner.permission.type' _description = 'Permission Type' name = fields.Char(string='Name') description = fields.Text(string='Description') admission_default = fields.Boolean(string='Default in Admission')
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 CODPaymentCollection(models.Model): _name = 'cod.payment.collection' _rec_name = 'sale_order_id' sale_order_id = fields.Many2one('sale.order', 'Sale Order') transaction_id = fields.Many2one('payment.transaction', 'Transaction') partner_id = fields.Many2one('res.partner', 'Customer') delivery_person_id = fields.Many2one('res.partner', 'Delivery Company/Person') order_amt = fields.Float("Order Amount") collection_amt = fields.Float("Collection Amount", required=True) company_id = fields.Many2one('res.company', 'Company') state = fields.Selection([('draft', 'Draft'), ('confirm', 'Confirmed'), ('done', 'Done')], default='draft', string='State') notes = fields.Text('Notes') def confirm_collection(self): self.update({'state': 'confirm'}) def done_collection(self): self.update({'state': 'done'}) @api.onchange('sale_order_id') def cod_collection_data_update(self): if self.sale_order_id: self.update({ 'transaction_id': self.sale_order_id.payment_tx_id, 'partner_id': self.sale_order_id.partner_id, 'order_amt': self.sale_order_id.amount_total, 'company_id': self.sale_order_id.partner_id.company_id, })
class test_model(models.Model): _name = 'test_converter.test_model' _description = 'Test Converter Model' char = fields.Char() integer = fields.Integer() float = fields.Float() numeric = fields.Float(digits=(16, 2)) many2one = fields.Many2one('test_converter.test_model.sub', group_expand='_gbf_m2o') binary = fields.Binary(attachment=False) date = fields.Date() datetime = fields.Datetime() selection_str = fields.Selection( [ ('A', u"Qu'il n'est pas arrivé à Toronto"), ('B', u"Qu'il était supposé arriver à Toronto"), ('C', u"Qu'est-ce qu'il fout ce maudit pancake, tabernacle ?"), ('D', u"La réponse D"), ], string=u"Lorsqu'un pancake prend l'avion à destination de Toronto et " u"qu'il fait une escale technique à St Claude, on dit:") html = fields.Html() text = fields.Text() # `base` module does not contains any model that implement the functionality # `group_expand`; test this feature here... @api.model def _gbf_m2o(self, subs, domain, order): sub_ids = subs._search([], order=order, access_rights_uid=SUPERUSER_ID) return subs.browse(sub_ids)
class Rating(models.Model): _inherit = 'rating.rating' # Add this related field to mail.message for performance reason website_published = fields.Boolean(related='message_id.website_published', store=True, readonly=False) # Adding information for comment a rating message publisher_comment = fields.Text("Publisher Comment") publisher_id = fields.Many2one('res.partner', 'Commented by', ondelete='set null', readonly=True) publisher_datetime = fields.Datetime("Commented on", readonly=True) def write(self, values): if values.get('publisher_comment'): if not self.env.user.has_group("website.group_website_publisher"): raise exceptions.AccessError( _("Only the publisher of the website can change the rating comment" )) if not values.get('publisher_datetime'): values['publisher_datetime'] = fields.Datetime.now() if not values.get('publisher_id'): values['publisher_id'] = self.env.user.partner_id.id return super(Rating, self).write(values)
class AccountAnalyticGroup(models.Model): _name = 'account.analytic.group' _description = 'Analytic Categories' _parent_store = True _rec_name = 'complete_name' name = fields.Char(required=True) description = fields.Text(string='Description') parent_id = fields.Many2one( 'account.analytic.group', string="Parent", ondelete='cascade', domain= "['|', ('company_id', '=', False), ('company_id', '=', company_id)]") parent_path = fields.Char(index=True) children_ids = fields.One2many('account.analytic.group', 'parent_id', string="Childrens") complete_name = fields.Char('Complete Name', compute='_compute_complete_name', store=True) company_id = fields.Many2one('res.company', string='Company', default=lambda self: self.env.company) @api.depends('name', 'parent_id.complete_name') def _compute_complete_name(self): for group in self: if group.parent_id: group.complete_name = '%s / %s' % ( group.parent_id.complete_name, group.name) else: group.complete_name = group.name
class HrEmployee(models.Model): _inherit = "hr.employee" include_inourteam = fields.Boolean(string="Enable to make the employee visible in snippet") emp_social_twitter = fields.Char(string="Twitter account", default="https://twitter.com/Eagle", translate=True) emp_social_facebook = fields.Char( string="Facebook account", default="https://www.facebook.com/Eagle", translate=True) emp_social_linkdin = fields.Char( string="Linkedin account", default="https://www.linkedin.com/company/eagle", translate=True) emp_description = fields.Text( string="Short description about employee", translate=True) @api.model def create(self, vals): if vals.get('include_inourteam') == True: vals.update({'website_published': True}) res = super(HrEmployee, self).create(vals) return res @api.multi def write(self, vals): if vals.get('include_inourteam') == True: vals.update({'website_published': True}) if vals.get('include_inourteam') == False: vals.update({'website_published': False}) res = super(HrEmployee, self).write(vals) return res
class HrSalaryRuleCategory(models.Model): _name = 'hr.salary.rule.category' _description = 'Salary Rule Category' name = fields.Char(required=True, translate=True) code = fields.Char(required=True) parent_id = fields.Many2one( 'hr.salary.rule.category', string='Parent', help= "Linking a salary category to its parent is used only for the reporting purpose." ) children_ids = fields.One2many('hr.salary.rule.category', 'parent_id', string='Children') note = fields.Text(string='Description') company_id = fields.Many2one( 'res.company', string='Company', default=lambda self: self.env['res.company']._company_default_get()) @api.constrains('parent_id') def _check_parent_id(self): if not self._check_recursion(): raise ValidationError( _('Error! You cannot create recursive hierarchy of Salary Rule Category.' ))
class FeeStructureLines(models.Model): _name = 'education.fee.structure.lines' @api.onchange('fee_type') def _get_fee_type_ids(self): return { 'domain': { 'fee_type': [('category_id', '=', self.fee_structure_id.category_id.id)] } } fee_type = fields.Many2one('education.fee.type', string='Fee', required=True) fee_structure_id = fields.Many2one('education.fee.structure', string='Fee Structure', ondelete='cascade', index=True) fee_amount = fields.Float('Amount', required=True, related='fee_type.lst_price') payment_type = fields.Selection([('onetime', 'One Time'), ('permonth', 'Per Month'), ('peryear', 'Per Year'), ('sixmonth', '6 Months'), ('threemonth', '3 Months')], string='Payment Type', related="fee_type.payment_type") interval = fields.Char(related="fee_type.interval", string="Interval") fee_description = fields.Text('Description', related='fee_type.description_sale')
class MrpRouting(models.Model): """ Specifies routings of work centers """ _name = 'mrp.routing' _description = 'Routings' name = fields.Char('Routing', required=True) active = fields.Boolean( 'Active', default=True, help= "If the active field is set to False, it will allow you to hide the routing without removing it." ) code = fields.Char('Reference', copy=False, default=lambda self: _('New'), readonly=True) note = fields.Text('Description') operation_ids = fields.One2many('mrp.routing.workcenter', 'routing_id', 'Operations', copy=True) company_id = fields.Many2one('res.company', 'Company', default=lambda self: self.env.company) @api.model def create(self, vals): if 'code' not in vals or vals['code'] == _('New'): vals['code'] = self.env['ir.sequence'].next_by_code( 'mrp.routing') or _('New') return super(MrpRouting, self).create(vals)
class Partner(models.Model): _inherit = 'res.partner' _check_company_auto = True property_stock_customer = fields.Many2one( 'stock.location', string="Customer Location", company_dependent=True, check_company=True, domain= "['|', ('company_id', '=', False), ('company_id', '=', allowed_company_ids[0])]", help= "The stock location used as destination when sending goods to this contact." ) property_stock_supplier = fields.Many2one( 'stock.location', string="Vendor Location", company_dependent=True, check_company=True, domain= "['|', ('company_id', '=', False), ('company_id', '=', allowed_company_ids[0])]", help= "The stock location used as source when receiving goods from this contact." ) picking_warn = fields.Selection(WARNING_MESSAGE, 'Stock Picking', help=WARNING_HELP, default='no-message') picking_warn_msg = fields.Text('Message for Stock Picking')
class res_partner(models.Model): _name = 'res.partner' _inherit = 'res.partner' @api.multi def _compute_purchase_order_count(self): # retrieve all children partners and prefetch 'parent_id' on them all_partners = self.search([('id', 'child_of', self.ids)]) all_partners.read(['parent_id']) purchase_order_groups = self.env['purchase.order'].read_group( domain=[('partner_id', 'in', all_partners.ids)], fields=['partner_id'], groupby=['partner_id']) for group in purchase_order_groups: partner = self.browse(group['partner_id'][0]) while partner: if partner in self: partner.purchase_order_count += group['partner_id_count'] partner = partner.parent_id @api.multi def _compute_supplier_invoice_count(self): # retrieve all children partners and prefetch 'parent_id' on them all_partners = self.search([('id', 'child_of', self.ids)]) all_partners.read(['parent_id']) supplier_invoice_groups = self.env['account.invoice'].read_group( domain=[('partner_id', 'in', all_partners.ids), ('type', '=', 'in_invoice')], fields=['partner_id'], groupby=['partner_id']) for group in supplier_invoice_groups: partner = self.browse(group['partner_id'][0]) while partner: if partner in self: partner.supplier_invoice_count += group['partner_id_count'] partner = partner.parent_id @api.model def _commercial_fields(self): return super(res_partner, self)._commercial_fields() property_purchase_currency_id = fields.Many2one( 'res.currency', string="Supplier Currency", company_dependent=True, help= "This currency will be used, instead of the default one, for purchases from the current partner" ) purchase_order_count = fields.Integer( compute='_compute_purchase_order_count', string='Purchase Order Count') supplier_invoice_count = fields.Integer( compute='_compute_supplier_invoice_count', string='# Vendor Bills') purchase_warn = fields.Selection(WARNING_MESSAGE, 'Purchase Order', help=WARNING_HELP, default="no-message") purchase_warn_msg = fields.Text('Message for Purchase Order')