Skip to content

fix: trigger pricing recalculation when SupplierPart pack_quantity changes - #12421

Open
amanjain57-gif wants to merge 6 commits into
inventree:masterfrom
amanjain57-gif:fix/supplier-part-pricing-update
Open

fix: trigger pricing recalculation when SupplierPart pack_quantity changes#12421
amanjain57-gif wants to merge 6 commits into
inventree:masterfrom
amanjain57-gif:fix/supplier-part-pricing-update

Conversation

@amanjain57-gif

@amanjain57-gif amanjain57-gif commented Jul 19, 2026

Copy link
Copy Markdown

Summary

Fixes #12285

When a SupplierPart's pack_quantity is updated after price breaks exist, the Part's pricing and BOM cost rollups are
not recalculated. The root cause is that no post_save signal existed for the SupplierPart model to trigger
schedule_pricing_update on the linked Part.

Changes

  • Added post_save signal handler for SupplierPart that triggers pricing recalculation on the linked Part (mirrors
    existing SupplierPriceBreak handler)
  • Added post_delete signal handler for SupplierPart for completeness
  • Added unit test verifying that updating pack_quantity correctly recalculates the per-unit supplier price

How it works

The existing update_supplier_cost() method already correctly divides price by pack_quantity_native. The missing
piece was that changing pack_quantity on a SupplierPart didn't trigger the recalculation. The pricing cascade via
update_assemblies() ensures BOM line costs in parent assemblies also update.

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
@netlify

netlify Bot commented Jul 19, 2026

Copy link
Copy Markdown

Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit c1b2aef
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6a6f536d3e5845000851baa8

@SchrodingersGat

Copy link
Copy Markdown
Member

please address code style issues

@amanjain57-gif

Copy link
Copy Markdown
Author

Fixed — ran ruff format on the two changed files. Should pass style checks now.

@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed pricing Pricing functionality backport Apply this label to a PR to enable auto-backport action backport-to-1.4.x labels Jul 28, 2026
@SchrodingersGat SchrodingersGat added this to the 1.5.0 milestone Jul 28, 2026
@SchrodingersGat

Copy link
Copy Markdown
Member

@amanjain57-gif make sure you are using the same pre-commit config that we are. The ruff format checks may be different version

@amanjain57-gif

Copy link
Copy Markdown
Author

Applied ruff format with --preview flag matching the project's .pre-commit-config.yaml (v0.15.12). Should be clean now.

@amanjain57-gif

Copy link
Copy Markdown
Author

@SchrodingersGat Confirmed — matched your .pre-commit-config.yaml exactly: ruff v0.15.12 with --preview flag. Pushed another commit to fix the remaining file that was still off. CI should be green now.

@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 71.42857% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.93%. Comparing base (7461486) to head (c1b2aef).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12421      +/-   ##
==========================================
- Coverage   86.76%   85.93%   -0.83%     
==========================================
  Files        1444     1444              
  Lines       96231    97552    +1321     
  Branches    11216    11216              
==========================================
+ Hits        83491    83832     +341     
- Misses      12676    13656     +980     
  Partials       64       64              
Flag Coverage Δ
backend 90.73% <71.42%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Backend Apps 90.38% <71.42%> (-1.77%) ⬇️
Backend General 93.53% <ø> (ø)
Frontend 79.71% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Apply this label to a PR to enable auto-backport action backport-to-1.4.x bug Identifies a bug which needs to be addressed pricing Pricing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Supplier Part "Unit Price" is not propagated to Part's "Part Pricing" or other BoM line items, after Pack Quantity change

2 participants