-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IPN uniqueness evaluation including revision #4618
Comments
Hi there @gunstr |
@gunstr I'm not fully sure that I'm following what you are asking for here Currently the "PART_ALLOW_DUPLICATE_IPN" setting just allows duplicate IPNs across part, the "description" of the part is not checked as part of this? |
@SchrodingersGat Sorry it was a typo from my side that made this confusing. It should be "name" - not "description"... Let me try to explain: For each new part the name has to be unique. If you add a revision multiple parts with the same name can be created. Correct? I use IPN's and as i need them to be unique I set PART_ALLOW_DUPLICATE_IPN to false which is fine for most parts. Some parts also have different revisions and thus I currenty have to assign a new IPN for each revision. So my question is if it would be possible to allow one IPN for multiple revisions also when PART_ALLOW_DUPLICATE_IPN is set to false in the same way as one name can have multiple revisions? More clear now? |
@matmair I found the section in the code that validates the IPN and it confirms that with PART_ALLOW_DUPLICATE_IPN set to false the same IPN cannot be used for different revisions. I was thinking a bit more on this but I have to admit I'm a bit on deep water here. If I set PART_ALLOW_DUPLICATE_IPN to true instead can I then create a plug-in that validates that the IPN+Revision is unique? You mentioned it's probably not possible. Is that because the validation mixin cannot be used to validate the uniqueness vs other parts so that would be a dead end? I looked at the validation plugin samples, and it seems to only act on the actual part and cannot reference other parts in the database. |
@gunstr we do not expose the revision of the current part to the validation function so you can not validate it. |
@matmair Thanks, then I understand why a plugin is not an option. |
@gunstr @matmair I would disagree here, I think that you certainly can have a custom validation routine for the IPN which operates exactly as you require. From the code (linked above): InvenTree/InvenTree/part/models.py Line 574 in 070e2af
And from the plugin code:
The "part" instance is passed to this function, so you have access to any attribute of the part. Writing a custom plugin here would be the correct approach IMO |
Thanks a lot @SchrodingersGat. I will give it a try to write a plugin in the coming days and let you know. |
@SchrodingersGat I have created a basic implementation for an IPN validation plugin and I can check various aspects on the IPN itself and also other attributes on the new part like that there is a revision assigned by accessing part.revision. But I cant figure out what mixin I need to add to the plugin to be able to query all existing parts in the database to validate that the IPN+revision on unique. I believe a test similar to what you do for the name in the core code should be done, but then only for IPN+revision InvenTree/InvenTree/part/models.py Lines 797 to 799 in 070e2af
Appreciate if you can guide me in the right directions. |
I don't think you need to add any other mixin? You should have direct access to make the same database calls as you provided in your example above? |
Oh, that I did not understand. I would assume I then at need some more import(s) on top of what you have in the IPN validation sample the be able to do a similar call as you do in the part/models code? I tried and it seems I cannot use the Part class right now, so I have obviously missed something...
|
I added With the quick testing I have done it seems to work like a charm. I can now set The validation method in all simplicity is only:
|
Glad you got it sorted with something simple :) if the plugin is public would you be willing for us to add it to the plugin samples page? |
Sure, I'm happy to share. I have the plugin on my local installation right now, will fix a git repo and let you know when it's done. |
Were you able to get this uploaded? We're in the same boat and would love to implement something that's already complete. 💯 |
It's a bad conscience of mine but give me a couple of days to fix it. I believe I had a bit too high ambition to clean it up and document but If you are OK with it I will just upload the code in all it's simplicity as a start. I have used it for a month now and it works perfectly fine :-) |
@gunstr looking forward to seeing what you've come up with :) |
Now the plugin is uploaded, you find it here. I have only installed the plugin locally as I have never done any PIP packaging. This could be a good case for me to learn but I thought it's better not to wait until I have done that. @walkermc20 appreciate if you can test and and let me know if it works for you also. @SchrodingersGat However, I tried to move it out from the As a little side note I found that the documentation refers to |
@gunstr cool plugin! |
I am working on installing this plugin with @walkermc20 . I have placed the Yet I am still getting an |
@andrewwetzel23 could be a few things:
|
Yes, I have restarted the server using: Unless there is something out of the box that would overwrite those values it shouldn't be. I haven't changed to much from the boiler plate docker install. Is there anything I need to change in the |
My installation is Bare Metal (on a VM), unfortunately I can't be of so much help on Docker. The only issue I had was that I could not move the plugin outsisde the InvenTree source code as I mentioned above. |
Thanks, I now have plugins enabled, but after a restart and with the EDIT: EDIT2: |
@andrewwetzel23 that was actually already developed but is not released at the moment. |
Ref: #4964 |
@SchrodingersGat I guess this issue can be considered as resolved now and can be closed? If you want to add a link to the plugin to the samples page please feel free to do so. |
@gunstr we can add it to the plugin repo if you want. |
Please verify that this feature request has NOT been suggested before.
Problem statement
Would it be possible to include the Revision in the IPN uniqueness evaluation in the same way as for part description?
In all tables I then see revision duplicated in both the IPN and Revision column, If I understand correctly the "last used serial number" would then also be evaluated for the base number and not restart for each revision.
Sorry it there is already a setting controlling this that I have not found.
Suggested solution
Include the Revision in the IPN uniqueness evaluation
Describe alternatives you've considered
Currently I need to include the revision in the IPN also.
Examples of other systems
No response
Do you want to develop this?
The text was updated successfully, but these errors were encountered: