createCalibreAndArticleRetailFromForm method
Future
createCalibreAndArticleRetailFromForm(
)
inherited
Implementation
Future<ArticleCalibre<ArticleRetail>>
createCalibreAndArticleRetailFromForm() async {
final now = DateTime.now();
ArticleRetail newArticle = ArticleRetail(
calibreId: _articlesStore.calibres.nextId,
id: 1,
fullName: name.trim(),
price: num.parse(price.trim()),
cost: 0,
weight: 1,
barcodeEAN: barcodeEAN.trim(),
articleCode: _articlesStore.calibres.nextId * 10 + 1,
creationDate: now,
updateDate: now,
statusUpdateDate: now,
status: true,
);
if (photoPath.isNotEmpty) {
final photo = ArticlePhoto(
calibreId: newArticle.calibreId,
id: newArticle.id,
path: photoPath,
source: PhotoSource.file);
await _articlesStore.upsertPhoto(photo);
}
if ((cost.isNotEmpty)) {
newArticle = newArticle.copyWith(cost: num.parse(cost.trim()));
}
if ((unitsPerPiece.isNotEmpty)) {
newArticle =
newArticle.copyWith(weight: double.parse(unitsPerPiece.trim()));
}
if (barcodeEAN.isNotEmpty && int.tryParse(barcodeEAN.trim()) != null) {
newArticle = newArticle.copyWith(barcodeEAN: barcodeEAN.trim());
}
final newLine = ArticleCalibre<ArticleRetail>(
id: _articlesStore.calibres.nextId,
title: name.trim(),
stockUnit: stockUnit,
categories: [''],
creationDate: now,
updateDate: now,
status: true,
statusUpdateDate: now,
articles: [newArticle]);
final articleLine =
await _articlesStore.createAndCalibrateArticle<ArticleRetail>(newLine);
return articleLine;
}