Merge pull request #2573 from SchrodingersGat/bom-stock-export

Expand available stock information when exporting Bill of Materials
This commit is contained in:
Oliver 2022-01-27 14:47:41 +11:00 committed by GitHub
commit 09bba40c20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 3 deletions

View File

@ -123,16 +123,22 @@ def ExportBom(part, fmt='csv', cascade=False, max_levels=None, parameter_data=Fa
stock_headers = [
_('Default Location'),
_('Total Stock'),
_('Available Stock'),
_('On Order'),
]
stock_cols = {}
for b_idx, bom_item in enumerate(bom_items):
stock_data = []
sub_part = bom_item.sub_part
# Get part default location
try:
loc = bom_item.sub_part.get_default_location()
loc = sub_part.get_default_location()
if loc is not None:
stock_data.append(str(loc.name))
@ -141,8 +147,20 @@ def ExportBom(part, fmt='csv', cascade=False, max_levels=None, parameter_data=Fa
except AttributeError:
stock_data.append('')
# Get part current stock
stock_data.append(str(normalize(bom_item.sub_part.available_stock)))
# Total "in stock" quantity for this part
stock_data.append(
str(normalize(sub_part.total_stock))
)
# Total "available stock" quantity for this part
stock_data.append(
str(normalize(sub_part.available_stock))
)
# Total "on order" quantity for this part
stock_data.append(
str(normalize(sub_part.on_order))
)
for s_idx, header in enumerate(stock_headers):
try:

View File

@ -154,7 +154,9 @@ class BomExportTest(TestCase):
'inherited',
'allow_variants',
'Default Location',
'Total Stock',
'Available Stock',
'On Order',
]
for header in expected: