Allow "pending" or "issued" sales orders to be marked as completed (#4564)

* Allow "pending" or "issued" sales orders to be marked as completed

* Display pending shipments for open sales orders

* Add "is_open" method for PurchasesOrder

- Bring into line with SalesOrder and ReturnOrder
This commit is contained in:
Oliver 2023-04-03 19:20:00 +10:00 committed by GitHub
parent b0668b72b7
commit 3018087ea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 12 deletions

View File

@ -479,6 +479,11 @@ class PurchaseOrder(TotalPriceMixin, Order):
"""Return True if the PurchaseOrder is 'pending'"""
return self.status == PurchaseOrderStatus.PENDING
@property
def is_open(self):
"""Return True if the PurchaseOrder is 'open'"""
return self.status in PurchaseOrderStatus.OPEN
def can_cancel(self):
"""A PurchaseOrder can only be cancelled under the following circumstances.
@ -813,9 +818,9 @@ class SalesOrder(TotalPriceMixin, Order):
if self.lines.count() == 0:
raise ValidationError(_('Order cannot be completed as no parts have been assigned'))
# Only a PENDING order can be marked as SHIPPED
elif self.status != SalesOrderStatus.PENDING:
raise ValidationError(_('Only a pending order can be marked as complete'))
# Only an open order can be marked as shipped
elif not self.is_open:
raise ValidationError(_('Only an open order can be marked as complete'))
elif self.pending_shipment_count > 0:
raise ValidationError(_("Order cannot be completed as there are incomplete shipments"))

View File

@ -57,11 +57,11 @@
{% endif %}
</ul>
</div>
{% if order.status == PurchaseOrderStatus.PENDING %}
{% if order.is_pending %}
<button type='button' class='btn btn-primary' id='place-order' title='{% trans "Submit Order" %}'>
<span class='fas fa-paper-plane'></span> {% trans "Submit Order" %}
</button>
{% elif order.status == PurchaseOrderStatus.PLACED %}
{% elif order.is_open %}
<button type='button' class='btn btn-primary' id='receive-order' title='{% trans "Receive items" %}'>
<span class='fas fa-sign-in-alt'></span>
{% trans "Receive Items" %}

View File

@ -20,7 +20,7 @@
{% include "spacer.html" %}
<div class='btn-group' role='group'>
{% if roles.purchase_order.change %}
{% if order.is_pending or allow_extra_editing %}
{% if order.is_open or allow_extra_editing %}
<a class='btn btn-primary' href='{% url "po-upload" order.id %}' role='button'>
<span class='fas fa-file-upload side-icon'></span> {% trans "Upload File" %}
</a>
@ -40,7 +40,7 @@
<div class='panel-content'>
<div id='order-toolbar-buttons' class='btn-group' style='float: right;'>
{% if roles.purchase_order.change %}
{% if order.is_pending or allow_extra_editing %}
{% if order.is_open or allow_extra_editing %}
<div class='btn-group' role='group'>
<!-- Multiple-select actions -->
<button id='multi-select-options' class='btn btn-primary dropdown-toggle' data-bs-toggle='dropdown'>
@ -68,7 +68,7 @@
{% include "spacer.html" %}
<div class='btn-group' role='group'>
{% if roles.purchase_order.change %}
{% if order.is_pending or allow_extra_editing %}
{% if order.is_open or allow_extra_editing %}
<button type='button' class='btn btn-success' id='new-po-extra-line'>
<span class='fas fa-plus-circle'></span> {% trans "Add Extra Line" %}
</button>
@ -248,7 +248,7 @@ onPanelLoad('order-items', function() {
name: 'purchaseorderextraline',
filtertarget: '#filter-list-purchase-order-extra-lines',
{% settings_value "PURCHASEORDER_EDIT_COMPLETED_ORDERS" as allow_edit %}
{% if order.is_pending or allow_edit %}
{% if order.is_open or allow_edit %}
allow_edit: {% js_bool roles.purchase_order.change %},
allow_delete: {% js_bool roles.purchase_order.delete %},
{% else %}

View File

@ -64,7 +64,7 @@
</div>
</div>
{% if order.is_pending %}
{% if order.is_open %}
<div class='panel panel-hidden' id='panel-order-shipments'>
<div class='panel-heading'>
<div class='d-flex flex-row'>
@ -166,7 +166,7 @@
// Callback when the "shipments" panel is first loaded
onPanelLoad('order-shipments', function() {
{% if order.is_pending %}
{% if order.is_open %}
loadSalesOrderShipmentTable('#pending-shipments-table', {
order: {{ order.pk }},
shipped: false,

View File

@ -4,7 +4,7 @@
{% trans "Line Items" as text %}
{% include "sidebar_item.html" with label='order-items' text=text icon="fa-list-ol" %}
{% if order.is_pending %}
{% if order.is_open %}
{% trans "Pending Shipments" as text %}
{% include "sidebar_item.html" with label='order-shipments' text=text icon="fa-truck-loading" %}
{% endif %}