Skip to content

Add "updated_at" field to Orders model#11374

Open
jmerro-c3d wants to merge 16 commits intoinventree:masterfrom
jmerro-c3d:po-updated-at-field
Open

Add "updated_at" field to Orders model#11374
jmerro-c3d wants to merge 16 commits intoinventree:masterfrom
jmerro-c3d:po-updated-at-field

Conversation

@jmerro-c3d
Copy link

This PR adds an extra field to the purchase order model to show when it or any of the line items were last updated.

Was writing a PO sync service between InvenTree and another software and wanted a way to check if a purchase order was modified since the last sync job.

@netlify
Copy link

netlify bot commented Feb 19, 2026

Deploy Preview for inventree-web-pui-preview ready!

Name Link
🔨 Latest commit 10072fd
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/699ee1fc3175cc00081df494
😎 Deploy Preview https://deploy-preview-11374--inventree-web-pui-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 94 (🟢 up 1 from production)
Accessibility: 81 (no change from production)
Best Practices: 100 (no change from production)
SEO: 78 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@SchrodingersGat
Copy link
Member

@jmerro-c3d I like this idea, notes below:

  • This should be added to the Order generic model, so that it applies to SalesOrder and ReturnOrder also
  • The signal hooks should then accommodate those orders too
  • API endpoints should be able to order the results by this field
  • The "purchase order" table (and other order tables) should display this in a column
  • That column(s) should be sortable
  • Also add API filters for before and after date ranges (see existing examples of this)
  • The purchase order detail page in the UI should display this date

@jmerro-c3d
Copy link
Author

@jmerro-c3d I like this idea, notes below:

  • This should be added to the Order generic model, so that it applies to SalesOrder and ReturnOrder also
  • The signal hooks should then accommodate those orders too
  • API endpoints should be able to order the results by this field
  • The "purchase order" table (and other order tables) should display this in a column
  • That column(s) should be sortable
  • Also add API filters for before and after date ranges (see existing examples of this)
  • The purchase order detail page in the UI should display this date

@SchrodingersGat Thanks, does this work for you? ... If you don't want to show the updated_at time in the details I can remove that.

Is there something else I need to do to generate the API schema or change tests?

@jmerro-c3d jmerro-c3d changed the title Add "updated_at" field to PurchaseOrder model Add "updated_at" field to Orders model Feb 20, 2026
@SchrodingersGat
Copy link
Member

Is there something else I need to do to generate the API schema or change tests?

API

Simply bump the API version in ./src/backend/InvenTree/InvenTree/api_version.py - according to the format already there

Tests

Add some unit tests to ensure that:

  • The updated_at field is correctly set when the order is saved
  • The updated_at field is correctly set when any line item is added / updated / deleted

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 21, 2026

Merging this PR will improve performance by 6.81%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 2 improved benchmarks
✅ 42 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_search_performance[purchaseorder] 25.8 ms 24.3 ms +6.02%
WallTime test_api_options_performance[/api/stock/location/] 25.4 ms 23.8 ms +6.81%

Comparing jmerro-c3d:po-updated-at-field (10072fd) with master (ac9a1f2)

Open in CodSpeed

@codecov
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

❌ Patch coverage is 99.00990% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.01%. Comparing base (edc639d) to head (91f50f7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11374      +/-   ##
==========================================
+ Coverage   87.99%   88.01%   +0.01%     
==========================================
  Files        1295     1296       +1     
  Lines       58806    58901      +95     
  Branches     1939     1939              
==========================================
+ Hits        51745    51839      +94     
- Misses       6579     6580       +1     
  Partials      482      482              
Flag Coverage Δ
backend 89.20% <99.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 91.71% <99.00%> (+0.01%) ⬆️
Backend General 93.37% <ø> (ø)
Frontend 70.85% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

)

