Add "updated_at" field to Orders model#11374
Add "updated_at" field to Orders model#11374jmerro-c3d wants to merge 16 commits intoinventree:masterfrom
Conversation
✅ Deploy Preview for inventree-web-pui-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@jmerro-c3d I like this idea, notes below:
|
@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? |
f0c379e to
2ed3ea4
Compare
APISimply bump the API version in TestsAdd some unit tests to ensure that:
|
Merging this PR will improve performance by 6.81%
|
| 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)
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
2ed3ea4 to
811881e
Compare
| ) | ||
|
|
||
| updated_at = models.DateTimeField( | ||
| default=InvenTree.helpers.current_time, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Is there a way to control that?
There was a problem hiding this comment.
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 orderingdiff --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',There was a problem hiding this comment.
@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 |
There was a problem hiding this comment.
Looks like you've left some git cruft in here - please clean this up!
There was a problem hiding this comment.
Oh, weird... Resolved in Github editor and it... didn't resolve?? whatever, fixed now.
|
Sorry, API version has got out of date again |
…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
All good, fixed. |
|
aw, playright tests job timed out downloading deb packages |

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.