From 74226f9b0b2d1d70c33fc520cdcbf32393e528ea Mon Sep 17 00:00:00 2001 From: Bernat Brunet Date: Wed, 26 Oct 2022 01:17:54 +0200 Subject: [PATCH] Change the way that the cost of operations are calculated when have subcontracted product. If the operation have a purchase line us it's cost, if not, but have a subcontract product use it cost, and if has nothing us the default way. --- operation.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/operation.py b/operation.py index 1f03be3..3cfd9be 100644 --- a/operation.py +++ b/operation.py @@ -462,9 +462,18 @@ class OperationSubcontrat(metaclass=PoolMeta): cls.save(to_save) def get_cost(self, name): - cost = super().get_cost(name) + pool = Pool() + Uom = pool.get('product.uom') + if self.purchase_request and self.purchase_request.purchase_line: - cost += self.purchase_request.purchase_line.amount + cost = self.purchase_request.purchase_line.amount + elif self.subcontracted_product: + quantity = Uom.compute_qty(self.uom, self.total_quantity, + self.subcontracted_product.default_uom) + cost = (Decimal(str(quantity)) * + self.subcontracted_product.cost_price) + else: + cost = super().get_cost(name) return cost @classmethod