From 064a4c0462e68edf89eadee6b5bc7c6508fe30eb Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 19 Jan 2023 10:59:33 +0700 Subject: new product must have manufacture id (brand) --- indoteknik_api/controllers/api_v1/product.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 78b03203..cfa2dbef 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -28,6 +28,8 @@ class Product(controller.Controller): ('active', '=', True), ('image_128', '!=', False), ('website_description', '!=', False), + # ('write_uid', '!=', 1), + ('x_manufacture', '!=', False), # ('create_date', '>=', delta_time), ] new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=250) @@ -57,6 +59,8 @@ class Product(controller.Controller): ('x_manufacture', '=', brand.id), ('image_128', '!=', False), ('website_description', '!=', False), + # ('write_uid', '!=', 1), + ('x_manufacture', '!=', False), # ('create_date', '>=', delta_time), ] count_products = request.env['product.template'].search_count(query) -- cgit v1.2.3 From 74e22ea21d16389937fe8d571a475218fda7ffa5 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 19 Jan 2023 11:59:23 +0700 Subject: add cache reset stock vendor --- indoteknik_custom/models/stock_vendor.py | 24 +++++++++++++++++++----- indoteknik_custom/views/stock_vendor.xml | 2 ++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/indoteknik_custom/models/stock_vendor.py b/indoteknik_custom/models/stock_vendor.py index 1a6b4a64..07b0e5b6 100755 --- a/indoteknik_custom/models/stock_vendor.py +++ b/indoteknik_custom/models/stock_vendor.py @@ -11,6 +11,20 @@ class StockVendor(models.Model): product_variant_id = fields.Many2one("product.product", string="Product Variant") quantity = fields.Integer(string="Quantity") + cache_reset_status = fields.Selection([ + ('reset', 'Reset'), + ('done', 'Done') + ], string="Cache Reset") + + def cache_reset(self): + stocks = self.env['stock.vendor'].search([ + ('cache_reset_status', '=', 'reset'), + ]) + 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' def update_product_template(self): updated_virtual_qty_product_template = self.env['ir.config_parameter'].search([('key', '=', 'updated_virtual_qty_product_template')], limit=1) @@ -30,8 +44,8 @@ class StockVendor(models.Model): template.virtual_qty = template.qty_stock_vendor or 0 _logger.info("Update Stock Product Template %s : %s" % (template.id, template.virtual_qty)) - @api.onchange('quantity') - def update_solr_flag(self): - for stock in self: - if stock.product_variant_id.product_tmpl_id.solr_flag == 1: - stock.product_variant_id.product_tmpl_id.solr_flag = 2 + # @api.onchange('quantity') + # def update_solr_flag(self): + # for stock in self: + # if stock.product_variant_id.product_tmpl_id.solr_flag == 1: + # stock.product_variant_id.product_tmpl_id.solr_flag = 2 diff --git a/indoteknik_custom/views/stock_vendor.xml b/indoteknik_custom/views/stock_vendor.xml index ebf63a6a..35931750 100755 --- a/indoteknik_custom/views/stock_vendor.xml +++ b/indoteknik_custom/views/stock_vendor.xml @@ -18,6 +18,7 @@ + @@ -33,6 +34,7 @@ + -- cgit v1.2.3 From cf29c503c23a76cfe0038fa7faa7be36d5f969ae Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 19 Jan 2023 14:47:10 +0700 Subject: back to leads scheduler --- indoteknik_custom/models/crm_lead.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py index e0a90d9c..3c8b842b 100755 --- a/indoteknik_custom/models/crm_lead.py +++ b/indoteknik_custom/models/crm_lead.py @@ -11,6 +11,15 @@ class CrmLead(models.Model): file_siup = fields.Binary(string="Surat Izin Usaha Perdagangan") body_html_lead = fields.Text('Body HTML', compute='compute_body_leads') + def revert_to_leads(self): + opportunities = self.env['crm.lead'].search([ + ('type', '=', 'opportunity'), + ('active', '=', True), + ('user_id', '=', False), + ]) + for opportunity in opportunities: + opportunity.type = 'lead' + @api.onchange('stage_id') def update_stars(self): for lead in self: -- cgit v1.2.3 From cf92957930fde29f7c04859593cb296bd8699c61 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 20 Jan 2023 14:24:04 +0700 Subject: add cache reset for stock vendor (solr_flag) --- indoteknik_custom/models/stock_vendor.py | 20 +++++++++++++------- 1 file 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)) -- cgit v1.2.3 From c54083f55d4d1990d8325fff063896b3bc0f6fb2 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 23 Jan 2023 08:54:07 +0700 Subject: add condition search rank weekly --- indoteknik_custom/models/user_activity_log.py | 1 + 1 file changed, 1 insertion(+) diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py index 3cf7bd58..16084037 100755 --- a/indoteknik_custom/models/user_activity_log.py +++ b/indoteknik_custom/models/user_activity_log.py @@ -70,6 +70,7 @@ class UserActivityLog(models.Model): activity_logs = self.env['user.activity.log'].search([ ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'), ('create_date', '>', delta_time), + ('url', 'not ilike', 'shopping'), ], limit=4000) for activity_log in activity_logs: _logger.info(activity_log.url) -- cgit v1.2.3 From 4bc68435bc20d7da0f38bd2370057481cb995584 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 23 Jan 2023 10:52:49 +0700 Subject: add dynamic limit for new product --- indoteknik_api/controllers/api_v1/product.py | 4 +++- indoteknik_custom/models/user_activity_log.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index cfa2dbef..23dcf48e 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -19,6 +19,8 @@ class Product(controller.Controller): is_brand_only = int(kw.get('is_brand_only', 0)) base_url = request.env['ir.config_parameter'].get_param('web.base.url') + limit_new_products = request.env['ir.config_parameter'].get_param('limit.new.product') + limit_new_products = int(limit_new_products) # current_time = datetime.now() # delta_time = current_time - timedelta(days=30) @@ -32,7 +34,7 @@ class Product(controller.Controller): ('x_manufacture', '!=', False), # ('create_date', '>=', delta_time), ] - new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=250) + new_products = request.env['product.template'].search(query_products, order='create_date desc', limit=limit_new_products) brands = [] for product in new_products: brands.append(product.x_manufacture) diff --git a/indoteknik_custom/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py index 16084037..32b389a1 100755 --- a/indoteknik_custom/models/user_activity_log.py +++ b/indoteknik_custom/models/user_activity_log.py @@ -71,7 +71,7 @@ class UserActivityLog(models.Model): ('url', 'ilike', 'https://indoteknik.co%/shop/product/%'), ('create_date', '>', delta_time), ('url', 'not ilike', 'shopping'), - ], limit=4000) + ], limit=1000) for activity_log in activity_logs: _logger.info(activity_log.url) strip_index = i = 0 -- cgit v1.2.3 From 8af5ee591aabc2d5d946c0eece93a5caab989975 Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Mon, 23 Jan 2023 14:44:12 +0700 Subject: Fix get api image logic --- indoteknik_api/models/product_product.py | 8 +++----- indoteknik_api/models/product_template.py | 13 ++++++------- indoteknik_api/models/x_manufactures.py | 6 +++--- indoteknik_custom/models/ir_attachment.py | 15 ++++++++++++++- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/indoteknik_api/models/product_product.py b/indoteknik_api/models/product_product.py index 6b02d91e..2e84b9f4 100644 --- a/indoteknik_api/models/product_product.py +++ b/indoteknik_api/models/product_product.py @@ -5,7 +5,6 @@ class ProductProduct(models.Model): _inherit = 'product.product' def api_single_response(self, product_product): - base_url = self.env['ir.config_parameter'].get_param('web.base.url') product_pricelist_default_discount_id = self.env['ir.config_parameter'].get_param('product.pricelist.default_discount_id') product_pricelist_default_discount_id = int(product_pricelist_default_discount_id) product_template = product_product.product_tmpl_id @@ -14,7 +13,7 @@ class ProductProduct(models.Model): 'parent': { 'id': product_template.id, 'name': product_template.name, - 'image': base_url + 'api/image/product.template/image_256/' + str(product_template.id) if product_template.image_256 else '', + 'image': self.env['ir.attachment'].api_image('product.template', 'image_256', product_template.id), }, 'code': product_product.default_code or '', 'name': product_product.display_name, @@ -27,13 +26,12 @@ class ProductProduct(models.Model): return data def api_manufacture(self, product_template): - base_url = self.env['ir.config_parameter'].get_param('web.base.url') if product_template.x_manufacture: manufacture = product_template.x_manufacture return { 'id': manufacture.id, 'name': manufacture.x_name, - 'image_promotion_1': base_url + 'api/image/x_manufactures/image_promotion_1/' + str(manufacture.id) if manufacture.image_promotion_1 else '', - 'image_promotion_2': base_url + 'api/image/x_manufactures/image_promotion_2/' + str(manufacture.id) if manufacture.image_promotion_2 else '', + 'image_promotion_1': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', manufacture.id), + 'image_promotion_2': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', manufacture.id), } return {} \ No newline at end of file diff --git a/indoteknik_api/models/product_template.py b/indoteknik_api/models/product_template.py index 9e8d04bc..72dda17f 100644 --- a/indoteknik_api/models/product_template.py +++ b/indoteknik_api/models/product_template.py @@ -5,12 +5,11 @@ class ProductTemplate(models.Model): _inherit = 'product.template' def api_single_response(self, product_template, with_detail=''): - base_url = self.env['ir.config_parameter'].get_param('web.base.url') product_pricelist_default_discount_id = self.env['ir.config_parameter'].get_param('product.pricelist.default_discount_id') product_pricelist_default_discount_id = int(product_pricelist_default_discount_id) data = { 'id': product_template.id, - 'image': base_url + 'api/image/product.template/image_128/' + str(product_template.id) if product_template.image_128 else '', + 'image': self.env['ir.attachment'].api_image('product.template', 'image_128', product_template.id), 'code': product_template.default_code or '', 'name': product_template.name, 'lowest_price': self.env['product.pricelist'].get_lowest_product_variant_price(product_template, product_pricelist_default_discount_id), @@ -23,7 +22,7 @@ class ProductTemplate(models.Model): if with_detail != '': data_with_detail = { - 'image': base_url + 'api/image/product.template/image_512/' + str(product_template.id) if product_template.image_512 else '', + 'image': self.env['ir.attachment'].api_image('product.template', 'image_512', product_template.id), 'display_name': product_template.display_name, 'variants': [self.env['product.product'].api_single_response(variant) for variant in product_template.product_variant_ids], 'description': product_template.website_description or '', @@ -31,12 +30,13 @@ class ProductTemplate(models.Model): data.update(data_with_detail) if with_detail == 'SOLR': + is_image_found = self.env['ir.attachment'].is_found('product.template', 'image_128', product_template.id) rate = 0 if data['lowest_price']['price'] > 0: rate += 1 if product_template.have_promotion_program: rate += 1 - if product_template.image_128: + if is_image_found: rate += 1 if product_template.website_description: rate += 1 @@ -52,14 +52,13 @@ class ProductTemplate(models.Model): return data def api_manufacture(self, product_template): - base_url = self.env['ir.config_parameter'].get_param('web.base.url') if product_template.x_manufacture: manufacture = product_template.x_manufacture return { 'id': manufacture.id, 'name': manufacture.x_name, - 'image_promotion_1': base_url + 'api/image/x_manufactures/image_promotion_1/' + str(manufacture.id) if manufacture.image_promotion_1 else '', - 'image_promotion_2': base_url + 'api/image/x_manufactures/image_promotion_2/' + str(manufacture.id) if manufacture.image_promotion_2 else '', + 'image_promotion_1': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_1', manufacture.id), + 'image_promotion_2': self.env['ir.attachment'].api_image('x_manufactures', 'image_promotion_2', manufacture.id), } return {} diff --git a/indoteknik_api/models/x_manufactures.py b/indoteknik_api/models/x_manufactures.py index 19fdcb9c..988d7a45 100644 --- a/indoteknik_api/models/x_manufactures.py +++ b/indoteknik_api/models/x_manufactures.py @@ -8,16 +8,16 @@ class Manufactures(models.Model): base_url = self.env['ir.config_parameter'].get_param('web.base.url') data = { 'id': manufacture.id, - 'logo': base_url + 'api/image/x_manufactures/x_logo_manufacture/' + str(manufacture.id) if manufacture.x_logo_manufacture else '', + 'logo': self.env['ir.attachment'].api_image('x_manufactures', 'x_logo_manufacture', manufacture.id), 'name': manufacture.x_name } if with_detail: data_with_detail = { 'description': manufacture.x_short_desc, 'banners': [ - base_url + 'api/image/x_banner.banner/x_banner_image/' + str(x.id) + self.env['ir.attachment'].api_image('x_banner.banner', 'x_banner_image', x.id) for x in manufacture.x_manufactures_banners - if x.x_status_banner == 'tayang' and x.x_banner_image + if x.x_status_banner == 'tayang' ] } data.update(data_with_detail) diff --git a/indoteknik_custom/models/ir_attachment.py b/indoteknik_custom/models/ir_attachment.py index 278eb938..fd86ab1b 100644 --- a/indoteknik_custom/models/ir_attachment.py +++ b/indoteknik_custom/models/ir_attachment.py @@ -9,4 +9,17 @@ class Attachment(models.Model): @api.autovacuum def _gc_file_store(self): - _logger.info("filestore gc checked, removed - override") \ No newline at end of file + _logger.info("filestore gc checked, removed - override") + + def is_found(self, model, field, id): + attachment = self.search([ + ('res_model', '=', model), + ('res_field', '=', field), + ('res_id', '=', int(id)) + ]) + return True if attachment else False + + def api_image(self, model, field, id): + base_url = self.env['ir.config_parameter'].get_param('web.base.url') + is_found = self.is_found(model, field, id) + return base_url + 'api/image/' + model + '/' + field + '/' + str(id) if is_found else '' \ No newline at end of file -- cgit v1.2.3 From 24907b0ab9ad83bf97ac84dc81c14b9eccd8f75a Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 23 Jan 2023 16:44:25 +0700 Subject: change to materialized view --- indoteknik_custom/models/sale_monitoring_detail.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py index d766cecd..a393f81d 100755 --- a/indoteknik_custom/models/sale_monitoring_detail.py +++ b/indoteknik_custom/models/sale_monitoring_detail.py @@ -22,7 +22,7 @@ class SaleMonitoringDetail(models.Model): def init(self): tools.drop_view_if_exists(self.env.cr, self._table) self.env.cr.execute(""" - CREATE OR REPLACE VIEW %s AS ( + CREATE MATERIALIZED VIEW %s AS ( SELECT *, CASE -- cgit v1.2.3 From 9b026c1ce5683b42dfdd15da74cf6da0ef7bf9d5 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 24 Jan 2023 08:57:04 +0700 Subject: refresh materialized view --- indoteknik_custom/models/sale_monitoring_detail.py | 11 ++++++++++- indoteknik_custom/views/sale_monitoring_detail.xml | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py index a393f81d..405b43ef 100755 --- a/indoteknik_custom/models/sale_monitoring_detail.py +++ b/indoteknik_custom/models/sale_monitoring_detail.py @@ -1,4 +1,7 @@ from odoo import fields, models, api, tools +import logging + +_logger = logging.getLogger(__name__) class SaleMonitoringDetail(models.Model): @@ -19,8 +22,14 @@ class SaleMonitoringDetail(models.Model): date_order = fields.Datetime(string="Date Order") status = fields.Char(string="Status") + def refresh_mv(self): + _logger.info('Refresh Materialized View Starting...') + self.env.cr.execute("REFRESH MATERIALIZED VIEW sale_monitoring_detail") + _logger.info("Refresh Materialized View berhasil") + def init(self): - tools.drop_view_if_exists(self.env.cr, self._table) + # tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute("DROP MATERIALIZED VIEW sale_monitoring_detail CASCADE") self.env.cr.execute(""" CREATE MATERIALIZED VIEW %s AS ( SELECT diff --git a/indoteknik_custom/views/sale_monitoring_detail.xml b/indoteknik_custom/views/sale_monitoring_detail.xml index 9e4734d3..cd87bc1a 100755 --- a/indoteknik_custom/views/sale_monitoring_detail.xml +++ b/indoteknik_custom/views/sale_monitoring_detail.xml @@ -22,6 +22,7 @@ decoration-success="status == 'SIAP KIRIM' or status == 'KIRIM SISANYA'" decoration-info="status == 'Belum Invoiced'" /> +