diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-01-24 11:41:31 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-01-24 11:41:31 +0700 |
| commit | 96a00bc1ac5f114777b2f5f0f0117c1e67141caf (patch) | |
| tree | 7200fbc52eda409d9bd45fb42a635dd0c76bf7b2 /indoteknik_custom/models/sale_monitoring.py | |
| parent | 9b026c1ce5683b42dfdd15da74cf6da0ef7bf9d5 (diff) | |
refresh materialize view
Diffstat (limited to 'indoteknik_custom/models/sale_monitoring.py')
| -rwxr-xr-x | indoteknik_custom/models/sale_monitoring.py | 58 |
1 files changed, 33 insertions, 25 deletions
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 |
