This commit is contained in:
Hillel Coren 2019-11-19 12:47:56 +02:00
parent 3a585d97bf
commit ff87752ec0
7 changed files with 31 additions and 18 deletions

View File

@ -58,7 +58,7 @@ abstract class ProductEntity extends Object
notes: '', notes: '',
cost: 0, cost: 0,
price: 0, price: 0,
quantity: 1, quantity: (state?.company?.defaultQuantity ?? true) ? 1 : 0,
taxName1: '', taxName1: '',
taxRate1: 0, taxRate1: 0,
taxName2: '', taxName2: '',

View File

@ -273,7 +273,9 @@ void handleExpenseAction(
break; break;
case EntityAction.newInvoice: case EntityAction.newInvoice:
final item = convertExpenseToInvoiceItem( final item = convertExpenseToInvoiceItem(
expense: expense, categoryMap: company.expenseCategoryMap); expense: expense,
categoryMap: company.expenseCategoryMap,
company: company);
createEntity( createEntity(
context: context, context: context,
entity: InvoiceEntity(state: state).rebuild((b) => b entity: InvoiceEntity(state: state).rebuild((b) => b

View File

@ -4,14 +4,17 @@ import 'package:built_collection/built_collection.dart';
import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/models/models.dart';
import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart'; import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart';
InvoiceItemEntity convertExpenseToInvoiceItem( InvoiceItemEntity convertExpenseToInvoiceItem({
{@required ExpenseEntity expense, @required ExpenseEntity expense,
@required BuiltMap<String, ExpenseCategoryEntity> categoryMap}) { @required BuiltMap<String, ExpenseCategoryEntity> categoryMap,
@required CompanyEntity company,
}) {
return InvoiceItemEntity().rebuild((b) => b return InvoiceItemEntity().rebuild((b) => b
..expenseId = expense.id ..expenseId = expense.id
..productKey = categoryMap[expense.categoryId]?.name ?? '' ..productKey = categoryMap[expense.categoryId]?.name ?? ''
..notes = expense.publicNotes ..notes = expense.publicNotes
..quantity = 1 ..quantity =
company.defaultQuantity || !company.enableProductQuantity ? 1 : null
..cost = expense.convertedAmount ..cost = expense.convertedAmount
..taxName1 = expense.taxName1 ..taxName1 = expense.taxName1
..taxRate1 = expense.taxRate1 ..taxRate1 = expense.taxRate1

View File

@ -223,7 +223,7 @@ void handleProductAction(
switch (action) { switch (action) {
case EntityAction.newInvoice: case EntityAction.newInvoice:
final item = final item =
convertProductToInvoiceItem(context: context, product: product); convertProductToInvoiceItem(company: state.company, product: product);
createEntity( createEntity(
context: context, context: context,
entity: InvoiceEntity(state: state) entity: InvoiceEntity(state: state)

View File

@ -4,13 +4,17 @@ import 'package:built_collection/built_collection.dart';
import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/models/models.dart';
import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart'; import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart';
InvoiceItemEntity convertProductToInvoiceItem( InvoiceItemEntity convertProductToInvoiceItem({
{BuildContext context, ProductEntity product}) { @required ProductEntity product,
@required CompanyEntity company,
}) {
return InvoiceItemEntity().rebuild((b) => b return InvoiceItemEntity().rebuild((b) => b
..productKey = product.productKey ..productKey = product.productKey
..notes = product.notes ..notes = product.notes
..cost = product.price ..cost = product.price
..quantity = product.quantity ..quantity = company.enableProductQuantity
? product.quantity
: company.defaultQuantity ? 1 : null
..customValue1 = product.customValue1 ..customValue1 = product.customValue1
..customValue2 = product.customValue2 ..customValue2 = product.customValue2
..taxName1 = product.taxName1 ..taxName1 = product.taxName1

View File

@ -86,7 +86,7 @@ class EntityHeader extends StatelessWidget {
child: Padding( child: Padding(
padding: EdgeInsets.all(16.0), padding: EdgeInsets.all(16.0),
child: Flex( child: Flex(
direction: value.length > 12 || secondValue.length > 12 direction: value.length > 12 || (secondValue ?? '').length > 12
? Axis.vertical ? Axis.vertical
: Axis.horizontal, : Axis.horizontal,
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,

View File

@ -52,8 +52,9 @@ class _InvoiceItemSelectorState extends State<InvoiceItemSelector>
super.dispose(); super.dispose();
} }
void _addBlankItem() { void _addBlankItem(CompanyEntity company) {
widget.onItemsSelected([InvoiceItemEntity(quantity: 1)]); widget.onItemsSelected(
[InvoiceItemEntity(quantity: company.defaultQuantity ? 1 : null)]);
Navigator.pop(context); Navigator.pop(context);
} }
@ -67,10 +68,11 @@ class _InvoiceItemSelectorState extends State<InvoiceItemSelector>
final product = entity as ProductEntity; final product = entity as ProductEntity;
if (state.company.fillProducts ?? true) { if (state.company.fillProducts ?? true) {
items.add( items.add(
convertProductToInvoiceItem(product: product, context: context)); convertProductToInvoiceItem(product: product, company: company));
} else { } else {
items.add( items.add(InvoiceItemEntity(
InvoiceItemEntity(productKey: product.productKey, quantity: 1)); productKey: product.productKey,
quantity: company.defaultQuantity ? 1 : null));
} }
} else if (entity.entityType == EntityType.task) { } else if (entity.entityType == EntityType.task) {
final task = entity as TaskEntity; final task = entity as TaskEntity;
@ -78,7 +80,9 @@ class _InvoiceItemSelectorState extends State<InvoiceItemSelector>
} else if (entity.entityType == EntityType.expense) { } else if (entity.entityType == EntityType.expense) {
final expense = entity as ExpenseEntity; final expense = entity as ExpenseEntity;
items.add(convertExpenseToInvoiceItem( items.add(convertExpenseToInvoiceItem(
expense: expense, categoryMap: company.expenseCategoryMap)); expense: expense,
categoryMap: company.expenseCategoryMap,
company: company));
} }
}); });
@ -172,7 +176,7 @@ class _InvoiceItemSelectorState extends State<InvoiceItemSelector>
: IconButton( : IconButton(
icon: Icon(Icons.add_circle_outline), icon: Icon(Icons.add_circle_outline),
tooltip: localization.createNew, tooltip: localization.createNew,
onPressed: () => _addBlankItem(), onPressed: () => _addBlankItem(company),
), ),
], ],
) )