# -*- coding: utf-8 -*- from odoo import models, fields, api, _ class SlideChannel(models.Model): _inherit = 'slide.channel' code = fields.Char('Code', required=True, copy=False, readonly=True, default=lambda self: _('New')) instance_arrangement = fields.Selection( [('share', 'Share'), ('exclude', 'Exclude'), ('both', 'Both'), ('no_need', 'No Need')], string="Instance Arrangement") share_instance_count = fields.Integer('Shared Instance Count') instance_base = fields.Many2one('ospp.instance', string="Instance Base") instance_ids = fields.One2many('channel.instance', 'channel_id', string="Instances") def name_get(self): # Prefetch the fields used by the `name_get`, so `browse` doesn't fetch other fields self.browse(self.ids).read(['name', 'code']) return [(channel.id, '%s%s' % (channel.code and '[%s] ' % channel.code or '', channel.name)) for channel in self] @api.model_create_multi def create(self, vals_list): for vals in vals_list: if 'company_id' in vals: self = self.with_company(vals['company_id']) if vals.get('name', _("New")) == _("New"): seq_date = None vals['name'] = self.env['ir.sequence'].next_by_code('slide.channel', sequence_date=seq_date) or _("New") return super().create(vals_list) class ChannelInstance(models.Model): _name = "channel.instance" _inherit = ['mail.thread', 'mail.activity.mixin', 'image.mixin'] _description = "Channel Instance" channel_id = fields.Many2one('slide.channel', required=True, string="Channel") instance_id = fields.Many2one('ospp.instance', required=True, string="Instance") name = fields.Char('Name', required=True) code = fields.Char('Code', required=True, copy=False, readonly=True, default=lambda self: _('New')) service_name = fields.Char('Service Name', required=True) service_url = fields.Char('Service URL', required=True) user_scope = fields.Many2many('slide.channel.partner', string="User Scope") active = fields.Boolean('Active', default=True) # class ospp_slide(models.Model): # _name = 'ospp_slide.ospp_slide' # _description = 'ospp_slide.ospp_slide' # name = fields.Char() # value = fields.Integer() # value2 = fields.Float(compute="_value_pc", store=True) # description = fields.Text() # # @api.depends('value') # def _value_pc(self): # for record in self: # record.value2 = float(record.value) / 100