diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2022-08-16 09:48:12 +0700 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2022-08-16 09:48:12 +0700 |
| commit | 66579ea9e7ac7e10cf1593e87669f36bc6f6d8c8 (patch) | |
| tree | ce095325c94ff11f8322739604347c48f815d123 | |
| parent | cbcf8d34bdc4d0ac2c47184dc46a3393d43bf145 (diff) | |
Restructure sale.monitoring and sale.monitoring.detail & Create view
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_monitoring.py | 63 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_monitoring_detail.py | 61 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sum_sale_monitoring.py | 32 | ||||
| -rwxr-xr-x | indoteknik_custom/security/ir.model.access.csv | 3 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_monitoring.xml | 41 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_monitoring_detail.xml | 89 |
8 files changed, 208 insertions, 83 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index d18f1582..58b8a3df 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -17,6 +17,7 @@ 'views/purchase_order.xml', 'views/purchase_pricelist.xml', 'views/sale_monitoring.xml', + 'views/sale_monitoring_detail.xml', 'views/user_activity_log.xml', 'views/vit_kelurahan.xml', 'views/vit_kecamatan.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index 03b01fc4..f98d7c58 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -15,3 +15,4 @@ from . import purchase_order from . import purchase_pricelist from . import purchase_order_line from . import sale_monitoring +from . import sale_monitoring_detail diff --git a/indoteknik_custom/models/sale_monitoring.py b/indoteknik_custom/models/sale_monitoring.py index 6fabb2df..70c51132 100755 --- a/indoteknik_custom/models/sale_monitoring.py +++ b/indoteknik_custom/models/sale_monitoring.py @@ -8,52 +8,37 @@ class SaleMonitoring(models.Model): id = fields.Integer() sale_order_id = fields.Many2one("sale.order", string="Sale Order") - status = fields.Char(string="Status") - product_id = fields.Many2one("product.product", string="Product") qty_so = fields.Integer(string="Qty SO") - qty_so_delivered = fields.Integer(string="Qty SO Delivered") - qty_so_invoiced = fields.Integer(string="Qty SO Invoiced") qty_po = fields.Integer(string="Qty PO") qty_po_received = fields.Integer(string="Qty PO Received") + qty_so_delivered = fields.Integer(string="Qty SO Delivered") + qty_so_invoiced = fields.Integer(string="Qty SO Invoiced") 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 - *, 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_po and qty_po_received <= 0 then 'Belum Received sama sekali' - when qty_po_received <> qty_po then 'Belum Received full' - when qty_so_delivered <> qty_so and qty_so_delivered <= 0 then 'SIAP KIRIM' - when qty_so_delivered <> qty_so then 'KIRIM SISANYA' - else 'Belum Invoiced' end as status - from - ( - SELECT - p.id AS id, - so.id AS sale_order_id, - p.id as product_id, - sol.product_uom_qty AS qty_so, - sol.qty_delivered AS qty_so_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 <> a.qty_so_delivered - or a.qty_so <> a.qty_so_invoiced - or a.qty_so <> a.qty_po - or a.qty_so <> a.qty_po_received + CREATE OR REPLACE VIEW %s AS ( + SELECT + smd.sale_order_id AS id, + smd.date_order, + smd.sale_order_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_po) AND SUM(qty_po_received) <= 0 THEN 'Belum Received sama sekali' + WHEN SUM(qty_po_received) <> SUM(qty_po) THEN 'Belum Received full' + WHEN SUM(qty_so_delivered) <> SUM(qty_so) AND SUM(qty_so_delivered) <= 0 THEN 'SIAP KIRIM' + WHEN SUM(qty_so_delivered) <> SUM(qty_so) THEN 'KIRIM SISANYA' + ELSE 'Belum Invoiced' + END AS status + FROM sale_monitoring_detail smd + GROUP BY smd.date_order, smd.sale_order_id ) """ % self._table) diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py new file mode 100755 index 00000000..ec9fe222 --- /dev/null +++ b/indoteknik_custom/models/sale_monitoring_detail.py @@ -0,0 +1,61 @@ +from odoo import fields, models, api, tools + + +class SaleMonitoringDetail(models.Model): + _name = 'sale.monitoring.detail' + _auto = False + _rec_name = 'sale_order_id' + + id = fields.Integer() + sale_order_id = fields.Many2one("sale.order", string="Sale Order") + product_id = fields.Many2one("product.product", string="Product") + qty_so = fields.Integer(string="Qty SO") + qty_po = fields.Integer(string="Qty PO") + qty_po_received = fields.Integer(string="Qty PO Received") + qty_so_delivered = fields.Integer(string="Qty SO Delivered") + qty_so_invoiced = fields.Integer(string="Qty SO Invoiced") + 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 + *, + 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_po and qty_po_received <= 0 THEN 'Belum Received sama sekali' + WHEN qty_po_received <> qty_po THEN 'Belum Received full' + WHEN qty_so_delivered <> qty_so AND qty_so_delivered <= 0 THEN 'SIAP KIRIM' + WHEN qty_so_delivered <> qty_so THEN 'KIRIM SISANYA' + ELSE 'Belum Invoiced' + END AS status + FROM + ( + SELECT + p.id AS id, + so.id AS sale_order_id, + p.id AS product_id, + sol.product_uom_qty AS qty_so, + sol.qty_delivered AS qty_so_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 <> a.qty_so_delivered + OR a.qty_so <> a.qty_so_invoiced + OR a.qty_so <> a.qty_po + OR a.qty_so <> a.qty_po_received + ) + """ % self._table) diff --git a/indoteknik_custom/models/sum_sale_monitoring.py b/indoteknik_custom/models/sum_sale_monitoring.py deleted file mode 100755 index bb392bcf..00000000 --- a/indoteknik_custom/models/sum_sale_monitoring.py +++ /dev/null @@ -1,32 +0,0 @@ -from odoo import fields, models, api, tools - -class SumSaleMonitoring(models.Model): - _name = 'sum.sale.monitoring' - _auto = False - _rec_name = 'sale_order_id' - - date_order = fields.Datetime(string="Date Order") - sale_order_id = fields.Many2one("sale.order", string="Sale Order") - qty_so = fields.Integer(string="Qty SO") - qty_po = fields.Integer(string="Qty PO") - qty_po_received = fields.Integer(string="Qty PO Received") - qty_so_delivered = fields.Integer(string="Qty SO Delivered") - qty_so_invoiced = fields.Integer(string="Qty SO Invoiced") - status = fields.Char(string="Status") - - def init(self): - tools.drop_view_if_exists(self.env.cr, self._table) - self.env.cr.execute(""" - select sm.date_order, sm.sale_order_id, sum(sm.qty_so) as qty_so, sum(sm.qty_po) as qty_po, - sum(sm.qty_po_received) as qty_received, sum(sm.qty_so_delivered) as qty_delivered, sum(sm.qty_so_invoiced) as qty_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_po) and sum(qty_po_received) <= 0 then 'Belum Received sama sekali' - when sum(qty_po_received) <> sum(qty_po) then 'Belum Received full' - when sum(qty_so_delivered) <> sum(qty_so) and sum(qty_so_delivered) <= 0 then 'SIAP KIRIM' - when sum(qty_so_delivered) <> sum(qty_so) then 'KIRIM SISANYA' - else 'Belum Invoiced' end as status - from sale_monitoring sm - group by sm.date_order, sm.sale_order_id - """ % self._table)
\ No newline at end of file diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index 60667274..08d8b519 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -8,4 +8,5 @@ access_x_product_tags,access.x.product.tags,model_x_product_tags,,1,1,1,1 access_stock_vendor,access.stock.vendor,model_stock_vendor,,1,1,1,1 access_user_activity_log,access.user.activity.log,model_user_activity_log,,1,1,1,1 access_purchase_pricelist,access.purchase.pricelist,model_purchase_pricelist,,1,1,1,1 -access_sale_monitoring,access.sale.monitoring,model_sale_monitoring,,1,1,1,1
\ No newline at end of file +access_sale_monitoring,access.sale.monitoring,model_sale_monitoring,,1,1,1,1 +access_sale_monitoring_detail,access.sale.monitoring.detail,model_sale_monitoring_detail,,1,1,1,1
\ No newline at end of file diff --git a/indoteknik_custom/views/sale_monitoring.xml b/indoteknik_custom/views/sale_monitoring.xml index 275fd205..15b55e2e 100755 --- a/indoteknik_custom/views/sale_monitoring.xml +++ b/indoteknik_custom/views/sale_monitoring.xml @@ -7,7 +7,6 @@ <tree create="false"> <field name="date_order"/> <field name="sale_order_id"/> - <field name="product_id"/> <field name="qty_so"/> <field name="qty_po"/> <field name="qty_po_received"/> @@ -33,7 +32,6 @@ <group> <group> <field name="sale_order_id"/> - <field name="product_id"/> <field name="status" widget="badge" decoration-danger="status == 'Belum PO sama sekali' or status == 'Belum PO full'" @@ -63,26 +61,47 @@ </record> <menuitem - id="menu_sale_monitoring_in_purchase" - name="Sale Monitoring" + id="menu_monitoring_in_sale" + name="Monitoring" + parent="sale.sale_menu_root" + sequence="101" + /> + + <menuitem + id="menu_monitoring_in_purchase" + name="Monitoring" parent="purchase.menu_purchase_root" - sequence="100" + sequence="101" + /> + + <menuitem + id="menu_monitoring_in_stock" + name="Monitoring" + parent="stock.menu_stock_root" + sequence="101" + /> + + <menuitem + id="menu_sale_monitoring_in_purchase" + name="Sale" + parent="menu_monitoring_in_purchase" + sequence="1" action="sale_monitoring_action" /> <menuitem id="menu_sale_monitoring_in_sale" - name="Sale Monitoring" - parent="sale.sale_menu_root" - sequence="100" + name="Sale" + parent="menu_monitoring_in_sale" + sequence="1" action="sale_monitoring_action" /> <menuitem id="menu_sale_monitoring_in_stock" - name="Sale Monitoring" - parent="stock.menu_stock_root" - sequence="100" + name="Sale" + parent="menu_monitoring_in_stock" + sequence="1" action="sale_monitoring_action" /> diff --git a/indoteknik_custom/views/sale_monitoring_detail.xml b/indoteknik_custom/views/sale_monitoring_detail.xml new file mode 100755 index 00000000..3a3ea787 --- /dev/null +++ b/indoteknik_custom/views/sale_monitoring_detail.xml @@ -0,0 +1,89 @@ +<?xml version="1.0" encoding="utf-8" ?> +<odoo> + <record id="sale_monitoring_detail_tree" model="ir.ui.view"> + <field name="name">sale.monitoring.detail.tree</field> + <field name="model">sale.monitoring.detail</field> + <field name="arch" type="xml"> + <tree create="false"> + <field name="date_order"/> + <field name="sale_order_id"/> + <field name="product_id"/> + <field name="qty_so"/> + <field name="qty_po"/> + <field name="qty_po_received"/> + <field name="qty_so_delivered"/> + <field name="qty_so_invoiced"/> + <field name="status" + widget="badge" + decoration-danger="status == 'Belum PO sama sekali' or status == 'Belum PO full'" + decoration-warning="status == 'Belum Received sama sekali' or status == 'Belum Received full'" + decoration-success="status == 'SIAP KIRIM' or status == 'KIRIM SISANYA'" + decoration-info="status == 'Belum Invoiced'" + /> + </tree> + </field> + </record> + + <record id="sale_monitoring_detail_form" model="ir.ui.view"> + <field name="name">sale.monitoring.detail.form</field> + <field name="model">sale.monitoring.detail</field> + <field name="arch" type="xml"> + <form create="false" edit="false"> + <sheet> + <group> + <group> + <field name="sale_order_id"/> + <field name="product_id"/> + <field name="status" + widget="badge" + decoration-danger="status == 'Belum PO sama sekali' or status == 'Belum PO full'" + decoration-warning="status == 'Belum Received sama sekali' or status == 'Belum Received full'" + decoration-success="status == 'SIAP KIRIM' or status == 'KIRIM SISANYA'" + decoration-info="status == 'Belum Invoiced'" + /> + </group> + <group> + <field name="qty_so"/> + <field name="qty_po"/> + <field name="qty_po_received"/> + <field name="qty_so_delivered"/> + <field name="qty_so_invoiced"/> + </group> + </group> + </sheet> + </form> + </field> + </record> + + <record id="sale_monitoring_detail_action" model="ir.actions.act_window"> + <field name="name">Sale Monitoring Detail</field> + <field name="type">ir.actions.act_window</field> + <field name="res_model">sale.monitoring.detail</field> + <field name="view_mode">tree,form</field> + </record> + + <menuitem + id="menu_sale_monitoring_detail_in_purchase" + name="Sale Detail" + parent="menu_monitoring_in_purchase" + sequence="2" + action="sale_monitoring_detail_action" + /> + + <menuitem + id="menu_sale_monitoring_detail_in_sale" + name="Sale Detail" + parent="menu_monitoring_in_sale" + sequence="2" + action="sale_monitoring_detail_action" + /> + + <menuitem + id="menu_sale_monitoring_detail_in_stock" + name="Sale Detail" + parent="menu_monitoring_in_stock" + sequence="2" + action="sale_monitoring_detail_action" + /> + +</odoo>
\ No newline at end of file |
