Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dq error for product quantity above 30kg #9316

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/ProductOpener/DataQualityFood.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,10 @@ sub check_quantity ($product_ref) {
if ((defined $product_ref->{product_quantity}) and ($product_ref->{product_quantity} ne "")) {
if ($product_ref->{product_quantity} > 10 * 1000) {
push @{$product_ref->{data_quality_warnings_tags}}, "en:product-quantity-over-10kg";

if ($product_ref->{product_quantity} > 30 * 1000) {
push @{$product_ref->{data_quality_errors_tags}}, "en:product-quantity-over-30kg";
}
}
if ($product_ref->{product_quantity} < 1) {
push @{$product_ref->{data_quality_warnings_tags}}, "en:product-quantity-under-1g";
Expand Down
10 changes: 9 additions & 1 deletion taxonomies/data_quality.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2794,6 +2794,14 @@ description:en:Compared to the category average, the Sugars value is abnormally

### Quantity and serving

<en:Data quality errors
en:Quantity and serving errors
description:en: Potential issues on quantities or serving size

<en:Quantity and serving errors
en:Product quantity over 30kg
description:en:Product quantity is above 30kg, which is very unlikely.

<en:Data quality warnings
en:Quantity and serving warnings
description:en: Potential issues on quantities or serving size
Expand All @@ -2804,7 +2812,7 @@ en:Product quantity in mg

<en:Quantity and serving warnings
en:Product quantity over 10kg
#description:en:
description:en:Product quantity is above 10kg, which is unlikely for most of the products

<en:Quantity and serving warnings
en:Product quantity under 1g
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/dataqualityfood.t
Original file line number Diff line number Diff line change
Expand Up @@ -1220,4 +1220,40 @@ check_quality_and_test_product_has_quality_tag(
'en:vegetarian-label-but-could-not-confirm-for-all-ingredients',
'raise warning because vegetarian or non-vegetarian is unknown for an ingredient', 0
);
# product quantity warnings and errors
$product_ref = {product_quantity => "123456789",};
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:product-quantity-over-10kg',
'raise warning because the product quantity is above 10000g', 1
);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:product-quantity-over-30kg',
'raise error because the product quantity is above 30000g', 1
);
# product quantity warnings and errors
$product_ref = {product_quantity => "20000",};
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:product-quantity-over-10kg',
'raise warning because the product quantity is above 10000g', 1
);
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:product-quantity-over-30kg',
'raise error because the product quantity is above 30000g', 0
);
$product_ref = {
product_quantity => "0.001",
quantity => "1 mg",
};
check_quality_and_test_product_has_quality_tag(
$product_ref,
'en:product-quantity-under-1g',
'raise warning because the product quantity is under 1g', 1
);
check_quality_and_test_product_has_quality_tag($product_ref, 'en:product-quantity-in-mg',
'raise warning because the product quantity is in mg', 1);

done_testing();
Loading