summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-04-27 10:41:15 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-04-27 10:41:15 +0700
commit04216fb6fc1ecc1bba78b7f0ed50195d3876b287 (patch)
tree4909d48824a70b008857af651083ca424857c937 /indoteknik_custom/models
parentaad3d92f97ad443c9288a5b51e618a112deb981e (diff)
add menu procurement monitoring
Diffstat (limited to 'indoteknik_custom/models')
-rwxr-xr-xindoteknik_custom/models/__init__.py1
-rw-r--r--indoteknik_custom/models/procurement_monitoring_detail.py55
2 files changed, 56 insertions, 0 deletions
diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py
index d6c88f7d..68b7df93 100755
--- a/indoteknik_custom/models/__init__.py
+++ b/indoteknik_custom/models/__init__.py
@@ -59,3 +59,4 @@ from . import uangmuka_pembelian
from . import automatic_purchase
from . import apache_solr
from . import raja_ongkir
+from . import procurement_monitoring_detail
diff --git a/indoteknik_custom/models/procurement_monitoring_detail.py b/indoteknik_custom/models/procurement_monitoring_detail.py
new file mode 100644
index 00000000..348fce68
--- /dev/null
+++ b/indoteknik_custom/models/procurement_monitoring_detail.py
@@ -0,0 +1,55 @@
+from odoo import fields, models, api, tools
+import logging
+
+_logger = logging.getLogger(__name__)
+
+
+class SaleMonitoringDetail(models.Model):
+ _name = 'procurement.monitoring.detail'
+ _auto = False
+ _rec_name = 'sale_order_id'
+
+ id = fields.Integer()
+ sale_order_id = fields.Many2one("sale.order", string="Sale Order")
+ partner_id = fields.Many2one("res.partner", string="Customer")
+ user_id = fields.Many2one("res.users", string="Salesperson")
+ product_id = fields.Many2one("product.product", string="Product")
+ qty_so = fields.Integer(string="Qty SO")
+ qty_reserved = fields.Integer(string="Qty Reserved")
+ qty_available = fields.Integer(string="Qty Available")
+ qty_po = fields.Integer(string="Qty PO")
+ date_order = fields.Datetime(string="Date Order")
+ status = fields.Char(string="Status")
+
+ def init(self):
+ tools.drop_view_if_exists(self.env.cr, self._table)
+ self.env.cr.execute("""
+ CREATE OR REPLACE VIEW %s AS (
+ SELECT
+ *,
+ a.qty_so-a.qty_reserved as qty_po,
+ case when a.qty_so-a.qty_reserved > 0 then 'harus beli'
+ else 'cukup' 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,
+ get_qty_available(sol.product_id) as qty_available,
+ get_qty_reserved(so.id, sol.product_id) as qty_reserved,
+ so.date_order AS date_order
+ 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'
+ and so.so_status not in ('terproses')
+ ) a
+ )
+ """ % self._table)