plugin-validation-purchase-orders#12094
Merged
Merged
Conversation
✅ Deploy Preview for inventree-web-pui-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12094 +/- ##
=======================================
Coverage 91.47% 91.47%
=======================================
Files 979 979
Lines 52331 52336 +5
=======================================
+ Hits 47870 47875 +5
Misses 4461 4461
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Member
|
@SchrodingersGat looks good to me |
Member
|
@NerosKi thanks for the contribution |
Contributor
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation and see the Github Action logs for details |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #12076
Problem
Custom validation plugins implementing the
validate_batch_codehook are enforcedwhen stock is created directly, but not when receiving stock against a Purchase
Order. Invalid/empty batch codes (and any other plugin validation) silently pass on
the PO receipt path.
Cause
Plugin validation hooks only fire through the model lifecycle:
validate_batch_codeviaStockItem.clean()validate_model_instanceviaStockItem.save()/full_clean()(
PluginValidationMixin.run_plugin_validation())PurchaseOrder.receive_line_items()creates stock viaStockItem.objects.bulk_create()and
StockItem._create_serial_numbers(), both of which bypasssave()/clean(), sothe hooks are never reached. (Serial-number validation already worked because it is
called explicitly in the receive serializer.)
Fix
Invoke the existing plugin validation hooks explicitly in
receive_line_items()— novalidation logic is added to core, the hooks the bulk path skips are simply called:
item.validate_batch_code()→plugin.validate_batch_codeitem.run_plugin_validation()→plugin.validate_model_instanceBoth creation branches are covered:
bulk_create()._create_serial_numbers().receive_line_items()is wrapped in@transaction.atomic, so aValidationErrorraised by any plugin rolls back all inserts — no partial/invalid stock is committed.
Testing
Manual testing has been performed by using a plugin that checks for the existence of various elements such as batch code, unit price, qr code etc. Tested adding stock the default way and via receiving stock in purchase orders. Tested nothing strange happens if no plugin is added. All seems ok.