add cost to of subcontracted purchase on production #059913

This commit is contained in:
Àngel Àlvarez Serra 2022-09-21 10:21:44 +02:00 committed by Àngel Àlvarez
parent 2ef9e82032
commit 7870289485
2 changed files with 20 additions and 0 deletions

View File

@ -9,6 +9,8 @@ from trytond import backend
from trytond.transaction import Transaction
from trytond.i18n import gettext
from trytond.exceptions import UserError
from trytond.modules.product import round_price
from decimal import Decimal
__all__ = ['Party', 'PurchaseRequest', 'BOM', 'Production', 'Purchase',
@ -297,6 +299,15 @@ class Production(metaclass=PoolMeta):
if shipments:
InternalShipment.assign_try(shipments)
def get_cost(self, name):
price = super().get_cost(name)
purchase = self.purchase_request and self.purchase_request.purchase
if not purchase:
return price
return price + purchase.untaxed_amount
# TODO: Internal shipment should be updated each time outputs are changed
class Purchase(metaclass=PoolMeta):

View File

@ -304,6 +304,8 @@ Make a subcontract production::
>>> purchase.save()
>>> Purchase.quote([purchase.id], config.context)
>>> purchase.reload()
>>> production.cost
Decimal('225.0000')
>>> purchase.state
'quotation'
>>> Purchase.confirm([purchase.id], config.context)
@ -330,3 +332,10 @@ Make a subcontract production::
>>> production.reload()
>>> production.state
'running'
>>> Production.done([production.id], config.context)
>>> production.reload()
>>> production.state
'done'
>>> output, = production.outputs
>>> output.unit_price
Decimal('112.5000')