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,15 +822,25 @@ class PurchaseOrderLineItem(OrderLineItem):
""" """
@staticmethod
def get_api_url():
return reverse('api-po-line-list')
class Meta: class Meta:
unique_together = ( unique_together = (
('order', 'part', 'quantity', 'purchase_price') ('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): def __str__(self):
return "{n} x {part} from {supplier} (for {po})".format( return "{n} x {part} from {supplier} (for {po})".format(
n=decimal2string(self.quantity), n=decimal2string(self.quantity),

View File

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

View File

@ -221,13 +221,47 @@ function renderOwner(name, data, parameters, options) {
} }
// Renderer for "PurchaseOrder" model
// eslint-disable-next-line no-unused-vars
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 += ` - <em>${data.description}</em>`;
}
html += `
<span class='float-right'>
<small>
{% trans "Order ID" %}: ${data.pk}
</small>
</span>
`;
return html;
}
// Renderer for "SalesOrder" model // Renderer for "SalesOrder" model
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
function renderSalesOrder(name, data, parameters, options) { function renderSalesOrder(name, data, parameters, options) {
var html = `<span>${data.reference}</span>`; var html = `<span>${data.reference}</span>`;
if (data.description) { if (data.description) {
html += ` - <i>${data.description}</i>`; html += ` - <em>${data.description}</em>`;
} }
html += ` html += `