diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-01-16 17:00:16 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-01-16 17:00:16 +0700 |
| commit | f960f1c092cdb7669152f8caca7afad314a59877 (patch) | |
| tree | 69e3fa5c1a5b28da935435440d3eb99ef2a2117c | |
| parent | 83ead9edac739720168d615f6282e3978634e461 (diff) | |
change logic api new product
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 39 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 3 | ||||
| -rwxr-xr-x | indoteknik_custom/views/x_manufactures.xml | 3 |
3 files changed, 33 insertions, 12 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 28a63ed5..2e8e0226 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -1,6 +1,7 @@ from .. import controller from odoo import http from odoo.http import request +from datetime import datetime, timedelta import ast @@ -12,20 +13,44 @@ class Product(controller.Controller): if not self.authenticate(): return self.response(code=401, description='Unauthorized') base_url = request.env['ir.config_parameter'].get_param('web.base.url') - query = [('show_as_new_product', '=', True)] - brands = request.env['x_manufactures'].search(query, order='sequence') + current_time = datetime.now() + delta_time = current_time - timedelta(days=30) + + delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + query_products = [ + ('type', '=', 'product'), + ('active', '=', True), + ('image_128', '!=', False), + ('website_description', '!=', False), + ('create_date', '>=', delta_time), + ] + new_products = request.env['product.template'].search(query_products, order='name', limit=500) + brands = [] + for product in new_products: + brands.append(product.x_manufacture) + brands = list(dict.fromkeys(brands)) + data = [] + count = 0 for brand in brands: - query_products = [ - ('is_new_product', '=', True), + count += 1 + if count == 11: + break + query = [ + ('type', '=', 'product'), + ('active', '=', True), ('x_manufacture', '=', brand.id), + ('image_128', '!=', False), + ('website_description', '!=', False), + ('create_date', '>=', delta_time), ] - products = request.env['product.template'].search(query_products, order='name') + products = request.env['product.template'].search(query, order='name', limit=36) data.append({ 'manufacture_id': brand.id, - 'sequence': brand.sequence, + 'sequence': brand.sequence if brand.sequence else count, 'name': brand.x_name, - 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(brand.id) if brand.x_logo_manufacture else '', + 'image': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str( + brand.id) if brand.x_logo_manufacture else '', 'products': [request.env['product.template'].api_single_response(x) for x in products] }) return self.response(data) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index caf7ea3a..74b4edb1 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -57,7 +57,6 @@ class ProductTemplate(models.Model): current_time = datetime.now() delta_time = current_time - timedelta(days=30) - #current_time = current_time.strftime('%Y-%m-%d %H:%M:%S') delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') products = self.env['product.template'].search([ @@ -65,7 +64,7 @@ class ProductTemplate(models.Model): ('active', '=', True), ('product_rating', '>', 3), ('create_date', '>=', delta_time), - ], limit=1000) + ], limit=100) seq = 0 for product in products: diff --git a/indoteknik_custom/views/x_manufactures.xml b/indoteknik_custom/views/x_manufactures.xml index cc8fd10c..e51cb6a7 100755 --- a/indoteknik_custom/views/x_manufactures.xml +++ b/indoteknik_custom/views/x_manufactures.xml @@ -43,7 +43,6 @@ <field name="x_manufacture_level"/> <field name="x_produk_aksesoris_sparepart"/> <field name="cache_reset_status"/> - <field name="show_as_new_product"/> <field name="sequence"/> </group> <group> @@ -64,8 +63,6 @@ <field name="create_date"/> <field name="solr_flag"/> <field name="product_rating"/> - <field name="is_new_product"/> - <field name="seq_new_product"/> </tree> </field> </page> |
