summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-10-27 09:44:48 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-10-27 09:44:48 +0700
commit742213021f5e301518512c4f190b91df8182337a (patch)
treef97d2d85811338220ca6d20482d18930d976b08b
parentca21d92d64d9d8574cbfa4c227989f05d6ca9f0b (diff)
parent8e79387dd2f1172c3ee1f2aa4588ae71d21ea36d (diff)
Merge commit '8e79387dd2f1172c3ee1f2aa4588ae71d21ea36d'
-rw-r--r--indoteknik_api/controllers/api_v1/product.py7
-rwxr-xr-xindoteknik_custom/models/product_template.py2
-rwxr-xr-xindoteknik_custom/models/stock_vendor.py24
3 files changed, 22 insertions, 11 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index d667c1b6..d8006873 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -14,14 +14,14 @@ class Product(controller.Controller):
name = kw.get('name')
manufactures = kw.get('manufactures')
categories = kw.get('categories')
+ ready_stock = kw.get('ready_stock')
- require_betweens = ['name', 'manufactures', 'categories']
+ require_betweens = ['name', 'manufactures', 'categories', 'ready_stock']
is_fulfill = False
for required in require_betweens:
if kw.get(required):
is_fulfill = True
- # If not fulfill in require_between
if not is_fulfill:
return self.response(code=400, description='name or manufactures or categories is required')
@@ -41,6 +41,9 @@ class Product(controller.Controller):
if categories:
query.append(('public_categ_ids', 'child_of', [int(x) for x in categories.split(',')]))
+ if ready_stock == '1':
+ query.append(('virtual_qty', '>', 0))
+
price_from = kw.get('price_from')
if price_from and int(price_from):
query.append(('web_price_sorting', '>=', int(price_from)))
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..79c95781 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 = 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))