Skip to content

Commit

Permalink
Merge pull request #95 from afkiwers/stock_data_enhancement
Browse files Browse the repository at this point in the history
Stock data display enhancement
  • Loading branch information
afkiwers authored May 2, 2024
2 parents 5ed15d2 + c69a1a8 commit 89086ad
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions inventree_kicad/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ class Meta:
'id',
'name',
'description',
'stock',
]

def __init__(self, *args, **kwargs):
Expand All @@ -418,7 +419,25 @@ def __init__(self, *args, **kwargs):
id = serializers.CharField(source='pk', read_only=True)

description = serializers.SerializerMethodField('get_description')
stock = serializers.SerializerMethodField('get_stock')

def get_stock(self, part):
"""Custom name function.
This will extract stock information and add it to a separate key variable which
can be displayed inside the symbol picker
"""

# In-stock quantity should be annotated to the queryset
stock_count = getattr(part, 'in_stock', 0)

try:
stock_count = decimal2string(stock_count)
except Exception as e:
logger.exception("Failed to format stock count: %s", e)

return stock_count

def get_description(self, part):
"""Custom name function.
Expand Down
2 changes: 1 addition & 1 deletion inventree_kicad/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
KICAD_PLUGIN_VERSION = "1.4.0"
KICAD_PLUGIN_VERSION = "1.4.1"

0 comments on commit 89086ad

Please sign in to comment.