summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/sale_order.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-05-22 14:36:57 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-05-22 14:36:57 +0700
commit752db0759177d9e804e9b57ed87e40676a4bcc5d (patch)
tree9acb5c7f42c0e67f645ac4c5efce14d521f32989 /indoteknik_custom/models/sale_order.py
parentd63a3069a30c944b63d784625f046d3e7363eebd (diff)
fix sales order monitoring
Diffstat (limited to 'indoteknik_custom/models/sale_order.py')
-rwxr-xr-xindoteknik_custom/models/sale_order.py18
1 files changed, 15 insertions, 3 deletions
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')