diff options
Diffstat (limited to 'indoteknik_custom/models')
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 1 | ||||
| -rw-r--r-- | indoteknik_custom/models/automatic_purchase.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/sale_monitoring_detail_v2.py | 68 |
3 files changed, 70 insertions, 1 deletions
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) |
