Fix rendering of purchase_price for exporting StockItem data (#4434)

* Fix rendering of purchase_price for exporting StockItem data

* Stock item quantity is a decimal field

* Update other fields
This commit is contained in:
Oliver 2023-03-02 14:50:04 +11:00 committed by GitHub
parent db42ffcf7c
commit 7aee97d63b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,17 +97,18 @@ class StockItemResource(InvenTreeResource):
'owner', 'owner',
] ]
id = Field(attribute='pk', column_name=_('Stock Item ID')) id = Field(attribute='pk', column_name=_('Stock Item ID'), widget=widgets.IntegerWidget())
part = Field(attribute='part', column_name=_('Part ID'), widget=widgets.ForeignKeyWidget(Part)) part = Field(attribute='part', column_name=_('Part ID'), widget=widgets.ForeignKeyWidget(Part))
part_name = Field(attribute='part__full_name', column_name=_('Part Name'), readonly=True) part_name = Field(attribute='part__full_name', column_name=_('Part Name'), readonly=True)
quantity = Field(attribute='quantity', column_name=_('Quantity')) quantity = Field(attribute='quantity', column_name=_('Quantity'), widget=widgets.DecimalWidget())
serial = Field(attribute='serial', column_name=_('Serial')) serial = Field(attribute='serial', column_name=_('Serial'))
batch = Field(attribute='batch', column_name=_('Batch')) batch = Field(attribute='batch', column_name=_('Batch'))
status_label = Field(attribute='status_label', column_name=_('Status'), readonly=True) status_label = Field(attribute='status_label', column_name=_('Status'), readonly=True)
status = Field(attribute='status', column_name=_('Status Code'), widget=widgets.IntegerWidget())
location = Field(attribute='location', column_name=_('Location ID'), widget=widgets.ForeignKeyWidget(StockLocation)) location = Field(attribute='location', column_name=_('Location ID'), widget=widgets.ForeignKeyWidget(StockLocation))
location_name = Field(attribute='location__name', column_name=_('Location Name'), readonly=True) location_name = Field(attribute='location__name', column_name=_('Location Name'), readonly=True)
supplier_part = Field(attribute='supplier_part', column_name=_('Supplier Part ID'), widget=widgets.ForeignKeyWidget(SupplierPart)) supplier_part = Field(attribute='supplier_part', column_name=_('Supplier Part ID'), widget=widgets.ForeignKeyWidget(SupplierPart))
supplier = Field(attribute='supplier_part__supplier__id', column_name=_('Supplier ID'), readonly=True) supplier = Field(attribute='supplier_part__supplier__id', column_name=_('Supplier ID'), readonly=True, widget=widgets.IntegerWidget())
supplier_name = Field(attribute='supplier_part__supplier__name', column_name=_('Supplier Name'), readonly=True) supplier_name = Field(attribute='supplier_part__supplier__name', column_name=_('Supplier Name'), readonly=True)
customer = Field(attribute='customer', column_name=_('Customer ID'), widget=widgets.ForeignKeyWidget(Company)) customer = Field(attribute='customer', column_name=_('Customer ID'), widget=widgets.ForeignKeyWidget(Company))
belongs_to = Field(attribute='belongs_to', column_name=_('Installed In'), widget=widgets.ForeignKeyWidget(StockItem)) belongs_to = Field(attribute='belongs_to', column_name=_('Installed In'), widget=widgets.ForeignKeyWidget(StockItem))
@ -119,11 +120,22 @@ class StockItemResource(InvenTreeResource):
link = Field(attribute='link', column_name=_('Link')) link = Field(attribute='link', column_name=_('Link'))
notes = Field(attribute='notes', column_name=_('Notes')) notes = Field(attribute='notes', column_name=_('Notes'))
# Status fields (note that IntegerWidget exports better to excel than BooleanWidget)
is_building = Field(attribute='is_building', column_name=_('Building'), widget=widgets.IntegerWidget())
review_needed = Field(attribute='review_needed', column_name=_('Review Needed'), widget=widgets.IntegerWidget())
delete_on_deplete = Field(attribute='delete_on_deplete', column_name=_('Delete on Deplete'), widget=widgets.IntegerWidget())
# Date management # Date management
updated = Field(attribute='updated', column_name=_('Last Updated'), widget=widgets.DateWidget()) updated = Field(attribute='updated', column_name=_('Last Updated'), widget=widgets.DateWidget())
stocktake_date = Field(attribute='stocktake_date', column_name=_('Stocktake'), widget=widgets.DateWidget()) stocktake_date = Field(attribute='stocktake_date', column_name=_('Stocktake'), widget=widgets.DateWidget())
expiry_date = Field(attribute='expiry_date', column_name=_('Expiry Date'), widget=widgets.DateWidget()) expiry_date = Field(attribute='expiry_date', column_name=_('Expiry Date'), widget=widgets.DateWidget())
def dehydrate_purchase_price(self, item):
"""Render purchase pric as float"""
if item.purchase_price is not None:
return float(item.purchase_price.amount)
def after_import(self, dataset, result, using_transactions, dry_run, **kwargs): def after_import(self, dataset, result, using_transactions, dry_run, **kwargs):
"""Rebuild after import to keep tree intact.""" """Rebuild after import to keep tree intact."""
super().after_import(dataset, result, using_transactions, dry_run, **kwargs) super().after_import(dataset, result, using_transactions, dry_run, **kwargs)