From d3d1d2f577be5ce5a6382d034d841cce863f7880 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 14 Oct 2021 18:00:17 +1100 Subject: [PATCH] Auto-rebuild the reference field for the SalesOrder on save --- InvenTree/order/migrations/0052_auto_20211014_0631.py | 2 -- InvenTree/order/models.py | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/InvenTree/order/migrations/0052_auto_20211014_0631.py b/InvenTree/order/migrations/0052_auto_20211014_0631.py index 93d3f86038..91ae28aadc 100644 --- a/InvenTree/order/migrations/0052_auto_20211014_0631.py +++ b/InvenTree/order/migrations/0052_auto_20211014_0631.py @@ -31,7 +31,6 @@ def build_refs(apps, schema_editor): order.save() print(f" - Updated {n} PurchaseOrder objects") - print("\n - Rebuilding reference field for SalesOrder model...") SalesOrder = apps.get_model('order', 'salesorder') @@ -54,7 +53,6 @@ def build_refs(apps, schema_editor): order.save() print(f" - Updated {n} SalesOrder objects") - print(f" - COMPLETE! -") diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 1b15e74663..0c45e3746a 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -534,6 +534,12 @@ class SalesOrder(Order): return queryset + def save(self, *args, **kwargs): + + self.rebuild_reference_field() + + super().save(*args, **kwargs) + def __str__(self): prefix = getSetting('SALESORDER_REFERENCE_PREFIX')