summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-20 14:24:04 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-20 14:24:04 +0700
commitcf92957930fde29f7c04859593cb296bd8699c61 (patch)
tree50e2db2e8523a3818fe99f88e4e11d1bf776e09b
parentcf29c503c23a76cfe0038fa7faa7be36d5f969ae (diff)
add cache reset for stock vendor (solr_flag)
-rwxr-xr-xindoteknik_custom/models/stock_vendor.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/indoteknik_custom/models/stock_vendor.py b/indoteknik_custom/models/stock_vendor.py
index 07b0e5b6..1e5bce16 100755
--- a/indoteknik_custom/models/stock_vendor.py
+++ b/indoteknik_custom/models/stock_vendor.py
@@ -20,26 +20,32 @@ class StockVendor(models.Model):
stocks = self.env['stock.vendor'].search([
('cache_reset_status', '=', 'reset'),
])
+
+ templates = []
for stock in stocks:
- if stock.product_variant_id.product_tmpl_id.solr_flag == 1:
- stock.product_variant_id.product_tmpl_id.solr_flag = 2
- _logger.info('Update Solr Flag to 2 %s' % stock.product_variant_id.product_tmpl_id.name)
- stock.cache_reset_status = 'done'
+ templates.append(stock.product_variant_id.product_tmpl_id)
+ # stock.cache_reset_status = 'done'
+ templates = list(dict.fromkeys(templates))
+
+ for template in templates:
+ if template.solr_flag == 1:
+ template.solr_flag = 2
+ _logger.info('Update Solr Flag to 2 %s' % template.name)
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))