From bacd84a9895031fdd5ce2f7ec0074f1bcd9e0a9a Mon Sep 17 00:00:00 2001 From: Azka Nathan Date: Tue, 2 Jan 2024 15:44:20 +0700 Subject: create new window for sale detail qty_po get from matches so on po --- indoteknik_custom/__manifest__.py | 1 + indoteknik_custom/models/__init__.py | 1 + indoteknik_custom/models/automatic_purchase.py | 2 +- .../models/sale_monitoring_detail_v2.py | 68 +++++++++++++ indoteknik_custom/security/ir.model.access.csv | 3 +- .../views/sale_monitoring_detail_v2.xml | 113 +++++++++++++++++++++ 6 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 indoteknik_custom/models/sale_monitoring_detail_v2.py create mode 100644 indoteknik_custom/views/sale_monitoring_detail_v2.xml diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index d31ac21a..e7793f1c 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -106,6 +106,7 @@ 'views/wati_history.xml', 'views/purchasing_job.xml', 'views/purchasing_job_multi_update.xml', + 'views/sale_monitoring_detail_v2.xml', 'report/report.xml', 'report/report_banner_banner.xml', 'report/report_banner_banner2.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index fb986c0d..f1d0a6cf 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -98,3 +98,4 @@ from . import purchasing_job from . import purchasing_job_multi_update from . import purchase_order_sales_match from . import sales_order_purchase_match +from . import sale_monitoring_detail_v2 \ No newline at end of file diff --git a/indoteknik_custom/models/automatic_purchase.py b/indoteknik_custom/models/automatic_purchase.py index ed35835e..d0bbdb1e 100644 --- a/indoteknik_custom/models/automatic_purchase.py +++ b/indoteknik_custom/models/automatic_purchase.py @@ -67,7 +67,7 @@ class AutomaticPurchase(models.Model): if self.is_po: raise UserError('Sudah pernah di create PO') - self.validate_so_is_po() + # self.validate_so_is_po() current_time = datetime.now() vendor_ids = self.env['automatic.purchase.line'].read_group( diff --git a/indoteknik_custom/models/sale_monitoring_detail_v2.py b/indoteknik_custom/models/sale_monitoring_detail_v2.py new file mode 100644 index 00000000..1aec2bef --- /dev/null +++ b/indoteknik_custom/models/sale_monitoring_detail_v2.py @@ -0,0 +1,68 @@ +from odoo import fields, models, api, tools +import logging + +_logger = logging.getLogger(__name__) + + +class SaleMonitoringDetailV2(models.Model): + _name = 'sale.monitoring.detail.v2' + _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_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") + qty_reserved = fields.Integer(string="Qty Reserved") + note = fields.Char(string="Note") + + 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_so_delivered = qty_so then 'Delivered' + when qty_reserved >= qty_so then 'Siap kirim' + when qty_po + qty_reserved - qty_po_received < qty_so then 'Belum/Kurang PO' + when qty_po_received = 0 then 'Belum terima' + when qty_po_received < qty_po then 'Terima sebagian' + when qty_so_invoiced = qty_so then 'Invoiced' + 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, + sol.qty_delivered AS qty_so_delivered, + get_qty_to_delivered(sol.id) as qty_to_delivered, + sol.qty_invoiced AS qty_so_invoiced, + so.date_order AS date_order, + get_qty_po_matches_so(so.id, sol.product_id) AS qty_po, + get_qty_received(so.id, sol.product_id) AS qty_po_received, + get_qty_reserved(so.id, sol.product_id) as qty_reserved, + sol.note_procurement as note + 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) diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv index c22ec688..ad266bd7 100755 --- a/indoteknik_custom/security/ir.model.access.csv +++ b/indoteknik_custom/security/ir.model.access.csv @@ -90,4 +90,5 @@ access_purchasing_job_multi_update,access.purchasing.job.multi.update,model_purc access_automatic_purchase_sales_match,access.automatic.purchase.sales.match,model_automatic_purchase_sales_match,,1,1,1,1 access_v_sales_outstanding,access.v.sales.outstanding,model_v_sales_outstanding,,1,1,1,1 access_purchase_order_sales_match,access.purchase.order.sales.match,model_purchase_order_sales_match,,1,1,1,1 -access_sales_order_purchase_match,access.sale.order.purchase.match,model_sales_order_purchase_match,,1,1,1,1 \ No newline at end of file +access_sales_order_purchase_match,access.sale.order.purchase.match,model_sales_order_purchase_match,,1,1,1,1 +access_sale_monitoring_detail_v2,access.sale.monitoring.detail.v2,model_sale_monitoring_detail_v2,,1,1,1,1 \ No newline at end of file diff --git a/indoteknik_custom/views/sale_monitoring_detail_v2.xml b/indoteknik_custom/views/sale_monitoring_detail_v2.xml new file mode 100644 index 00000000..c2e7844d --- /dev/null +++ b/indoteknik_custom/views/sale_monitoring_detail_v2.xml @@ -0,0 +1,113 @@ + + + + sale.monitoring.detail.v2.tree + sale.monitoring.detail.v2 + + + + + + + + + + + + + + + + + + + + + sale.monitoring.detail.v2.form + sale.monitoring.detail.v2 + +
+ + + + + + + + + + + + + + + + + + + + +
+
+
+ + + sale.monitoring.detail.v2.list.select + sale.monitoring.detail.v2 + + + + + + + + + + + + + + Sale Monitoring Detail V2 + ir.actions.act_window + sale.monitoring.detail.v2 + + tree,form + + + + + + + + +
\ No newline at end of file -- cgit v1.2.3