summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-01-24 11:43:52 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-01-24 11:43:52 +0700
commit2a3a0a7e88ef24456eeda070a7d74f1457efdb18 (patch)
tree2bb4cd374d46b5d5e4fb6e32fe239c5ccc83daf4 /indoteknik_custom/models
parent287cf8497b4b6bb825870ee2b3d1b49d4c29ab6a (diff)
parent646b9e22fc11f6f1d1b556761a3df2df61f8f59b (diff)
Merge branch 'release' into staging
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/crm_lead.py9
-rw-r--r--indoteknik_custom/models/ir_attachment.py15
-rwxr-xr-xindoteknik_custom/models/sale_monitoring.py58
-rwxr-xr-xindoteknik_custom/models/sale_monitoring_detail.py98
-rwxr-xr-xindoteknik_custom/models/stock_vendor.py36
-rwxr-xr-xindoteknik_custom/models/user_activity_log.py3
6 files changed, 145 insertions, 74 deletions
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:
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
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 d766cecd..553ec21f 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):
@@ -20,45 +23,62 @@ class SaleMonitoringDetail(models.Model):
status = fields.Char(string="Status")
def init(self):
- tools.drop_view_if_exists(self.env.cr, self._table)
+ 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 OR REPLACE 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)
diff --git a/indoteknik_custom/models/stock_vendor.py b/indoteknik_custom/models/stock_vendor.py
index 1a6b4a64..1e5bce16 100755
--- a/indoteknik_custom/models/stock_vendor.py
+++ b/indoteknik_custom/models/stock_vendor.py
@@ -11,27 +11,47 @@ 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'),
+ ])
+
+ templates = []
+ for stock in stocks:
+ 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))
- @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/models/user_activity_log.py b/indoteknik_custom/models/user_activity_log.py
index 3cf7bd58..32b389a1 100755
--- a/indoteknik_custom/models/user_activity_log.py
+++ b/indoteknik_custom/models/user_activity_log.py
@@ -70,7 +70,8 @@ class UserActivityLog(models.Model):
activity_logs = self.env['user.activity.log'].search([
('url', 'ilike', 'https://indoteknik.co%/shop/product/%'),
('create_date', '>', delta_time),
- ], limit=4000)
+ ('url', 'not ilike', 'shopping'),
+ ], limit=1000)
for activity_log in activity_logs:
_logger.info(activity_log.url)
strip_index = i = 0