From 752db0759177d9e804e9b57ed87e40676a4bcc5d Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Mon, 22 May 2023 14:36:57 +0700 Subject: fix sales order monitoring --- indoteknik_custom/models/sale_monitoring_detail.py | 1 + indoteknik_custom/models/sale_order.py | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models') diff --git a/indoteknik_custom/models/sale_monitoring_detail.py b/indoteknik_custom/models/sale_monitoring_detail.py index 5fd8e47a..a578f67b 100755 --- a/indoteknik_custom/models/sale_monitoring_detail.py +++ b/indoteknik_custom/models/sale_monitoring_detail.py @@ -29,6 +29,7 @@ class SaleMonitoringDetail(models.Model): SELECT *, CASE + WHEN qty_so = qty_so_invoiced then 'Done' 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_so and qty_po_received <= 0 THEN 'Belum Received sama sekali' diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 14c87641..85d7e595 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -421,9 +421,21 @@ class SaleOrderLine(models.Model): def onchange_vendor_id(self): if not self.product_id or self.product_id.type == 'service': return - purchase_price = self.env['purchase.pricelist'].search( - [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], limit=1) - self.purchase_price = purchase_price.product_price + elif self.product_id.categ_id.id == 34: # finish good / manufacturing only + print('a') + bom = self.env['mrp.bom'].search( + [('product_tmpl_id', '=', self.product_id.product_tmpl_id.id)] + , limit=1) + cost = 0 + for line in bom.bom_line_ids: + purchase_price = self.env['purchase.pricelist'].search( + [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', line.product_id.id)], limit=1) + cost += purchase_price.product_price + self.purchase_price = cost + else: + purchase_price = self.env['purchase.pricelist'].search( + [('vendor_id', '=', self.vendor_id.id), ('product_id', '=', self.product_id.id)], limit=1) + self.purchase_price = purchase_price.product_price self.purchase_tax_id = 22 @api.onchange('product_id') -- cgit v1.2.3