class FleetVehicleModelBrand(models.Model): _name = 'fleet.vehicle.model.brand' _description = 'Brand of the vehicle' _order = 'name asc' name = fields.Char('Make', required=True) image = fields.Binary( "Logo", attachment=True, help= "This field holds the image used as logo for the brand, limited to 1024x1024px." ) image_medium = fields.Binary( "Medium-sized image", attachment=True, help="Medium-sized logo of the brand. It is automatically " "resized as a 128x128px image, with aspect ratio preserved. " "Use this field in form views or some kanban views.") image_small = fields.Binary( "Small-sized image", attachment=True, help="Small-sized logo of the brand. It is automatically " "resized as a 64x64px image, with aspect ratio preserved. " "Use this field anywhere a small image is required.") @api.model_create_multi def create(self, vals_list): for vals in vals_list: tools.image_resize_images(vals) return super(FleetVehicleModelBrand, self).create(vals_list) @api.multi def write(self, vals): tools.image_resize_images(vals) return super(FleetVehicleModelBrand, self).write(vals)
class IrActionsActClient(models.Model): _name = 'ir.actions.client' _description = 'Client Action' _inherit = 'ir.actions.actions' _table = 'ir_act_client' _sequence = 'ir_actions_id_seq' _order = 'name' name = fields.Char(string='Action Name', translate=True) type = fields.Char(default='ir.actions.client') tag = fields.Char(string='Client action tag', required=True, help="An arbitrary string, interpreted by the client" " according to its own needs and wishes. There " "is no central tag repository across clients.") target = fields.Selection([('current', 'Current Window'), ('new', 'New Window'), ('fullscreen', 'Full Screen'), ('main', 'Main action of Current Window')], default="current", string='Target Window') res_model = fields.Char( string='Destination Model', help="Optional model, mostly used for needactions.") context = fields.Char( string='Context Value', default="{}", required=True, help= "Context dictionary as Python expression, empty by default (Default: {})" ) params = fields.Binary(compute='_compute_params', inverse='_inverse_params', string='Supplementary arguments', help="Arguments sent to the client along with " "the view tag") params_store = fields.Binary(string='Params storage', readonly=True) @api.depends('params_store') def _compute_params(self): self_bin = self.with_context(bin_size=False, bin_size_params_store=False) for record, record_bin in pycompat.izip(self, self_bin): record.params = record_bin.params_store and safe_eval( record_bin.params_store, {'uid': self._uid}) def _inverse_params(self): for record in self: params = record.params record.params_store = repr(params) if isinstance(params, dict) else params def _get_default_form_view(self): doc = super(IrActionsActClient, self)._get_default_form_view() params = doc.find(".//field[@name='params']") params.getparent().remove(params) params_store = doc.find(".//field[@name='params_store']") params_store.getparent().remove(params_store) return doc
class BinarySvg(models.Model): _name = 'test_new_api.binary_svg' _description = 'Test SVG upload' name = fields.Char(required=True) image_attachment = fields.Binary(attachment=True) image_wo_attachment = fields.Binary(attachment=False)
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 WebsiteMenu(models.Model): _inherit = "website.menu" is_megamenu = fields.Boolean(string='Is megamenu...?') megamenu_view_type = fields.Selection([('cat_megamenu', 'Category Megamenu'), ('pages_megamenu', "Pages Megamenu")], # default='cat_megamenu', string="Megamenu View Type") megamenu_size = fields.Selection([('medium', 'Medium'), ('large', 'Large')], default='medium', string="Megamenu Size") megamenu_type = fields.Selection([('2_col', '2 Columns'), ('3_col', '3 Columns'), ('4_col', '4 Columns')], default='3_col', string="Megamenu type") megamenu_bg = fields.Boolean( string='Want to set megamenu background', default=False) megamenu_bg_img_color = fields.Selection([('bg_img', 'Background image'), ('bg_color', 'Background color')], default='bg_img', string="Megamenu background selection") megamenu_bg_image = fields.Binary(string="Background image for megamenu") megamenu_bg_color = fields.Char(string="Background color for megamenu", default='#ccc', help="Background color for megamenu, for setting background color you have to pass hexacode here.") category_slider = fields.Boolean( string='Want to display category slider', default=False) carousel_header_name = fields.Char(string="Slider label", default="Latest", translate=True, help="Header name for carousel slider in megamenu") category_slider_position = fields.Selection([('left', 'Left'), ('right', 'Right')], default='left', string="Category Slider Position") menu_icon = fields.Boolean( string='Want to display menu icon', default=False) menu_icon_image = fields.Binary( string="Menu Icon", help="Menu icon for your menu") display_menu_footer = fields.Boolean(string="Display menu footer", default=False, help="For displaying footer in megamenu") menu_footer = fields.Text(string="Footer content", translate=True, help="Footer name for megamenu") customize_menu_colors = fields.Boolean( string='Want to customize menu colors', default=False) main_category_color = fields.Char(string='Main menu color', help="Set color for main menu in megamenu") sub_category_color = fields.Char(string='Submenu color', help="Set color for submenu in megamenu")
class UploadEducationPosition(models.TransientModel): _name = 'upload.education.position' _description = 'Wizard to Upload Education Position' file_normal = fields.Binary(string='Positions file (070)', filters='*.txt') file_other = fields.Binary(string='Other Positions file (T16)', filters='*.txt') def button_upload(self): normal_lines = _read_binary_file(self.file_normal) other_lines = _read_binary_file(self.file_other) position_obj = self.env['education.position'].with_context( active_test=False) if not normal_lines and not other_lines: raise exceptions.Warning(_('Empty file.')) else: for line in normal_lines: if len(line) > 0: education_code = _format_info(line[0:3]) vals = { 'education_code': education_code, 'description': _format_info(line[3:103]), 'description_eu': _format_info(line[103:203]), 'type': 'normal', } positions = position_obj.search([('education_code', '=', education_code), ('type', '=', 'normal')]) if positions: positions.write(vals) else: position_obj.create(vals) for line in other_lines: if len(line) > 0: education_code = _format_info(line[0:3]) vals = { 'education_code': education_code, 'description': _format_info(line[3:103]), 'description_eu': _format_info(line[103:203]), 'type': 'other', } positions = position_obj.search([('education_code', '=', education_code), ('type', '=', 'other')]) if positions: positions.write(vals) else: position_obj.create(vals) action = self.env.ref('education.action_education_position') return action.read()[0]
class UploadEducationDesignationLevel(models.TransientModel): _name = 'upload.education.designation_level' _description = 'Wizard to Upload Education Designation Levels' file = fields.Binary(string='Designation Levels File (061)', filters='*.txt') def button_upload(self): lines = _read_binary_file(self.file) designation_level_obj = self.env[ 'education.designation_level'].with_context(active_test=False) if not lines: raise exceptions.Warning(_('Empty file.')) else: for line in lines: if len(line) > 0: education_code = _format_info(line[0:3]) vals = { 'education_code': education_code, 'description': _format_info(line[3:103]), 'description_eu': _format_info(line[103:203]), 'short_description': _format_info(line[203:223]), 'short_description_eu': _format_info(line[223:243]), } designation_levels = designation_level_obj.search([ ('education_code', '=', education_code) ]) if designation_levels: designation_levels.write(vals) else: designation_level_obj.create(vals) action = self.env.ref('education.action_education_designation_level') return action.read()[0]
class UploadEducationContractType(models.TransientModel): _name = 'upload.education.task_type' _description = 'Wizard to Upload Education Task Type' file = fields.Binary(string='Task Types File (T13)', filters='*.txt') def button_upload(self): lines = _read_binary_file(self.file) task_type_obj = self.env['education.task_type'].with_context( active_test=False) if not lines: raise exceptions.Warning(_('Empty file.')) else: for line in lines: if len(line) > 0: education_code = _format_info(line[1:5]) vals = { 'type': _format_info(line[0:1]), 'education_code': education_code, 'tutoring': _format_info(line[5:6]), 'description': _format_info(line[6:256]), 'description_eu': _format_info(line[256:506]), 'level': _format_info(line[506:507]), 'other_activities': _format_info(line[507:508]), } task_types = task_type_obj.search([('education_code', '=', education_code)]) if task_types: task_types.write(vals) else: task_type_obj.create(vals) action = self.env.ref('education.action_education_task_type') return action.read()[0]
class UploadEducationField(models.TransientModel): _name = 'upload.education.field' _description = 'Wizard to Upload Education Fields' file = fields.Binary(string='Study Fields File (V55T14)', filters='*.txt') def button_upload(self): lines = _read_binary_file(self.file) field_obj = self.env['education.field'].with_context(active_test=False) if not lines: raise exceptions.Warning(_('Empty file.')) else: for line in lines: if len(line) > 0: education_code = _format_info(line[0:4]) vals = { 'education_code': education_code, 'description': _format_info(line[4:54]), 'description_eu': _format_info(line[54:104]), } fields = field_obj.search([('education_code', '=', education_code)]) if fields: fields.write(vals) else: field_obj.create(vals) action = self.env.ref('education.action_education_field') return action.read()[0]
class EagleeduInstructor(models.Model): _name = 'eagleedu.instructor' # _inherit = ['mail.thread'] _description = 'All Teachers Details' @api.model def create(self, vals): """Over riding the create method to assign the sequence for newly creating records""" vals['instructor_id'] = self.env['ir.sequence'].next_by_code( 'eagleedu.instructor') res = super(EagleeduInstructor, self).create(vals) return res name = fields.Char(string="Instructor Name", required=True) instructor_id = fields.Char(string="Instructor ID No.", readonly=True) ins_father_name = fields.Char(string="Father Name") ins_mother_name = fields.Char(string="Mother Name") ins_mobile_no = fields.Char(string="Mobile no.") ins_email = fields.Char(string="Email Address") ins_present_address = fields.Char(string="Present Address") ins_permanent_address = fields.Char(string="Permanent Address") ins_image = fields.Binary(string="Instructor Image") ins_gender = fields.Selection([('male', 'Male'), ('female', 'Female'), ('other', 'Other')], string='Gender', required=False, track_visibility='onchange', help="Your Gender is") ins_date_of_birth = fields.Date(string="Date Of birth", help="Enter your DOB")
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 UploadEducationLanguage(models.TransientModel): _name = 'upload.education.language' _description = 'Wizard to Upload Languages' file = fields.Binary(string='Languages File (T55)', filters='*.txt') def button_upload(self): lines = _read_binary_file(self.file) language_obj = self.env['education.language'].with_context( active_test=False) if not lines: raise exceptions.Warning(_('Empty file.')) else: for line in lines: if len(line) > 0: education_code = _format_info(line[0:2]) vals = { 'education_code': education_code, 'description': _format_info(line[2:102]), 'description_eu': _format_info(line[102:202]), 'short_description': _format_info(line[202:206]), 'short_description_eu': _format_info(line[206:210]), } languages = language_obj.search([('education_code', '=', education_code)]) if languages: languages.write(vals) else: language_obj.create(vals) action = self.env.ref('education.action_education_language') return action.read()[0]
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 UploadEducationContractType(models.TransientModel): _name = 'upload.education.contract_type' _description = 'Wizard to Upload Education Contract Types' file = fields.Binary(string='Contract Types File (T31)', filters='*.txt') def button_upload(self): lines = _read_binary_file(self.file) contract_type_obj = self.env['education.contract_type'].with_context( active_test=False) if not lines: raise exceptions.Warning(_('Empty file.')) else: for line in lines: if len(line) > 0: education_code = _format_info(line[0:4]) vals = { 'education_code': education_code, 'description': _format_info(line[4:104]), 'description_eu': _format_info(line[104:204]), 'short_description': _format_info(line[204:224]), 'short_description_eu': _format_info(line[224:244]), } contract_types = contract_type_obj.search([ ('education_code', '=', education_code) ]) if contract_types: contract_types.write(vals) else: contract_type_obj.create(vals) action = self.env.ref('education.action_education_contract_type') return action.read()[0]
class ks_Links(models.Model): _name = "theme.links" _description = "Maintain the social media links of the website" name = fields.Char() ks_links_images = fields.Binary("Link Image") ks_link_address = fields.Char("Link Redirect Address", required=True)
class UploadEducationContractType(models.TransientModel): _name = 'upload.education.shift' _description = 'Wizard to Upload Class Shift' file = fields.Binary(string='Class Shifts File (V55T32)', filters='*.txt') def button_upload(self): lines = _read_binary_file(self.file) shift_obj = self.env['education.shift'].with_context(active_test=False) if not lines: raise exceptions.Warning(_('Empty file.')) else: for line in lines: if len(line) > 0: education_code = _format_info(line[0:4]) vals = { 'education_code': education_code, 'description': _format_info(line[4:24]), 'description_eu': _format_info(line[24:44]), } shifts = shift_obj.search([('education_code', '=', education_code)]) if shifts: shifts.write(vals) else: shift_obj.create(vals) action = self.env.ref('education.action_education_shift') return action.read()[0]
class UploadEducationSubject(models.TransientModel): _name = 'upload.education.subject' _description = 'Wizard to Upload Subjects' file = fields.Binary(string='Subjects File (V55T15W18T54_1)', filters='*.txt') def button_upload(self): lines = _read_binary_file(self.file) subject_obj = self.env['education.subject'].with_context( active_test=False) if not lines: raise exceptions.Warning(_('Empty file.')) else: for line in lines: if len(line) > 0: education_code = _format_info(line[0:8]) vals = { 'education_code': education_code, 'description': _format_info(line[8:108]), 'description_eu': _format_info(line[108:208]), 'short_description': _format_info(line[208:228]), 'short_description_eu': _format_info(line[228:248]), 'min_description': _format_info(line[248:252]), 'min_description_eu': _format_info(line[252:256]), 'type': _format_info(line[256:260]), } subjects = subject_obj.search([('education_code', '=', education_code)]) if subjects: subjects.write(vals) else: subject_obj.create(vals) action = self.env.ref('education.action_education_subject') return action.read()[0]
class ribbonMedalForce(models.Model): _name="ribbon.medal.force" _description = "Name of the Force ie; Police, Army ..." name=fields.Char("Force Name") image=fields.Binary("Logo") description=fields.Char("Description") ribbon_ids=fields.Many2many("ribbon.medal",'ribbon_force_medal_rel',column1='force_id',column2="ribbon_id",string="ribbons") ranks=fields.One2many("ribbon.medal.rank",'force_id')
class SaasModuleCategory(models.Model): _name = 'saas.module.category' _parent_name = "parent_id" _parent_store = True _parent_order = 'name' _rec_name = 'complete_name' _order = 'parent_left' _description = 'Class for creating Module Categories that one wishes to provide as a service.' image = fields.Binary(string='Image') name = fields.Char(string="Category Name", required=True) complete_name = fields.Char('Complete Name', compute='_compute_complete_name', store=True) parent_id = fields.Many2one('saas.module.category', 'Parent Category', ondelete='cascade') parent_path = fields.Char(index=True) child_id = fields.One2many('saas.module.category', 'parent_id', 'Child Categories') parent_left = fields.Integer('Left Parent', index=1) parent_right = fields.Integer('Right Parent', index=1) module_category = fields.Many2one(comodel_name="saas.module.category", string="Module Category") module_count = fields.Integer(string='Modules', compute='_compute_module_count') @api.depends('name', 'parent_id.complete_name') def _compute_complete_name(self): for category in self: if category.parent_id: category.complete_name = '%s / %s' % ( category.parent_id.complete_name, category.name) else: category.complete_name = category.name def _compute_module_count(self): read_group_res = self.env['saas.module'].read_group( [('categ_id', 'child_of', self.ids)], ['categ_id'], ['categ_id']) group_data = dict((data['categ_id'][0], data['categ_id_count']) for data in read_group_res) for categ in self: module_count = 0 for sub_categ_id in categ.search([('id', 'child_of', categ.id) ]).ids: module_count += group_data.get(sub_categ_id, 0) categ.module_count = module_count @api.constrains('parent_id') def _check_category_recursion(self): if not self._check_recursion(): raise ValidationError( _('Error ! You cannot create recursive categories.')) return True @api.model def name_create(self, name): return self.create({'name': name}).name_get()[0]
class ribbonMedalAcquiredRibbonWizard(models.TransientModel): _name = "ribbon.acquired.ribbon.wizard" _description = "list of acquired rebbon" _order = "serial desc" force_member_id = fields.Many2one("res.partner") ribbon_id = fields.Many2one("ribbon.regulation") image = fields.Binary("Image", related="ribbon_id.big_ribbon.image") extension = fields.Many2one("ribbon.extension") serial = fields.Integer("serial")
class ProductImage(models.Model): _name = 'product.image' _description = 'Product Image' name = fields.Char('Name') image = fields.Binary('Image', attachment=True) product_tmpl_id = fields.Many2one('product.template', 'Related Product', copy=True)
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 BaseLanguageImport(models.TransientModel): _name = "base.language.import" _description = "Language Import" name = fields.Char('Language Name', required=True) code = fields.Char('ISO Code', size=6, required=True, help="ISO Language and Country code, e.g. en_US") data = fields.Binary('File', required=True, attachment=False) filename = fields.Char('File Name', required=True) overwrite = fields.Boolean( 'Overwrite Existing Terms', default=True, help= "If you enable this option, existing translations (including custom ones) " "will be overwritten and replaced by those in this file") def import_lang(self): this = self[0] this = this.with_context(overwrite=this.overwrite) with TemporaryFile('wb+') as buf: try: buf.write(base64.decodestring(this.data)) # now we determine the file format buf.seek(0) fileformat = os.path.splitext(this.filename)[-1][1:].lower() tools.trans_load_data(this._cr, buf, fileformat, this.code, lang_name=this.name, context=this._context) except ProgrammingError as e: _logger.exception( 'File unsuccessfully imported, due to a malformed file.') with closing(sql_db.db_connect( self._cr.dbname).cursor()) as cr: raise UserError( _('File %r not imported due to a malformed file.\n\n' + 'This issue can be caused by duplicates entries who are referring to the same field. ' + 'Please check the content of the file you are trying to import.\n\n' + 'Technical Details:\n%s') % tools.ustr(e)) except Exception as e: _logger.exception( 'File unsuccessfully imported, due to format mismatch.') raise UserError( _('File %r not imported due to format mismatch or a malformed file.' ' (Valid formats are .csv, .po, .pot)\n\nTechnical Details:\n%s') % \ (this.filename, tools.ustr(e)) ) return True
class product_template(models.Model): _inherit = 'product.template' select_label = fields.Many2one('website.product.label', 'Select Product Label') label_image = fields.Binary('Label Image') @api.onchange('select_label') def onchange_product_label(self): self.label_image = self.select_label.image
class ribbonMedalawardRibbon(models.Model): _name="ribbon.medal.award.ribbon" _description = "list of ribbon acquired for service" _order = "serial desc" force_member_id = fields.Many2one("res.partner") ribbon_id = fields.Many2one("ribbon.medal.regulation") image = fields.Binary( "Image", related="ribbon_id.big_ribbon.image") extension = fields.Many2one("ribbon.medal.extension") serial = fields.Integer("serial")
class FleetVehicleModel(models.Model): _name = 'fleet.vehicle.model' _description = 'Model of a vehicle' _order = 'name asc' name = fields.Char('Model name', required=True) brand_id = fields.Many2one('fleet.vehicle.model.brand', 'Make', required=True, help='Make of the vehicle') vendors = fields.Many2many('res.partner', 'fleet_vehicle_model_vendors', 'model_id', 'partner_id', string='Vendors') image = fields.Binary(related='brand_id.image', string="Logo", readonly=False) image_medium = fields.Binary(related='brand_id.image_medium', string="Logo (medium)", readonly=False) image_small = fields.Binary(related='brand_id.image_small', string="Logo (small)", readonly=False) @api.multi @api.depends('name', 'brand_id') def name_get(self): res = [] for record in self: name = record.name if record.brand_id.name: name = record.brand_id.name + '/' + name res.append((record.id, name)) return res @api.onchange('brand_id') def _onchange_brand(self): if self.brand_id: self.image_medium = self.brand_id.image else: self.image_medium = False
class UploadEducationLevelWorkdayType(models.TransientModel): _name = 'upload.education.level.workday_type' _description = 'Wizard to Upload Education Level and Workday Type Relation' file = fields.Binary(string='Level and Workday Type Relation File (T09)', filters='*.txt') def button_upload(self): lines = _read_binary_file(self.file) relation_obj = self.env['education.level.workday_type'].with_context( active_test=False) academic_year_obj = self.env['education.academic_year'].with_context( active_test=False) workday_type_obj = self.env['education.workday_type'].with_context( active_test=False) level_obj = self.env['education.level'].with_context(active_test=False) if not lines: raise exceptions.Warning(_('Empty file.')) else: for line in lines: if len(line) > 0: academic_year_code = _format_info(line[0:9]) academic_year = academic_year_obj.search([ ('name', '=', academic_year_code) ]) if not academic_year: academic_year = academic_year_obj.create({ 'name': academic_year_code, }) workday_type = workday_type_obj.search([ ('education_code', '=', _format_info(line[9:18])) ]) levels = level_obj.search([('education_code', '=', _format_info(line[18:22]))]) for level in levels: vals = { 'academic_year_id': academic_year.id, 'workday_type_id': workday_type.id, 'level_id': level.id, 'dedicated_working_day': _format_info(line[22:27]), 'school_working_day': _format_info(line[27:32]) } relations = relation_obj.search([ ('academic_year_id', '=', academic_year.id), ('workday_type_id', '=', workday_type.id), ('level_id', '=', level.id) ]) if relations: relations.write(vals) else: relation_obj.create(vals) action = self.env.ref('education.action_education_level') return action.read()[0]
class ks_trending_style(models.Model): _inherit = 'product.public.category' ks_product_category_slogan = fields.Char(string='Slogan') ks_categ_tag = fields.Boolean(string='Trendy') child_id = fields.One2many('product.public.category', 'parent_id', string='Child Category') category_url = fields.Char(help="So each category can have their urls") ks_categ_background = fields.Binary(string='Breadcrumb Image', widget='binary')
class ModelBinary(models.Model): _name = 'test_new_api.model_binary' _description = 'Test Image field' binary = fields.Binary() binary_related_store = fields.Binary("Binary Related Store", related='binary', store=True, readonly=False) binary_related_no_store = fields.Binary("Binary Related No Store", related='binary', store=False, readonly=False) binary_computed = fields.Binary(compute='_compute_binary') @api.depends('binary') def _compute_binary(self): # arbitrary value: 'bin_size' must have no effect for record in self: record.binary_computed = [(record.id, bool(record.binary))]
class RestaurantFloor(models.Model): _name = 'restaurant.floor' _description = 'Restaurant Floor' name = fields.Char('Floor Name', required=True, help='An internal identification of the restaurant floor') pos_config_id = fields.Many2one('pos.config', string='Point of Sale') background_image = fields.Binary('Background Image', attachment=True, help='A background image used to display a floor layout in the point of sale interface') background_color = fields.Char('Background Color', help='The background color of the floor layout, (must be specified in a html-compatible format)', default='rgb(210, 210, 210)') table_ids = fields.One2many('restaurant.table', 'floor_id', string='Tables', help='The list of tables in this floor') sequence = fields.Integer('Sequence', help='Used to sort Floors', default=1)