from odoo import fields, models import logging _logger = logging.getLogger(__name__) class StockVendor(models.Model): _name = "stock.vendor" _description = "Stock Vendor" _rec_name = "product_variant_id" product_variant_id = fields.Many2one("product.product", string="Product Variant") quantity = fields.Integer(string="Quantity") def update_product_template(self): updated_virtual_qty_product_template = self.env['ir.config_parameter'].search([('key', '=', 'updated_virtual_qty_product_template')], limit=1) updated_virtual_qty_product_template_value = int(updated_virtual_qty_product_template.value) limit = 10000 query = [('active', '=', True), ('type', '=', 'product')] templates = self.env['product.template'].search(query, limit=limit, offset=updated_virtual_qty_product_template_value) template_count = self.env['product.template'].search_count(query) if (updated_virtual_qty_product_template_value + limit) > template_count: updated_virtual_qty_product_template.value = '0' else: updated_virtual_qty_product_template.value = str(limit + updated_virtual_qty_product_template_value) for template in templates: template.virtual_qty = template.qty_stock_vendor or 0 _logger.info("Update Stock Product Template %s : %s" % (template.id, template.virtual_qty))