Add clean() function for PurchaseOrderLineItem

Also adds renderer for purchaseorder model
This commit is contained in:
Oliver Walters 2022-01-26 22:56:00 +11:00
parent 34d8a4b4df
commit 681e007092
3 changed files with 56 additions and 9 deletions

View File

@ -822,14 +822,24 @@ class PurchaseOrderLineItem(OrderLineItem):
"""
@staticmethod
def get_api_url():
return reverse('api-po-line-list')
class Meta:
unique_together = (
('order', 'part', 'quantity', 'purchase_price')
)
@staticmethod
def get_api_url():
return reverse('api-po-line-list')
def clean(self):
if self.order.supplier and self.part:
# Supplier part *must* point to the same supplier!
if self.part.supplier != self.order.supplier:
raise ValidationError({
'part': _('Supplier part must match supplier')
})
def __str__(self):
return "{n} x {part} from {supplier} (for {po})".format(

View File

@ -1734,6 +1734,9 @@ function renderModelData(name, model, data, parameters, options) {
case 'partparametertemplate':
renderer = renderPartParameterTemplate;
break;
case 'purchaseorder':
renderer = renderPurchaseOrder;
break;
case 'salesorder':
renderer = renderSalesOrder;
break;

View File

@ -221,20 +221,54 @@ function renderOwner(name, data, parameters, options) {
}
// Renderer for "SalesOrder" model
// Renderer for "PurchaseOrder" model
// eslint-disable-next-line no-unused-vars
function renderSalesOrder(name, data, parameters, options) {
var html = `<span>${data.reference}</span>`;
function renderPurchaseOrder(name, data, parameters, options) {
var html = '';
var prefix = global_settings.PURCHASEORDER_REFERENCE_PREFIX;
var thumbnail = null;
html += `<span>${prefix}${data.reference}</span>`;
if (data.supplier_detail) {
thumbnail = data.supplier_detail.thumbnail || data.supplier_detail.image;
html += ' - ' + select2Thumbnail(thumbnail);
html += `<span>${data.supplier_detail.name}</span>`;
}
if (data.description) {
html += ` - <i>${data.description}</i>`;
html += ` - <em>${data.description}</em>`;
}
html += `
<span class='float-right'>
<small>
{% trans "Order ID" %}: ${data.pk}
</small>
</small>
</span>
`;
return html;
}
// Renderer for "SalesOrder" model
// eslint-disable-next-line no-unused-vars
function renderSalesOrder(name, data, parameters, options) {
var html = `<span>${data.reference}</span>`;
if (data.description) {
html += ` - <em>${data.description}</em>`;
}
html += `
<span class='float-right'>
<small>
{% trans "Order ID" %}: ${data.pk}
</small>
</span>`;
return html;