mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
Merge branch 'master' of github.com:inventree/InvenTree into multi_part_forms
This commit is contained in:
@ -223,7 +223,7 @@ class PurchaseOrder(Order):
|
||||
return reverse('po-detail', kwargs={'pk': self.id})
|
||||
|
||||
@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.
|
||||
This function will check that:
|
||||
|
||||
@ -254,7 +254,12 @@ class PurchaseOrder(Order):
|
||||
if matches.count() > 0:
|
||||
line = matches.first()
|
||||
|
||||
line.quantity += quantity
|
||||
# update quantity and price
|
||||
quantity_new = line.quantity + quantity
|
||||
line.quantity = quantity_new
|
||||
supplier_price = supplier_part.get_price(quantity_new)
|
||||
if line.purchase_price and supplier_price:
|
||||
line.purchase_price = supplier_price / quantity_new
|
||||
line.save()
|
||||
|
||||
return
|
||||
@ -263,7 +268,9 @@ class PurchaseOrder(Order):
|
||||
order=self,
|
||||
part=supplier_part,
|
||||
quantity=quantity,
|
||||
reference=reference)
|
||||
reference=reference,
|
||||
purchase_price=purchase_price,
|
||||
)
|
||||
|
||||
line.save()
|
||||
|
||||
@ -329,7 +336,7 @@ class PurchaseOrder(Order):
|
||||
return self.pending_line_items().count() == 0
|
||||
|
||||
@transaction.atomic
|
||||
def receive_line_item(self, line, location, quantity, user, status=StockStatus.OK):
|
||||
def receive_line_item(self, line, location, quantity, user, status=StockStatus.OK, purchase_price=None):
|
||||
""" Receive a line item (or partial line item) against this PO
|
||||
"""
|
||||
|
||||
@ -353,13 +360,14 @@ class PurchaseOrder(Order):
|
||||
location=location,
|
||||
quantity=quantity,
|
||||
purchase_order=self,
|
||||
status=status
|
||||
status=status,
|
||||
purchase_price=purchase_price,
|
||||
)
|
||||
|
||||
stock.save()
|
||||
|
||||
text = _("Received items")
|
||||
note = f"{_('Received')} {quantity} {_('items against order')} {str(self)}"
|
||||
note = _('Received {n} items against order {name}').format(n=quantity, name=str(self))
|
||||
|
||||
# Add a new transaction note to the newly created stock item
|
||||
stock.addTransactionNote(text, user, note)
|
||||
|
@ -146,6 +146,8 @@ $('#view-calendar').click(function() {
|
||||
|
||||
$("#purchase-order-calendar").show();
|
||||
$("#view-list").show();
|
||||
|
||||
calendar.render();
|
||||
});
|
||||
|
||||
$("#view-list").click(function() {
|
||||
|
@ -141,9 +141,11 @@ $('#view-calendar').click(function() {
|
||||
$(".columns-right").hide();
|
||||
$(".search").hide();
|
||||
$('#filter-list-salesorder').hide();
|
||||
|
||||
|
||||
$("#sales-order-calendar").show();
|
||||
$("#view-list").show();
|
||||
|
||||
calendar.render();
|
||||
});
|
||||
|
||||
$("#view-list").click(function() {
|
||||
|
@ -1183,6 +1183,7 @@ class PurchaseOrderReceive(AjaxUpdateView):
|
||||
line.receive_quantity,
|
||||
self.request.user,
|
||||
status=line.status_code,
|
||||
purchase_price=line.purchase_price,
|
||||
)
|
||||
|
||||
|
||||
@ -1403,6 +1404,14 @@ class OrderParts(AjaxView):
|
||||
part.order_supplier = supplier_part.id if supplier_part else None
|
||||
part.order_quantity = quantity
|
||||
|
||||
# set supplier-price
|
||||
if supplier_part:
|
||||
supplier_price = supplier_part.get_price(quantity)
|
||||
if supplier_price:
|
||||
part.purchase_price = supplier_price / quantity
|
||||
if not hasattr(part, 'purchase_price'):
|
||||
part.purchase_price = None
|
||||
|
||||
self.parts.append(part)
|
||||
|
||||
if supplier_part is None:
|
||||
@ -1502,7 +1511,10 @@ class OrderParts(AjaxView):
|
||||
sp=item.order_supplier))
|
||||
continue
|
||||
|
||||
order.add_line_item(supplier_part, quantity)
|
||||
# get purchase price
|
||||
purchase_price = item.purchase_price
|
||||
|
||||
order.add_line_item(supplier_part, quantity, purchase_price=purchase_price)
|
||||
|
||||
|
||||
class POLineItemCreate(AjaxCreateView):
|
||||
@ -1802,7 +1814,7 @@ class SalesOrderAssignSerials(AjaxView, FormMixin):
|
||||
except StockItem.DoesNotExist:
|
||||
self.form.add_error(
|
||||
'serials',
|
||||
_('No matching item for serial') + f" '{serial}'"
|
||||
_('No matching item for serial {serial}').format(serial=serial)
|
||||
)
|
||||
continue
|
||||
|
||||
@ -1812,7 +1824,7 @@ class SalesOrderAssignSerials(AjaxView, FormMixin):
|
||||
if not stock_item.in_stock:
|
||||
self.form.add_error(
|
||||
'serials',
|
||||
f"'{serial}' " + _("is not in stock")
|
||||
_('{serial} is not in stock').format(serial=serial)
|
||||
)
|
||||
continue
|
||||
|
||||
@ -1820,7 +1832,7 @@ class SalesOrderAssignSerials(AjaxView, FormMixin):
|
||||
if stock_item.is_allocated():
|
||||
self.form.add_error(
|
||||
'serials',
|
||||
f"'{serial}' " + _("already allocated to an order")
|
||||
_('{serial} already allocated to an order').format(serial=serial)
|
||||
)
|
||||
continue
|
||||
|
||||
|
Reference in New Issue
Block a user