diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2022-10-26 16:49:37 +0700 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2022-10-26 16:49:37 +0700 |
| commit | 5b8509a6ff49db845e2ce625506d8e4837a62681 (patch) | |
| tree | 949bd0b41cf6949215a8b3b1d2beec3fe13435ed | |
| parent | eca615138b5259114073e29e06d4499edaadbc69 (diff) | |
compute virtual quantity
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/models/stock_vendor.py | 24 |
2 files changed, 17 insertions, 9 deletions
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index 219eda5c..156cf381 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -31,7 +31,7 @@ class ProductTemplate(models.Model): product_rating = fields.Float('Product Rating', help="Digunakan untuk sorting product di website", default=0.0) last_calculate_rating = fields.Datetime("Last Calculate Rating") web_price_sorting = fields.Float('Web Price Sorting', help='Hanya digunakan untuk sorting di web, harga tidak berlaku', default=0.0) - qty_vendor = fields.Float(string='Qty Vendor', default=0) + virtual_qty = fields.Float(string='Virtual Qty', default=0) def _compute_qty_stock_vendor(self): for product_template in self: diff --git a/indoteknik_custom/models/stock_vendor.py b/indoteknik_custom/models/stock_vendor.py index 6f80a12e..85283654 100755 --- a/indoteknik_custom/models/stock_vendor.py +++ b/indoteknik_custom/models/stock_vendor.py @@ -13,11 +13,19 @@ class StockVendor(models.Model): quantity = fields.Integer(string="Quantity") def update_product_template(self): - stock_vendors = self.env['stock.vendor'].search([('quantity', '>', 0)]) - count = 0 - for stock in stock_vendors: - template = stock.product_variant_id.product_tmpl_id - template.qty_vendor = stock.quantity - _logger.info("Update Stock Vendor %s" % template.id) - count += 1 - _logger.info("CHECKED HERE - Stock Vendor Updated %s" % count) + 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 = 500 + 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)) |
