Skip to content

Add "updated_at" field to Orders model - #11374

Merged
SchrodingersGat merged 19 commits into
inventree:masterfrom
jmerro-c3d:po-updated-at-field
Feb 27, 2026
Merged

SchrodingersGat merged 19 commits into
inventree:masterfrom
jmerro-c3d:po-updated-at-field

Conversation

@jmerro-c3d

Copy link
Copy Markdown
Contributor

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

netlify Bot commented Feb 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit cc3f520
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/69a18d8626ed6e0008d75cbd

@SchrodingersGat

Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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

codspeed Bot commented Feb 21, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 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.

✅ 44 untouched benchmarks


Comparing jmerro-c3d:po-updated-at-field (cc3f520) with master (fb3b118)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (cdd102f) during the generation of this report, so fb3b118 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Feb 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.00990% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 88.02%. Comparing base (fb3b118) to head (cc3f520).
⚠️ Report is 335 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11374      +/-   ##
==========================================
+ Coverage   88.01%   88.02%   +0.01%     
==========================================
  Files        1295     1296       +1     
  Lines       58908    59003      +95     
  Branches     1938     1938              
==========================================
+ Hits        51848    51939      +91     
- Misses       6578     6582       +4     
  Partials      482      482              
Flag Coverage Δ
backend 89.22% <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.81% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/backend/InvenTree/order/models.py Outdated
)

updated_at = models.DateTimeField(
default=InvenTree.helpers.current_time,

Copy link
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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] <[email protected]>
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 <[email protected]>
* [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
Copy Markdown
Contributor Author

Sorry, API version has got out of date again

All good, fixed.

@jmerro-c3d

Copy link
Copy Markdown
Contributor Author

aw, playright tests job timed out downloading deb packages

@jmerro-c3d

jmerro-c3d commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor Author

@SchrodingersGat WEB UI job passed the other day... playright tests seem to be flaky on other branches too.

edit:
Passed now.

@SchrodingersGat SchrodingersGat added this to the 1.3.0 milestone Feb 27, 2026
@SchrodingersGat SchrodingersGat added enhancement This is an suggested enhancement or new feature order Related to purchase orders / sales orders api Relates to the API feature User Interface Related to the frontend / User Interface labels Feb 27, 2026
@SchrodingersGat

Copy link
Copy Markdown
Member

@jmerro-c3d nice work on this! The only other change I would request at this stage is that you add a brief entry to CHANGELOG.md

@jmerro-c3d

Copy link
Copy Markdown
Contributor Author

@jmerro-c3d nice work on this! The only other change I would request at this stage is that you add a brief entry to CHANGELOG.md

Done!

@SchrodingersGat
SchrodingersGat merged commit 3d9104e into inventree:master Feb 27, 2026
35 of 36 checks passed
@SchrodingersGat

Copy link
Copy Markdown
Member

@jmerro-c3d thanks for the contribution!

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

Labels

api Relates to the API enhancement This is an suggested enhancement or new feature feature order Related to purchase orders / sales orders User Interface Related to the frontend / User Interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants