Skip to content

Commit 2b2211e

Browse files
committed
Assume fractional unit is 0 when no conversion is possible of encoded unit & use scanned code when selecting bundle product
1 parent bf8878d commit 2b2211e

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.14.6]
5+
6+
### Fixed
7+
- Assume fractional unit is 0 when no conversion is possible of encoded unit
8+
- Use scanned code when selecting bundle product
9+
410
## [0.14.5]
511

612
### Changes

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ allprojects {
2323
}
2424

2525
project.ext {
26-
sdkVersion='0.14.5'
26+
sdkVersion='0.14.6'
2727
versionCode=1
2828

2929
compileSdkVersion=28

ui/src/main/java/io/snabble/sdk/ui/scanner/ProductResolver.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,23 @@ private void handleProductAvailable(Product product, boolean wasOnlineProduct, S
185185
} else {
186186
int scale = decimal.scale();
187187
Unit fractionalUnit = unit.getFractionalUnit(scale);
188-
if (fractionalUnit != null) {
189-
BigDecimal converted = Unit.convert(decimal, unit, fractionalUnit);
190-
scannedCode.setEmbeddedData(converted.intValue());
191-
scannedCode.setEmbeddedUnit(fractionalUnit);
188+
if (fractionalUnit == null) {
189+
fractionalUnit = unit;
190+
191+
if (scale > 0) {
192+
decimal = decimal.multiply(new BigDecimal(Math.pow(10, scale)));
193+
}
192194
}
195+
196+
BigDecimal converted = Unit.convert(decimal, unit, fractionalUnit);
197+
scannedCode.setEmbeddedData(converted.intValue());
198+
scannedCode.setEmbeddedUnit(fractionalUnit);
193199
}
194200
}
195201
}
196202

197203
if(product.getBundleProducts().length > 0){
198-
showBundleDialog(product);
204+
showBundleDialog(product, scannedCode);
199205
} else {
200206
if (product.getSaleStop()) {
201207
if (onSaleStopListener != null) {
@@ -230,18 +236,15 @@ private void handleProductAvailable(Product product, boolean wasOnlineProduct, S
230236
}
231237
}
232238

233-
private void showBundleDialog(Product product) {
239+
private void showBundleDialog(Product product, final ScannedCode scannedCode) {
234240
SelectBundleDialog.show(context, product, new SelectBundleDialog.Callback() {
235241
@Override
236242
public void onProductSelected(Product product) {
237243
Telemetry.event(Telemetry.Event.SelectedBundleProduct, product);
238244

239245
Product.Code[] codes = product.getScannableCodes();
240-
if(codes.length > 0) {
241-
List<ScannedCode> scannedCodes = ScannedCode.parse(SnabbleUI.getProject(), codes[0].lookupCode);
242-
if (scannedCodes != null && scannedCodes.size() > 0) {
243-
showProduct(product, scannedCodes.get(0));
244-
}
246+
if (codes.length > 0) {
247+
showProduct(product, scannedCode);
245248
}
246249
}
247250

0 commit comments

Comments
 (0)