mirror of
https://github.com/inventree/inventree-app.git
synced 2025-06-17 20:55:26 +00:00
Part pricing detail (#655)
* Implement part pricing data and new part pricing widget * improve part pricing widget and part pricing data. Add part pricing setting. * Refactor helper func * Tweak translated string * Refactor part pricing page * Update release notes * Fixes * More cleanup --------- Co-authored-by: JarEXE <eykenj@gmail.com>
This commit is contained in:
@ -18,6 +18,7 @@ import "package:inventree/widget/part/bom_list.dart";
|
||||
import "package:inventree/widget/part/part_list.dart";
|
||||
import "package:inventree/widget/notes_widget.dart";
|
||||
import "package:inventree/widget/part/part_parameter_widget.dart";
|
||||
import "package:inventree/widget/part/part_pricing.dart";
|
||||
import "package:inventree/widget/progress.dart";
|
||||
import "package:inventree/widget/part/category_display.dart";
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
@ -52,14 +53,18 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
|
||||
int parameterCount = 0;
|
||||
|
||||
bool allowLabelPrinting = false;
|
||||
bool showParameters = false;
|
||||
bool showBom = false;
|
||||
bool showPricing = false;
|
||||
|
||||
int attachmentCount = 0;
|
||||
int bomCount = 0;
|
||||
int usedInCount = 0;
|
||||
int variantCount = 0;
|
||||
|
||||
InvenTreePartPricing? partPricing;
|
||||
|
||||
List<Map<String, dynamic>> labels = [];
|
||||
|
||||
@override
|
||||
@ -151,6 +156,12 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
|
||||
final bool result = await part.reload();
|
||||
|
||||
// Load page settings from local storage
|
||||
showPricing = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_PRICING, true);
|
||||
showParameters = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_PARAMETERS, true);
|
||||
showBom = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_BOM, true);
|
||||
allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
||||
|
||||
if (!result || part.pk == -1) {
|
||||
// Part could not be loaded, for some reason
|
||||
Navigator.of(context).pop();
|
||||
@ -179,9 +190,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
}
|
||||
});
|
||||
|
||||
// Request the number of parameters for this part
|
||||
showParameters = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_PARAMETERS, true);
|
||||
|
||||
// Request the number of attachments
|
||||
InvenTreePartAttachment().countAttachments(part.pk).then((int value) {
|
||||
if (mounted) {
|
||||
@ -191,7 +199,16 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
}
|
||||
});
|
||||
|
||||
showBom = await InvenTreeSettingsManager().getBool(INV_PART_SHOW_BOM, true);
|
||||
// If show pricing information?
|
||||
if (showPricing) {
|
||||
part.getPricing().then((InvenTreePartPricing? pricing) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
partPricing = pricing;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Request the number of BOM items
|
||||
InvenTreePart().count(
|
||||
@ -233,7 +250,6 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
});
|
||||
|
||||
List<Map<String, dynamic>> _labels = [];
|
||||
bool allowLabelPrinting = await InvenTreeSettingsManager().getBool(INV_ENABLE_LABEL_PRINTING, true);
|
||||
allowLabelPrinting &= api.supportsMixin("labels");
|
||||
|
||||
if (allowLabelPrinting) {
|
||||
@ -271,8 +287,8 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
Widget headerTile() {
|
||||
return Card(
|
||||
child: ListTile(
|
||||
title: Text("${part.fullname}"),
|
||||
subtitle: Text("${part.description}"),
|
||||
title: Text(part.fullname),
|
||||
subtitle: Text(part.description),
|
||||
trailing: Text(
|
||||
part.stockString(),
|
||||
style: TextStyle(
|
||||
@ -425,6 +441,36 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
||||
),
|
||||
);
|
||||
|
||||
if (showPricing && partPricing != null) {
|
||||
|
||||
String pricing = formatPriceRange(
|
||||
partPricing?.overallMin,
|
||||
partPricing?.overallMax,
|
||||
currency: partPricing?.currency
|
||||
);
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().partPricing),
|
||||
leading: Icon(TablerIcons.currency_dollar, color: COLOR_ACTION),
|
||||
trailing: Text(
|
||||
pricing.isNotEmpty ? pricing : L10().noPricingAvailable,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => PartPricingWidget(part: part, partPricing: partPricing),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Tiles for "purchaseable" parts
|
||||
if (part.isPurchaseable) {
|
||||
|
||||
|
198
lib/widget/part/part_pricing.dart
Normal file
198
lib/widget/part/part_pricing.dart
Normal file
@ -0,0 +1,198 @@
|
||||
import "package:flutter/material.dart";
|
||||
|
||||
import "package:inventree/inventree/part.dart";
|
||||
import "package:inventree/l10.dart";
|
||||
|
||||
import "package:inventree/widget/refreshable_state.dart";
|
||||
import "package:inventree/helpers.dart";
|
||||
|
||||
class PartPricingWidget extends StatefulWidget {
|
||||
|
||||
const PartPricingWidget({Key? key, required this.part, required this.partPricing}) : super(key: key);
|
||||
final InvenTreePart part;
|
||||
final InvenTreePartPricing? partPricing;
|
||||
|
||||
@override
|
||||
_PartPricingWidgetState createState() => _PartPricingWidgetState();
|
||||
}
|
||||
|
||||
class _PartPricingWidgetState extends RefreshableState<PartPricingWidget> {
|
||||
|
||||
@override
|
||||
String getAppBarTitle() {
|
||||
return L10().partPricing;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Widget> getTiles(BuildContext context) {
|
||||
|
||||
List<Widget> tiles = [
|
||||
Card(
|
||||
child: ListTile(
|
||||
title: Text(widget.part.fullname),
|
||||
subtitle: Text(widget.part.description),
|
||||
leading: api.getThumbnail(widget.part.thumbnail)
|
||||
)
|
||||
),
|
||||
];
|
||||
|
||||
if (widget.partPricing == null) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().noPricingAvailable),
|
||||
subtitle: Text(L10().noPricingDataFound),
|
||||
)
|
||||
);
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
final pricing = widget.partPricing!;
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().currency),
|
||||
trailing: Text(pricing.currency),
|
||||
)
|
||||
);
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().priceRange),
|
||||
trailing: Text(
|
||||
formatPriceRange(
|
||||
pricing.overallMin,
|
||||
pricing.overallMax,
|
||||
currency: pricing.currency
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if (pricing.overallMin != null) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().priceOverrideMin),
|
||||
trailing: Text(
|
||||
renderCurrency(pricing.overallMin, pricing.overrideMinCurrency)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (pricing.overrideMax != null) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().priceOverrideMax),
|
||||
trailing: Text(
|
||||
renderCurrency(pricing.overallMax, pricing.overrideMaxCurrency)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().internalCost),
|
||||
trailing: Text(
|
||||
formatPriceRange(
|
||||
pricing.internalCostMin,
|
||||
pricing.internalCostMax,
|
||||
currency: pricing.currency
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
if (widget.part.isTemplate) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().variantCost),
|
||||
trailing: Text(
|
||||
formatPriceRange(
|
||||
pricing.variantCostMin,
|
||||
pricing.variantCostMax,
|
||||
currency: pricing.currency
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.part.isAssembly) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().bomCost),
|
||||
trailing: Text(
|
||||
formatPriceRange(
|
||||
pricing.bomCostMin,
|
||||
pricing.bomCostMax,
|
||||
currency: pricing.currency
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.part.isPurchaseable) {
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().purchasePrice),
|
||||
trailing: Text(
|
||||
formatPriceRange(
|
||||
pricing.purchaseCostMin,
|
||||
pricing.purchaseCostMax,
|
||||
currency: pricing.currency
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().supplierPricing),
|
||||
trailing: Text(
|
||||
formatPriceRange(
|
||||
pricing.supplierPriceMin,
|
||||
pricing.supplierPriceMax,
|
||||
currency: pricing.currency
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.part.isSalable) {
|
||||
tiles.add(Divider());
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().salePrice),
|
||||
trailing: Text(
|
||||
formatPriceRange(
|
||||
pricing.salePriceMin,
|
||||
pricing.salePriceMax,
|
||||
currency: pricing.currency
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
tiles.add(
|
||||
ListTile(
|
||||
title: Text(L10().saleHistory),
|
||||
trailing: Text(
|
||||
formatPriceRange(
|
||||
pricing.saleHistoryMin,
|
||||
pricing.saleHistoryMax,
|
||||
currency: pricing.currency
|
||||
)
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user