Repository navigation
fix: trigger pricing recalculation when SupplierPart pack_quantity changes - #12421
SchrodingersGat merged 11 commits into
Conversation
When a SupplierPart's pack_quantity is updated after price breaks have already been created, the Part's pricing (and BOM cost rollups for any assemblies using that part) was not recalculated. This is because there was no post_save or post_delete signal handler for the SupplierPart model to trigger schedule_pricing_update on the linked Part. Added post_save and post_delete signal handlers for SupplierPart that mirror the existing SupplierPriceBreak signal handlers. The pricing cascade (via update_assemblies) ensures BOM line costs in parent assemblies are also updated. Fixes inventree#12285
✅ Deploy Preview for inventree-web-pui-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
please address code style issues |
|
Fixed — ran |
|
@amanjain57-gif make sure you are using the same pre-commit config that we are. The ruff format checks may be different version |
|
Applied ruff format with |
|
@SchrodingersGat Confirmed — matched your |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #12421 +/- ##
==========================================
+ Coverage 86.72% 86.75% +0.02%
==========================================
Files 1447 1447
Lines 96780 96724 -56
Branches 11180 11221 +41
==========================================
- Hits 83932 83909 -23
+ Misses 12784 12751 -33
Partials 64 64
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
@amanjain57-gif thanks - still some CI issues to address though |
The test captured self.part.pricing before any PartPricing row existed, yielding an unsaved instance; the later refresh_from_db() then raised DoesNotExist. Re-fetch self.part.pricing after the price break creates the row, matching the pattern in test_supplier_part_pricing.
|
@SchrodingersGat Fixed the CI failure. The erroring test ( Now it re-fetches |
|
@amanjain57-gif thanks for the contribution |
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation and see the Github Action logs for details |
…anges (#12421) (#12674) * fix: trigger pricing recalculation when SupplierPart is saved or deleted When a SupplierPart's pack_quantity is updated after price breaks have already been created, the Part's pricing (and BOM cost rollups for any assemblies using that part) was not recalculated. This is because there was no post_save or post_delete signal handler for the SupplierPart model to trigger schedule_pricing_update on the linked Part. Added post_save and post_delete signal handlers for SupplierPart that mirror the existing SupplierPriceBreak signal handlers. The pricing cascade (via update_assemblies) ensures BOM line costs in parent assemblies are also updated. Fixes #12285 * style: fix ruff format issues * style: apply ruff format with --preview flag (matching project config) * fix: resolve PartPricing.DoesNotExist in pack_quantity test The test captured self.part.pricing before any PartPricing row existed, yielding an unsaved instance; the later refresh_from_db() then raised DoesNotExist. Re-fetch self.part.pricing after the price break creates the row, matching the pattern in test_supplier_part_pricing. --------- (cherry picked from commit be9faff) Co-authored-by: amanjain57-gif <[email protected]> Co-authored-by: Oliver <[email protected]> Co-authored-by: Aman Jain <[email protected]>

Summary
Fixes #12285
When a SupplierPart's
pack_quantityis updated after price breaks exist, the Part's pricing and BOM cost rollups arenot recalculated. The root cause is that no
post_savesignal existed for theSupplierPartmodel to triggerschedule_pricing_updateon the linked Part.Changes
post_savesignal handler forSupplierPartthat triggers pricing recalculation on the linked Part (mirrorsexisting
SupplierPriceBreakhandler)post_deletesignal handler forSupplierPartfor completenesspack_quantitycorrectly recalculates the per-unit supplier priceHow it works
The existing
update_supplier_cost()method already correctly divides price bypack_quantity_native. The missingpiece was that changing
pack_quantityon aSupplierPartdidn't trigger the recalculation. The pricing cascade viaupdate_assemblies()ensures BOM line costs in parent assemblies also update.