Skip to content

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

Merged
SchrodingersGat merged 11 commits into
inventree:masterfrom
amanjain57-gif:fix/supplier-part-pricing-update
Aug 20, 2026
Merged

SchrodingersGat merged 11 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
Contributor

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 ready!

Name Link
🔨 Latest commit 60a2f96
🔍 Latest deploy log https://app.netlify.com/projects/inventree-web-pui-preview/deploys/6a7a80e3ddab080008ebaaf9
😎 Deploy Preview https://deploy-preview-12421--inventree-web-pui-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 98 (no change from production)
Accessibility: 81 (no change from production)
Best Practices: 100 (no change from production)
SEO: 78 (no change from production)
PWA: -
View the detailed breakdown and full score reports
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@SchrodingersGat

Copy link
Copy Markdown
Member

please address code style issues

@amanjain57-gif

Copy link
Copy Markdown
Contributor 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
Contributor 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
Contributor 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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.75%. Comparing base (11a48bf) to head (60a2f96).

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              
Flag Coverage Δ
backend 90.77% <100.00%> (-0.01%) ⬇️

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

Components Coverage Δ
Backend Apps 92.14% <100.00%> (-0.01%) ⬇️
Backend General 93.53% <ø> (-0.04%) ⬇️
Frontend 79.62% <ø> (+0.05%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@SchrodingersGat

Copy link
Copy Markdown
Member

@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.
@amanjain57-gif

Copy link
Copy Markdown
Contributor Author

@SchrodingersGat Fixed the CI failure. The erroring test (test_supplier_part_pack_quantity_update) was capturing self.part.pricing before any PartPricing row existed — that returns an unsaved instance, so the later refresh_from_db() raised PartPricing.DoesNotExist.

Now it re-fetches self.part.pricing after the price break creates the row (same pattern as test_supplier_part_pricing). Style/format are clean locally against your .pre-commit-config.yaml (ruff v0.15.12 --preview).

@SchrodingersGat

Copy link
Copy Markdown
Member

@amanjain57-gif thanks for the contribution

@SchrodingersGat
SchrodingersGat merged commit be9faff into inventree:master Aug 20, 2026
42 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
✅ 1.5.x

Questions ?

Please refer to the Backport tool documentation and see the Github Action logs for details

SchrodingersGat added a commit that referenced this pull request Aug 21, 2026
…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]>
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.5.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