Skip to content
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

[BUG] Saving an Item template deletes important info from its variants #17664

Open
Don-Leopardo opened this issue May 17, 2019 · 2 comments

Comments

@Don-Leopardo
Copy link
Contributor

@Don-Leopardo Don-Leopardo commented May 17, 2019

Issue:

The reorder_levels Item's child table disappears with no apparent reason.

Tracked down bug:

By searching in the tabVersion table of the db, I detected that the child table had been in all the items at the same time, and the common denominator of all that "random" items was the Item Template. So I searched for a change made in the Item Template at that same time, and there it was, the item_defaults child table was modified.
I tryed changing that table to recreate the issue, and it happened. I decided to take it a step further and save the document without changing anything, it deleted the reorder_levels child table too.
In conclusion: When you save an Item Template, all its variants are updated and their reorder_levels records are deleted.

How to fix it:

The way to fix it is to add "reorder_levels" to the exclude_fields list in the next line:

def copy_attributes_to_variant(item, variant):
# copy non no-copy fields
exclude_fields = ["naming_series", "item_code", "item_name", "show_in_website",
"show_variant_in_website", "opening_stock", "variant_of", "valuation_rate"]

I could do it, but a lot of my Pull Requests are open and unattended, so I let this here and you can make your own Pull Request.

@Don-Leopardo

This comment has been minimized.

Copy link
Contributor Author

@Don-Leopardo Don-Leopardo commented May 23, 2019

Well, the bug is a little bit more complex than I thougth in first place. The solution mentioned in the OP can be a viable solution, but this should be discussed.
The existing functionality is to copy the reorder_level child table from the template to the variants. The problem is that the possibility for a variant to have its own reorder_level does not exists, and it's a real case.

The possibilities:

  • Force the user to change the reorder_level of every variant every time that the template is modified (existing functionality)
  • Force the user to edit the reorder_level of every variant after insertion (OP's solution)
  • Check the modified fields of the template and copy only those fields to the variants every time that it is updated (this still forces the user to modify the variants when the reorder_level of the template is modified)
  • Make a button in the template to "replicate changes to variants" (this will forces the user to modify the variants when the reorder_level of the template is modified, but it's less intrusive)
  • Use the field warehouse of the reorder_level child table as a "primary key" and only copy the ones that are not already in the variant (this will not modify the existing ones when you change them in the template)
  • A checkbox in the variants for when the user don't want to copy the reorder_level child table of the template (this solution seems to be very specific but can be the more versatile)

Example case:

There is a variant that has a bigger demand than the rest of them and the user wants to assign to it a different reorder level.
Note: This is just one example, there are a lot of them.

I need opinions, I could make the PR.

@agritheory

This comment has been minimized.

Copy link
Contributor

@agritheory agritheory commented May 28, 2019

Rather than change the default behavior via PR, consider exposing settings (per-child-table? maybe even finer than that?) about what is updated in the Item Variant Settings.

From a UI perspective, it might make sense to have a tool where one can view and edit all the reorder points with a combination of sort methods or hierarchies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.