from odoo import models, fields, api import logging _logger = logging.getLogger(__name__) class XManufactures(models.Model): _name = 'x_manufactures' _description = "Manufactures" _rec_name = "x_name" x_name = fields.Char(string="Name") x_description = fields.Html(string="Description") x_logo_manufacture = fields.Binary(string="Logo Manufacture") x_logo_manufacture_128 = fields.Image("Image 128", related="x_logo_manufacture", max_width=128, max_height=128, store=True) image_promotion_1 = fields.Binary(string="Promotion Image 1") image_promotion_2 = fields.Binary(string="Promotion Image 2") x_manufacture_level = fields.Selection([ ('prioritas', 'Prioritas'), ('gold', 'Gold'), ('silver', 'Silver') ], string="Manufacture Level") x_manufacture_product = fields.One2many( comodel_name="product.template", inverse_name="x_manufacture", string="Relasi Produk" ) x_manufacture_service_center = fields.Many2many("res.partner", string="Service Center") x_manufactures_banners = fields.One2many( comodel_name="x_banner.banner", inverse_name="x_relasi_manufacture", string="Relasi Manufacture Banner" ) x_negara_asal = fields.Char(string="Negara Asal") x_produk_aksesoris_sparepart = fields.Selection([ ('produk', 'Produk'), ('aksesoris', 'Aksesoris'), ('sparepart', 'Spare Part') ], string="Jenis Produk") x_short_desc = fields.Text(string="Short Description") product_tmpl_ids = fields.One2many('product.template', 'x_manufacture', string='Product Templates') cache_reset_status = fields.Selection([ ('reset', 'Reset'), ('done', 'Done') ], string="Cache Reset") sequence = fields.Integer(string='Sequence', help='Urutan tampil di homepage jika show as new product') show_as_new_product = fields.Boolean(string='Show as New Product', help='Centang jika ingin ditammpilkan di website sebagai segment Produk Baru') def cache_reset(self): manufactures = self.env['x_manufactures'].search([ ('cache_reset_status', '=', 'reset'), ]) for manufacture in manufactures: products = self.env['product.template'].search([ ('x_manufacture', '=', manufacture.id), ('solr_flag', '=', 1), ]) for product in products: product.solr_flag = 2 _logger.info("Reset Solr Flag to 2 %s" % product.id) manufacture.cache_reset_status = 'done' @api.onchange('x_name','image_promotion_1','image_promotion_2') def update_solr_flag(self): for manufacture in self: templates = self.env['product.template'].search([ ('x_manufacture', '=', manufacture.id) ]) for template in templates: if template.solr_flag == 1: template.solr_flag = 2