diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-05-17 15:01:34 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-05-17 15:01:34 +0700 |
| commit | 1545c0341e36811ad23d4b465e2e5194f7b0162a (patch) | |
| tree | 11c881332ad946c18f8106543fe57413fa945b14 /indoteknik_custom/models | |
| parent | b7387d281425da2a72f202aac78c5800866a7117 (diff) | |
fix sale monitoring
Diffstat (limited to 'indoteknik_custom/models')
| -rwxr-xr-x | indoteknik_custom/models/sale_monitoring_detail.py | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py index 82bd5c48..5fd8e47a 100755 --- a/indoteknik_custom/models/sale_monitoring_detail.py +++ b/indoteknik_custom/models/sale_monitoring_detail.py @@ -23,26 +23,9 @@ class SaleMonitoringDetail(models.Model): status = fields.Char(string="Status") def init(self): - 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): + tools.drop_view_if_exists(self.env.cr, self._table) self.env.cr.execute(""" - CREATE MATERIALIZED VIEW %s AS ( + CREATE OR REPLACE VIEW %s AS ( SELECT *, CASE @@ -76,10 +59,7 @@ class SaleMonitoringDetail(models.Model): WHERE pt.type IN ('consu','product') AND so.state IN ('sale','done') AND so.create_date >= '2022-08-10' - and sol.product_uom_qty > get_qty_available(sol.product_id) - ) a - WHERE - a.qty_so_delivered > a.qty_so_invoiced - or a.qty_to_delivered > 0 + and so.so_status not in('terproses') + ) a ) """ % self._table) |
