External order checks (#11935)

* Add new global settings

Co-authored-by: Copilot <copilot@github.com>

* Validation logic

Co-authored-by: Copilot <copilot@github.com>

* Remove one setting

- Already covered if build order requires validation

* Add unit test

Co-authored-by: Copilot <copilot@github.com>

---------

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Oliver
2026-05-13 15:16:34 +10:00
committed by GitHub
co-authored by Copilot
parent 5d72eb4f1d
commit 727ca62883
5 changed files with 91 additions and 16 deletions
+15 -1
View File
@@ -1955,13 +1955,16 @@ class PurchaseOrderLineItem(OrderLineItem):
if self.part.supplier != self.order.supplier:
raise ValidationError({'part': _('Supplier part must match supplier')})
# Link to the base part
part = self.part.part
if self.build_order:
if not self.build_order.external:
raise ValidationError({
'build_order': _('Build order must be marked as external')
})
if part := self.part.part:
if part:
if not part.assembly:
raise ValidationError({
'build_order': _(
@@ -1974,6 +1977,17 @@ class PurchaseOrderLineItem(OrderLineItem):
'build_order': _('Build order part must match line item part')
})
# Extra checks for external builds
if part and part.assembly and get_global_setting('BUILDORDER_EXTERNAL_BUILDS'):
if not self.build_order and get_global_setting(
'BUILDORDER_EXTERNAL_REQUIRED'
):
raise ValidationError({
'build_order': _(
'An external build order is required for assembly parts'
)
})
def __str__(self):
"""Render a string representation of a PurchaseOrderLineItem instance."""
return '{n} x {part} - {po}'.format(