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

Part pricing cache #3710

Merged
merged 99 commits into from
Nov 14, 2022
Merged

Conversation

SchrodingersGat
Copy link
Member

@SchrodingersGat SchrodingersGat commented Sep 23, 2022

This PR represents the first steps towards a major overhaul of pricing.

Currently, part pricing is too expensive to calculate "on the fly" and causes issues with viewing prices in a Bill of Materials, for example.

The major goal of this PR is to add a new database model which stores cached pricing information for a Part. This pricing information can be used in API requests for fast lookup against multiple parts.

Individual "quantity pricing" for a single part will still need to be calculated "on the fly" but for a single part should not be too expensive.

TODO

  • Overhaul part pricing tab
  • Validate page load times (currently takes ~14s to load "MAST Master Assembly" page with pricing turned on)
  • Fix template rendering issues which clip price values to 2 decimal places
  • Fix BOM export issues which clip price values to 2 decimal places
  • Implement functionality for "caching" min and max part pricing (inc. unit tests)
  • Add new pricing information to various API endpoints
  • Display pricing information in Part table
  • Display pricing information in BOM table
  • Add background tasks for updating various pricing data
  • Call background tasks when underlying data changes
  • Add data migration to perform initial part pricing calculations
  • Unit testing
  • Periodically check for any pricing information which is stored in the "wrong" currency
  • Periodically check for any parts which are missing pricing information
  • Schedule update when part is created / edited / deleted
  • Schedule update when BomItem is is created / edited / deleted
  • Schedule update when SupplierPriceBreak is is created / edited / deleted
  • Schedule update when InternalPrice is created / edited / deleted
  • Schedule update when PurchaseOrderLineItem is created / edited / deleted
  • Updated documentation - Documentation for new pricing structure inventree-docs#388
  • Remove or refactor has_complete_bom_pricing method
  • Prevent infinite loops for updates
  • Handle conversion issues when rates are missing (or other errors)
  • Include pricing summary information when exporting BOM table
  • Include pricing summary information when exporting part table
  • Respect "internal price overrides BOM price" if set

Future Work

  • Refactor 'quantity pricing' calculations
  • Refactor get_price_info method
  • Refactor get_bom_price_range method
  • Refactor get_price_range method

References

@SchrodingersGat SchrodingersGat added enhancement This is an suggested enhancement or new feature user interface api Relates to the API pricing Pricing functionality labels Sep 23, 2022
@SchrodingersGat SchrodingersGat added this to the 0.9.0 milestone Sep 23, 2022
@SchrodingersGat SchrodingersGat marked this pull request as draft September 23, 2022 03:09
Copy link
Member

@matmair matmair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems a bit verbose datastructure wise

InvenTree/part/models.py Show resolved Hide resolved
@SchrodingersGat
Copy link
Member Author

Seems a bit verbose datastructure wise

Which fields would you cull? How do you see the caching functionality working here?

@SchrodingersGat SchrodingersGat modified the milestones: 0.9.0, 0.10.0 Oct 20, 2022
Copy link
Member

@matmair matmair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SchrodingersGat looks good from my side.
Still wondering if code duplication could be reduced with the different types of pricing (esp. in API urls, forms)

@matmair
Copy link
Member

matmair commented Nov 13, 2022

Not really sure if it solves #3553 fully

@SchrodingersGat
Copy link
Member Author

Not really sure if it solves #3553 fully

@matmair it extends all pricing fields to use 6 decimal places, is this not fixing that?

@matmair
Copy link
Member

matmair commented Nov 13, 2022

@SchrodingersGat i think the idea was originally to make a toggle as we also had an FR to reduce the number of shown decimal places.

@SchrodingersGat SchrodingersGat merged commit 06266b4 into inventree:master Nov 14, 2022
@SchrodingersGat SchrodingersGat deleted the part-pricing-cache branch November 14, 2022 04:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment