mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-30 22:46:49 +00:00
Render list of SupplierPart
This commit is contained in:
parent
5429c06349
commit
71ef6b3c5a
@ -1,9 +1,12 @@
|
|||||||
|
import 'package:inventree/api.dart';
|
||||||
|
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The InvenTreeCompany class repreents the Company model in the InvenTree database.
|
* The InvenTreeCompany class repreents the Company model in the InvenTree database.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class InvenTreeCompany extends InvenTreeModel {
|
class InvenTreeCompany extends InvenTreeModel {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -14,7 +17,9 @@ class InvenTreeCompany extends InvenTreeModel {
|
|||||||
|
|
||||||
InvenTreeCompany() : super();
|
InvenTreeCompany() : super();
|
||||||
|
|
||||||
String get image => jsondata['image'] ?? '';
|
String get image => jsondata['image'] ?? jsondata['thumbnail'] ?? InvenTreeAPI.staticImage;
|
||||||
|
|
||||||
|
String get thumbnail => jsondata['thumbnail'] ?? jsondata['image'] ?? InvenTreeAPI.staticThumb;
|
||||||
|
|
||||||
String get website => jsondata['website'] ?? '';
|
String get website => jsondata['website'] ?? '';
|
||||||
|
|
||||||
@ -44,14 +49,14 @@ class InvenTreeCompany extends InvenTreeModel {
|
|||||||
*/
|
*/
|
||||||
class InvenTreeSupplierPart extends InvenTreeModel {
|
class InvenTreeSupplierPart extends InvenTreeModel {
|
||||||
@override
|
@override
|
||||||
String url = "company/part/";
|
String URL = "company/part/";
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Map<String, String> defaultListFilters() {
|
Map<String, String> defaultListFilters() {
|
||||||
return {
|
return {
|
||||||
"manufacturer_detail": "true",
|
"manufacturer_detail": "true",
|
||||||
"supplier_detail": "true",
|
"supplier_detail": "true",
|
||||||
"supplier_part_detail": "true",
|
"manufacturer_part_detail": "true",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,12 +66,22 @@ class InvenTreeSupplierPart extends InvenTreeModel {
|
|||||||
|
|
||||||
int get manufacturerId => (jsondata['manufacturer'] ?? -1) as int;
|
int get manufacturerId => (jsondata['manufacturer'] ?? -1) as int;
|
||||||
|
|
||||||
|
String get manufacturerName => jsondata['manufacturer_detail']['name'];
|
||||||
|
|
||||||
|
String get manufacturerImage => jsondata['manufacturer_detail']['image'] ?? jsondata['manufacturer_detail']['thumbnail'];
|
||||||
|
|
||||||
int get manufacturerPartId => (jsondata['manufacturer_part'] ?? -1) as int;
|
int get manufacturerPartId => (jsondata['manufacturer_part'] ?? -1) as int;
|
||||||
|
|
||||||
int get supplierId => (jsondata['supplier'] ?? -1) as int;
|
int get supplierId => (jsondata['supplier'] ?? -1) as int;
|
||||||
|
|
||||||
|
String get supplierName => jsondata['supplier_detail']['name'];
|
||||||
|
|
||||||
|
String get supplierImage => jsondata['supplier_detail']['image'] ?? jsondata['supplier_detail']['thumbnail'];
|
||||||
|
|
||||||
String get SKU => (jsondata['SKU'] ?? '') as String;
|
String get SKU => (jsondata['SKU'] ?? '') as String;
|
||||||
|
|
||||||
|
String get MPN => jsondata['MPN'] ?? '';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
InvenTreeModel createFromJson(Map<String, dynamic> json) {
|
||||||
var part = InvenTreeSupplierPart.fromJson(json);
|
var part = InvenTreeSupplierPart.fromJson(json);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:inventree/api.dart';
|
import 'package:inventree/api.dart';
|
||||||
import 'package:inventree/inventree/stock.dart';
|
import 'package:inventree/inventree/stock.dart';
|
||||||
|
import 'package:inventree/inventree/company.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:inventree/l10.dart';
|
import 'package:inventree/l10.dart';
|
||||||
|
|
||||||
@ -174,13 +175,10 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
final parts = await InvenTreeSupplierPart().list(
|
final parts = await InvenTreeSupplierPart().list(
|
||||||
filters: {
|
filters: {
|
||||||
"part": "${pk}",
|
"part": "${pk}",
|
||||||
"manufacturer_detail": "true",
|
|
||||||
"supplier_detail": "true",
|
|
||||||
"supplier_part_detail": "true"
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
for (result in parts) {
|
for (var result in parts) {
|
||||||
if (result is InvenTreeSupplierPart) {
|
if (result is InvenTreeSupplierPart) {
|
||||||
_supplierParts.add(result);
|
_supplierParts.add(result);
|
||||||
}
|
}
|
||||||
@ -196,7 +194,7 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
int get testTemplateCount => testingTemplates.length;
|
int get testTemplateCount => testingTemplates.length;
|
||||||
|
|
||||||
// Request test templates from the serve
|
// Request test templates from the serve
|
||||||
Future<void> getTestTemplates({bool showDialog=false}) async {
|
Future<void> getTestTemplates() async {
|
||||||
|
|
||||||
InvenTreePartTestTemplate().list(
|
InvenTreePartTestTemplate().list(
|
||||||
filters: {
|
filters: {
|
||||||
|
@ -14,6 +14,7 @@ import 'package:inventree/widget/snacks.dart';
|
|||||||
import 'package:inventree/inventree/part.dart';
|
import 'package:inventree/inventree/part.dart';
|
||||||
import 'package:inventree/widget/full_screen_image.dart';
|
import 'package:inventree/widget/full_screen_image.dart';
|
||||||
import 'package:inventree/widget/category_display.dart';
|
import 'package:inventree/widget/category_display.dart';
|
||||||
|
import 'package:inventree/widget/part_suppliers.dart';
|
||||||
import 'package:inventree/widget/dialogs.dart';
|
import 'package:inventree/widget/dialogs.dart';
|
||||||
import 'package:inventree/widget/fields.dart';
|
import 'package:inventree/widget/fields.dart';
|
||||||
import 'package:inventree/api.dart';
|
import 'package:inventree/api.dart';
|
||||||
@ -328,10 +329,13 @@ class _PartDisplayState extends RefreshableState<PartDetailWidget> {
|
|||||||
tiles.add(
|
tiles.add(
|
||||||
ListTile(
|
ListTile(
|
||||||
title: Text(L10().suppliers),
|
title: Text(L10().suppliers),
|
||||||
leading: FaIcon(FontAwesomeIcons.industry),
|
leading: FaIcon(FontAwesomeIcons.industry, color: COLOR_CLICK),
|
||||||
trailing: Text("${part.supplierCount}"),
|
trailing: Text("${part.supplierCount}"),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// TODO
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (context) => PartSupplierWidget(part))
|
||||||
|
);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
75
lib/widget/part_suppliers.dart
Normal file
75
lib/widget/part_suppliers.dart
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
import 'package:inventree/l10.dart';
|
||||||
|
|
||||||
|
import 'package:inventree/api.dart';
|
||||||
|
|
||||||
|
import 'dart:core';
|
||||||
|
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:inventree/inventree/part.dart';
|
||||||
|
import 'package:inventree/inventree/company.dart';
|
||||||
|
import 'package:inventree/widget/refreshable_state.dart';
|
||||||
|
|
||||||
|
class PartSupplierWidget extends StatefulWidget {
|
||||||
|
|
||||||
|
PartSupplierWidget(this.part, {Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
final InvenTreePart part;
|
||||||
|
|
||||||
|
@override
|
||||||
|
_PartSupplierState createState() => _PartSupplierState(part);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class _PartSupplierState extends RefreshableState<PartSupplierWidget> {
|
||||||
|
|
||||||
|
_PartSupplierState(this.part);
|
||||||
|
|
||||||
|
final InvenTreePart part;
|
||||||
|
|
||||||
|
List<InvenTreeSupplierPart> _supplierParts = [];
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> request() async {
|
||||||
|
// TODO - Request list of suppliers for the part
|
||||||
|
await part.reload();
|
||||||
|
_supplierParts = await part.getSupplierParts();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String getAppBarTitle(BuildContext context) => L10().partSuppliers;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Widget> getAppBarActions(BuildContext contexts) {
|
||||||
|
// TODO
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _supplierPartTile(BuildContext context, int index) {
|
||||||
|
|
||||||
|
InvenTreeSupplierPart _part = _supplierParts[index];
|
||||||
|
|
||||||
|
return ListTile(
|
||||||
|
leading: InvenTreeAPI().getImage(
|
||||||
|
_part.supplierImage,
|
||||||
|
width: 40,
|
||||||
|
height: 40,
|
||||||
|
),
|
||||||
|
title: Text("${_part.SKU}"),
|
||||||
|
subtitle: Text("${_part.manufacturerName}: ${_part.MPN}")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget getBody(BuildContext context) {
|
||||||
|
return ListView.separated(
|
||||||
|
shrinkWrap: true,
|
||||||
|
physics: ClampingScrollPhysics(),
|
||||||
|
separatorBuilder: (_, __) => const Divider(height: 3),
|
||||||
|
itemCount: _supplierParts.length,
|
||||||
|
itemBuilder: _supplierPartTile,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user