updated_at = models.DateTimeField(
default=InvenTree.helpers.current_time,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to update every existing order to have an updated_at time which corresponds to the time of the database update to add this column?

Please check this - when you run invoke migrate - do the existing entries in the database get filled with a constant value, or null?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yep, will change them to be null by default. When ordering by "updated" DESC do you want the ones with null to be at the bottom or top of the list? By default they are at the top.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to control that?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me:

diff --git a/src/backend/InvenTree/InvenTree/filters.py b/src/backend/InvenTree/InvenTree/filters.py
index 78c5c5e45..d87395dd7 100644
--- a/src/backend/InvenTree/InvenTree/filters.py
+++ b/src/backend/InvenTree/InvenTree/filters.py
@@ -4,6 +4,7 @@ from datetime import datetime
 
 from django.conf import settings
 from django.core.exceptions import ValidationError
+from django.db.models import F
 from django.utils import timezone
 from django.utils.timezone import make_aware
 
@@ -114,9 +115,10 @@ class InvenTreeOrderingFilter(filters.OrderingFilter):
         ordering = super().get_ordering(request, queryset, view)
 
         aliases = getattr(view, 'ordering_field_aliases', None)
+        nulls_last = getattr(view, 'nulls_last_fields', set())
 
         # Attempt to map ordering fields based on provided aliases
-        if ordering is not None and aliases is not None:
+        if ordering is not None and (aliases is not None or nulls_last):
             """Ordering fields should be mapped to separate fields."""
 
             ordering_initial = ordering
@@ -129,7 +131,7 @@ class InvenTreeOrderingFilter(filters.OrderingFilter):
                     field = field[1:]
 
                 # Are aliases defined for this field?
-                alias = aliases.get(field, field)
+                alias = aliases.get(field, field) if aliases else field
 
                 """
                 Potentially, a single field could be "aliased" to multiple field,
@@ -153,10 +155,14 @@ class InvenTreeOrderingFilter(filters.OrderingFilter):
                     continue
 
                 for a in alias:
-                    if reverse:
-                        a = '-' + a
-
-                    ordering.append(a)
+                    if a in nulls_last:
+                        ordering.append(
+                            F(a).desc(nulls_last=True)
+                            if reverse
+                            else F(a).asc(nulls_last=True)
+                        )
+                    else:
+                        ordering.append(('-' + a) if reverse else a)
 
         return ordering
diff --git a/src/backend/InvenTree/order/api.py b/src/backend/InvenTree/order/api.py
index a7bdee756..a3723a4ef 100644
--- a/src/backend/InvenTree/order/api.py
+++ b/src/backend/InvenTree/order/api.py
@@ -431,6 +431,8 @@ class PurchaseOrderList(
         'updated_at',
     ]
 
+    nulls_last_fields = {'updated_at'}
+
     ordering = '-reference'
 
 
@@ -894,6 +896,8 @@ class SalesOrderList(
         'updated_at',
     ]
 
+    nulls_last_fields = {'updated_at'}
+
     search_fields = [
         'customer__name',
         'reference',
@@ -1562,6 +1566,8 @@ class ReturnOrderList(
         'updated_at',
     ]
 
+    nulls_last_fields = {'updated_at'}
+
     search_fields = [
         'customer__name',
         'reference',

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmerro-c3d interesting, I have been wondering how to control that for a while. It would be useful to submit that as a separate PR, but please keep it out of scope for this one.


INVENTREE_API_TEXT = """

<<<<<<< po-updated-at-field
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you've left some git cruft in here - please clean this up!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, weird... Resolved in Github editor and it... didn't resolve?? whatever, fixed now.

@SchrodingersGat
Copy link
Member

Sorry, API version has got out of date again

matmair and others added 6 commits February 25, 2026 11:45
…dates (inventree#11416)

Bumps the dependencies group with 4 updates in the / directory: [depot/setup-action](https://github.com/depot/setup-action), [depot/build-push-action](https://github.com/depot/build-push-action), [anchore/sbom-action](https://github.com/anchore/sbom-action) and [actions/stale](https://github.com/actions/stale).


Updates `depot/setup-action` from 1.6.0 to 1.7.1
- [Release notes](https://github.com/depot/setup-action/releases)
- [Commits](depot/setup-action@b0b1ea4...15c09a5)

Updates `depot/build-push-action` from 1.16.2 to 1.17.0
- [Release notes](https://github.com/depot/build-push-action/releases)
- [Commits](depot/build-push-action@9785b13...5f3b3c2)

Updates `anchore/sbom-action` from 0.21.1 to 0.22.2
- [Release notes](https://github.com/anchore/sbom-action/releases)
- [Changelog](https://github.com/anchore/sbom-action/blob/main/RELEASE.md)
- [Commits](anchore/sbom-action@0b82b0b...28d7154)

Updates `actions/stale` from 10.1.1 to 10.2.0
- [Release notes](https://github.com/actions/stale/releases)
- [Changelog](https://github.com/actions/stale/blob/main/CHANGELOG.md)
- [Commits](actions/stale@9971854...b5d41d4)

---
updated-dependencies:
- dependency-name: depot/setup-action
  dependency-version: 1.7.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dependencies
- dependency-name: depot/build-push-action
  dependency-version: 1.17.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dependencies
- dependency-name: anchore/sbom-action
  dependency-version: 0.22.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dependencies
- dependency-name: actions/stale
  dependency-version: 10.2.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: dependencies
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Prevent copy button if copy value is null

* Add "link" columns to order tables

* Support copy for default column types

* Tweak padding to avoid flickering issues

* Refactor IPNColumn

* Adjust visual styling

* Copy for SKU and MPN columns

* Add more copy columns

* More tweaks

* Tweak playwright testing

* Further cleanup

* More copy cols
…nventree#11411)

* Fix auto pricing overwriting manual purchase price inventree#10846

* Added entry to api_version.py

---------

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
* [UI] Support default server language

* Handle faulty theme

* Add option for default language

* Improve language selection

* Brief docs entry

* Fix typo

* Fix yarn build

* Remove debug msg

* Fix calendar locale
…ments (inventree#11372)

* [FR] ensure restore of backups only works in correct enviroments
Fixes inventree#11214

* update PR nbr

* fix wrong ty detection

* fix link

* ensure tracing does not enagage while running backup ops

* fix import

* remove debugging string

* add error codes

* add tests for backup and restore

* complete test for restore

* we do not need e2e on every matrix entry
there is no realy db dep here

* fix changelog format

* add flag to allow bypass
@jmerro-c3d
Copy link
Author

Sorry, API version has got out of date again

All good, fixed.

@jmerro-c3d
Copy link
Author

aw, playright tests job timed out downloading deb packages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants