mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
automato fill purchase price #1509
This commit is contained in:
parent
126c5ca3bf
commit
c14478ed1f
@ -223,7 +223,7 @@ class PurchaseOrder(Order):
|
|||||||
return reverse('po-detail', kwargs={'pk': self.id})
|
return reverse('po-detail', kwargs={'pk': self.id})
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def add_line_item(self, supplier_part, quantity, group=True, reference=''):
|
def add_line_item(self, supplier_part, quantity, group=True, reference='', purchase_price=None):
|
||||||
""" Add a new line item to this purchase order.
|
""" Add a new line item to this purchase order.
|
||||||
This function will check that:
|
This function will check that:
|
||||||
|
|
||||||
@ -254,7 +254,11 @@ class PurchaseOrder(Order):
|
|||||||
if matches.count() > 0:
|
if matches.count() > 0:
|
||||||
line = matches.first()
|
line = matches.first()
|
||||||
|
|
||||||
line.quantity += quantity
|
# update quantity and price
|
||||||
|
quantity_new = line.quantity + quantity
|
||||||
|
line.quantity = quantity_new
|
||||||
|
if purchase_price:
|
||||||
|
line.purchase_price = supplier_part.get_price(quantity_new) / quantity_new
|
||||||
line.save()
|
line.save()
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -263,7 +267,9 @@ class PurchaseOrder(Order):
|
|||||||
order=self,
|
order=self,
|
||||||
part=supplier_part,
|
part=supplier_part,
|
||||||
quantity=quantity,
|
quantity=quantity,
|
||||||
reference=reference)
|
reference=reference,
|
||||||
|
purchase_price=purchase_price,
|
||||||
|
)
|
||||||
|
|
||||||
line.save()
|
line.save()
|
||||||
|
|
||||||
|
@ -996,6 +996,7 @@ class OrderParts(AjaxView):
|
|||||||
|
|
||||||
part.order_supplier = supplier_part.id if supplier_part else None
|
part.order_supplier = supplier_part.id if supplier_part else None
|
||||||
part.order_quantity = quantity
|
part.order_quantity = quantity
|
||||||
|
part.purchase_price = supplier_part.get_price(quantity) / quantity if supplier_part else None
|
||||||
|
|
||||||
self.parts.append(part)
|
self.parts.append(part)
|
||||||
|
|
||||||
@ -1096,7 +1097,10 @@ class OrderParts(AjaxView):
|
|||||||
sp=item.order_supplier))
|
sp=item.order_supplier))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
order.add_line_item(supplier_part, quantity)
|
# get purchase price
|
||||||
|
purchase_price = item.purchase_price if item.purchase_price else None
|
||||||
|
|
||||||
|
order.add_line_item(supplier_part, quantity, purchase_price=purchase_price)
|
||||||
|
|
||||||
|
|
||||||
class POLineItemCreate(AjaxCreateView):
|
class POLineItemCreate(AjaxCreateView):
|
||||||
|
Loading…
Reference in New Issue
Block a user