automato fill purchase price #1509

This commit is contained in:
Matthias 2021-04-22 19:31:04 +02:00
parent 126c5ca3bf
commit c14478ed1f
2 changed files with 14 additions and 4 deletions

View File

@ -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()

View File

@ -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):