From 5f30895ed87d0e611a7035070c9ea01fa8e5bfeb Mon Sep 17 00:00:00 2001 From: IT Fixcomart Date: Fri, 12 Aug 2022 11:49:44 +0700 Subject: Sale monitoring --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/sale_monitoring.py | 50 +++++++++++++++++++++++++ indoteknik_custom/security/ir.model.access.csv | 3 +- indoteknik_custom/views/sale_monitoring.xml | 51 ++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 indoteknik_custom/models/sale_monitoring.py create mode 100644 indoteknik_custom/views/sale_monitoring.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 8de5bebc..d18f1582 100644 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -16,6 +16,7 @@ 'views/product_template.xml', 'views/purchase_order.xml', 'views/purchase_pricelist.xml', + 'views/sale_monitoring.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 30914b52..03b01fc4 100644 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -14,3 +14,4 @@ from . import user_activity_log from . import purchase_order from . import purchase_pricelist from . import purchase_order_line +from . import sale_monitoring diff --git a/indoteknik_custom/models/sale_monitoring.py b/indoteknik_custom/models/sale_monitoring.py new file mode 100644 index 00000000..6a558669 --- /dev/null +++ b/indoteknik_custom/models/sale_monitoring.py @@ -0,0 +1,50 @@ +from odoo import fields, models, api, tools + + +class SaleMonitoring(models.Model): + _name = 'sale.monitoring' + _auto = False + + id = fields.Integer() + name = fields.Char(string="Name") + product_name = fields.Char(string="Product Name") + default_code = fields.Char(string="Default Code") + 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") + + def init(self): + tools.drop_view_if_exists(self.env.cr, self._table) + self.env.cr.execute(""" + CREATE or REPLACE VIEW %s as ( + SELECT + p.id AS id, + so.name AS name, + p.default_code AS default_code, + pt.name as product_name, + sol.product_uom_qty AS qty_so, + sol.qty_delivered AS qty_so_delivered, + sol.qty_invoiced AS qty_so_invoiced, + ( + SELECT SUM(product_uom_qty) + FROM purchase_order_line pol + JOIN purchase_order poo ON poo.id = pol.order_id + WHERE poo.sale_order_id = so.id AND pol.product_id = sol.product_id + ) AS qty_po, + ( + SELECT SUM(qty_received) + FROM purchase_order_line pol + JOIN purchase_order poo ON poo.id = pol.order_id + WHERE poo.sale_order_id = so.id AND pol.product_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') + AND so.create_date >= '2022-08-10' + ) + """ % self._table) diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index dc18fd33..60667274 100644 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -7,4 +7,5 @@ access_x_partner_purchase_order,access.x.partner.purchase.order,model_x_partner_ 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 \ No newline at end of file +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 diff --git a/indoteknik_custom/views/sale_monitoring.xml b/indoteknik_custom/views/sale_monitoring.xml new file mode 100644 index 00000000..3c160e19 --- /dev/null +++ b/indoteknik_custom/views/sale_monitoring.xml @@ -0,0 +1,51 @@ + + + + sale.monitoring.tree + sale.monitoring + + + + + + + + + + + + + + + + Sale Monitoring + ir.actions.act_window + sale.monitoring + tree + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3