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

Fix build item over-allocation checks #8235

Merged
merged 1 commit into from
Oct 6, 2024

Conversation

fuzeman
Copy link
Contributor

@fuzeman fuzeman commented Oct 3, 2024

This pull request fixes an issue with BuildItem over-allocation checks which prevent allocation changes to over-allocated items. Looking a bit closer at related code it appears SalesOrderAllocation already handled this correctly, and I've aligned these changes with that implementation.


Not sure if this is a concern but I noticed the quantity checks between BuildItem and SalesOrderAllocation don't appear to be aligned with one casting to decimal.Decimal and the other not. Not sure if this is breaking anything, but it doesn't look quite right to me.

# Allocated quantity cannot cause the stock item to be over-allocated
available = decimal.Decimal(self.stock_item.quantity)
allocated = decimal.Decimal(self.stock_item.allocation_count())
quantity = decimal.Decimal(self.quantity)
if available - allocated + quantity < quantity:
raise ValidationError({
'quantity': _('Stock item is over-allocated')
})

# Ensure that we do not 'over allocate' a stock item
build_allocation_count = self.item.build_allocation_count()
sales_allocation_count = self.item.sales_order_allocation_count(
exclude_allocations={'pk': self.pk}
)
total_allocation = (
build_allocation_count + sales_allocation_count + self.quantity
)
if total_allocation > self.item.quantity:
errors['quantity'] = _('Stock item is over-allocated')

Copy link

netlify bot commented Oct 3, 2024

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

Name Link
🔨 Latest commit c3b6369
🔍 Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/66fe7a650434c60008d93976

@fuzeman fuzeman force-pushed the over-allocation-checks branch from a5028d2 to c3b6369 Compare October 3, 2024 11:05
Copy link

codecov bot commented Oct 3, 2024

Codecov Report

Attention: Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.

Project coverage is 84.25%. Comparing base (f8c7635) to head (c3b6369).
Report is 312 commits behind head on master.

Files with missing lines Patch % Lines
src/backend/InvenTree/stock/models.py 85.71% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8235   +/-   ##
=======================================
  Coverage   84.24%   84.25%           
=======================================
  Files        1157     1157           
  Lines       52347    52373   +26     
  Branches     1892     1892           
=======================================
+ Hits        44100    44125   +25     
- Misses       7789     7790    +1     
  Partials      458      458           
Flag Coverage Δ
backend 86.01% <96.66%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed build Build orders backport Apply this label to a PR to enable auto-backport action backport-to-0.16.x labels Oct 6, 2024
@SchrodingersGat SchrodingersGat added this to the 0.17.0 milestone Oct 6, 2024
@SchrodingersGat
Copy link
Member

@fuzeman thanks for the fix, looks like a pretty subtle one to work out!

@SchrodingersGat SchrodingersGat merged commit a1024f1 into inventree:master Oct 6, 2024
30 checks passed
github-actions bot pushed a commit that referenced this pull request Oct 6, 2024
Copy link
Contributor

github-actions bot commented Oct 6, 2024

💚 All backports created successfully

Status Branch Result
0.16.x

Questions ?

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

SchrodingersGat pushed a commit that referenced this pull request Oct 6, 2024
(cherry picked from commit a1024f1)

Co-authored-by: Dean <me@dgardiner.net>
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 bug Identifies a bug which needs to be addressed build Build orders
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants