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 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'indoteknik_custom/models') 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 -- 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(+) (limited to 'indoteknik_custom/models') 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(-) (limited to 'indoteknik_custom/models') 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(+) (limited to 'indoteknik_custom/models') 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_custom/models/user_activity_log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models') 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_custom/models/ir_attachment.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') 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(-) (limited to 'indoteknik_custom/models') 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 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'indoteknik_custom/models') 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 -- cgit v1.2.3 From 96a00bc1ac5f114777b2f5f0f0117c1e67141caf Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Tue, 24 Jan 2023 11:41:31 +0700 Subject: refresh materialize view --- indoteknik_custom/models/sale_monitoring.py | 58 +++++++----- indoteknik_custom/models/sale_monitoring_detail.py | 101 ++++++++++++--------- 2 files changed, 89 insertions(+), 70 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_monitoring.py b/indoteknik_custom/models/sale_monitoring.py index a837a6bc..a3265a8b 100755 --- a/indoteknik_custom/models/sale_monitoring.py +++ b/indoteknik_custom/models/sale_monitoring.py @@ -1,5 +1,7 @@ from odoo import fields, models, api, tools +import logging +_logger = logging.getLogger(__name__) class SaleMonitoring(models.Model): _name = 'sale.monitoring' @@ -22,29 +24,35 @@ class SaleMonitoring(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 ( - SELECT - smd.sale_order_id AS id, - smd.date_order, - smd.sale_order_id, - smd.partner_id, - smd.user_id, - SUM(smd.qty_so) AS qty_so, - SUM(smd.qty_po) AS qty_po, - SUM(smd.qty_po_received) AS qty_po_received, - SUM(smd.qty_so_delivered) AS qty_so_delivered, - SUM(smd.qty_so_invoiced) AS qty_so_invoiced, - CASE - WHEN SUM(qty_po) < SUM(qty_so) AND SUM(qty_po) <= 0 THEN 'Belum PO sama sekali' - WHEN SUM(qty_po) < SUM(qty_so) THEN 'Belum PO full' - WHEN SUM(qty_po_received) < SUM(qty_so) AND SUM(qty_po_received) <= 0 THEN 'Belum Received sama sekali' - WHEN SUM(qty_po_received) < SUM(qty_so) THEN 'Belum Received full' - WHEN SUM(qty_to_delivered) = SUM(qty_so) THEN 'SIAP KIRIM' - WHEN SUM(qty_to_delivered) < SUM(qty_so) and SUM(qty_to_delivered) > 0 THEN 'KIRIM SISANYA' - ELSE 'Belum Invoiced' - END AS status, - get_po_number(smd.sale_order_id) as po_number - FROM sale_monitoring_detail smd - GROUP BY smd.date_order, smd.sale_order_id, smd.partner_id, smd.user_id - ) + CREATE OR REPLACE VIEW %s AS ( + SELECT + smd.sale_order_id AS id, + smd.date_order, + smd.sale_order_id, + smd.partner_id, + smd.user_id, + SUM(smd.qty_so) AS qty_so, + SUM(smd.qty_po) AS qty_po, + SUM(smd.qty_po_received) AS qty_po_received, + SUM(smd.qty_so_delivered) AS qty_so_delivered, + SUM(smd.qty_so_invoiced) AS qty_so_invoiced, + CASE + WHEN SUM(qty_po) < SUM(qty_so) AND SUM(qty_po) <= 0 THEN 'Belum PO sama sekali' + WHEN SUM(qty_po) < SUM(qty_so) THEN 'Belum PO full' + WHEN SUM(qty_po_received) < SUM(qty_so) AND SUM(qty_po_received) <= 0 THEN 'Belum Received sama sekali' + WHEN SUM(qty_po_received) < SUM(qty_so) THEN 'Belum Received full' + WHEN SUM(qty_to_delivered) = SUM(qty_so) THEN 'SIAP KIRIM' + WHEN SUM(qty_to_delivered) < SUM(qty_so) and SUM(qty_to_delivered) > 0 THEN 'KIRIM SISANYA' + ELSE 'Belum Invoiced' + END AS status, + get_po_number(smd.sale_order_id) as po_number + FROM sale_monitoring_detail smd + GROUP BY smd.date_order, smd.sale_order_id, smd.partner_id, smd.user_id + ) """ % self._table) + + def action_refresh(self): + _logger.info("Refresh %s View Starting..." % self._table) + self.env.cr.execute("REFRESH MATERIALIZED VIEW sale_monitoring_detail") + _logger.info("Refresh %s View Success" % self._table) + \ No newline at end of file diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py index 405b43ef..553ec21f 100755 --- a/indoteknik_custom/models/sale_monitoring_detail.py +++ b/indoteknik_custom/models/sale_monitoring_detail.py @@ -22,52 +22,63 @@ 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) - self.env.cr.execute("DROP MATERIALIZED VIEW sale_monitoring_detail CASCADE") + self._drop_view() + self.env.cr.execute("SELECT matviewname from pg_matviews where schemaname = 'public' and matviewname = '%s'" % self._table) + materialized_view = self.env.cr.fetchone() + if materialized_view is None: + self._init_materialized_view() + + def action_refresh(self): + _logger.info("Refresh %s View Starting..." % self._table) + self.env.cr.execute("REFRESH MATERIALIZED VIEW %s" % self._table) + _logger.info("Refresh %s View Success" % self._table) + + def _drop_view(self): + self.env.cr.execute("SELECT viewname from pg_views where schemaname = 'public' and viewname = '%s'" % self._table) + standard_view = self.env.cr.fetchone() + if standard_view is not None: + self.env.cr.execute("DROP VIEW %s CASCADE" % self._table) + + def _init_materialized_view(self): self.env.cr.execute(""" - CREATE MATERIALIZED VIEW %s AS ( - SELECT - *, - CASE - WHEN qty_po < qty_so AND qty_po <= 0 THEN 'Belum PO sama sekali' - WHEN qty_po < qty_so THEN 'Belum PO full' - WHEN qty_po_received < qty_so and qty_po_received <= 0 THEN 'Belum Received sama sekali' - WHEN qty_po_received < qty_so THEN 'Belum Received full' - WHEN qty_to_delivered = qty_so THEN 'SIAP KIRIM' - WHEN qty_to_delivered < qty_so and qty_to_delivered > 0 THEN 'KIRIM SISANYA' - ELSE 'Belum Invoiced' - END AS status - FROM - ( + CREATE MATERIALIZED VIEW %s AS ( SELECT - sol.id AS id, - so.id AS sale_order_id, - so.partner_id as partner_id, - so.user_id, - p.id AS product_id, - sol.product_uom_qty AS qty_so, - sol.qty_delivered AS qty_so_delivered, - get_qty_to_delivered(sol.id) as qty_to_delivered, - sol.qty_invoiced AS qty_so_invoiced, - so.date_order AS date_order, - get_qty_po(so.id, sol.product_id) AS qty_po, - get_qty_received(so.id, sol.product_id) AS qty_po_received - FROM sale_order so - JOIN sale_order_line sol ON sol.order_id = so.id - JOIN product_product p ON p.id = sol.product_id - JOIN product_template pt ON pt.id = p.product_tmpl_id - WHERE pt.type IN ('consu','product') - AND so.state IN ('sale','done') - AND so.create_date >= '2022-08-10' - ) a - WHERE - a.qty_so_delivered > a.qty_so_invoiced - or a.qty_to_delivered > 0 - ) + *, + CASE + WHEN qty_po < qty_so AND qty_po <= 0 THEN 'Belum PO sama sekali' + WHEN qty_po < qty_so THEN 'Belum PO full' + WHEN qty_po_received < qty_so and qty_po_received <= 0 THEN 'Belum Received sama sekali' + WHEN qty_po_received < qty_so THEN 'Belum Received full' + WHEN qty_to_delivered = qty_so THEN 'SIAP KIRIM' + WHEN qty_to_delivered < qty_so and qty_to_delivered > 0 THEN 'KIRIM SISANYA' + ELSE 'Belum Invoiced' + END AS status + FROM + ( + SELECT + sol.id AS id, + so.id AS sale_order_id, + so.partner_id as partner_id, + so.user_id, + p.id AS product_id, + sol.product_uom_qty AS qty_so, + sol.qty_delivered AS qty_so_delivered, + get_qty_to_delivered(sol.id) as qty_to_delivered, + sol.qty_invoiced AS qty_so_invoiced, + so.date_order AS date_order, + get_qty_po(so.id, sol.product_id) AS qty_po, + get_qty_received(so.id, sol.product_id) AS qty_po_received + FROM sale_order so + JOIN sale_order_line sol ON sol.order_id = so.id + JOIN product_product p ON p.id = sol.product_id + JOIN product_template pt ON pt.id = p.product_tmpl_id + WHERE pt.type IN ('consu','product') + AND so.state IN ('sale','done') + AND so.create_date >= '2022-08-10' + ) a + WHERE + a.qty_so_delivered > a.qty_so_invoiced + or a.qty_to_delivered > 0 + ) """ % self._table) -- cgit v1.2.3