Skip to content

Commit 64b8d2c

Browse files
committed
Add mandatory hs tariff number validation condition
1 parent c9c8b48 commit 64b8d2c

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

WooCommerce/Classes/ViewRelated/Orders/Order Details/Shipping Labels/WooShipping Create Shipping Labels/WooShipping Customs/WooShippingCustomsItemViewModel.swift

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,20 @@ final class WooShippingCustomsItemViewModel: ObservableObject {
6464

6565
private var cancellables = Set<AnyCancellable>()
6666

67+
/// WOOMOB-891
68+
/// Shipments with a EU destination address must contain HS tariff number
69+
///
70+
/// Introduced to enforce tariff validation
71+
/// if `true` then `hsTariffNumber` must be valid for `requiredInformationIsEntered` to be `true`
72+
private let isHSTariffNumberRequired: Bool
73+
6774
init(itemName: String,
6875
itemProductID: Int64,
6976
itemQuantity: Decimal,
7077
itemValue: Double,
7178
itemWeight: Double,
7279
currencySymbol: String,
80+
isHSTariffNumberRequired: Bool = false,
7381
originCountryCode: AnyPublisher<String?, Never>? = nil,
7482
storageManager: StorageManagerType = ServiceLocator.storageManager) {
7583
self.title = itemName
@@ -85,6 +93,7 @@ final class WooShippingCustomsItemViewModel: ObservableObject {
8593

8694
self.currencySymbol = currencySymbol
8795
self.storageManager = storageManager
96+
self.isHSTariffNumberRequired = isHSTariffNumberRequired
8897

8998
originCountryCode?
9099
.assign(to: &$originCountryCode)
@@ -128,15 +137,27 @@ private extension WooShippingCustomsItemViewModel {
128137
}
129138

130139
func combineRequiredInformationIsEntered() {
131-
Publishers.CombineLatest4($description, $valuePerUnit, $weightPerUnit, $selectedCountry)
132-
.sink { [weak self] description, valuePerUnit, weightPerUnit, selectedCountry in
133-
guard let self else { return }
134-
requiredInformationIsEntered = description.isNotEmpty &&
135-
valuePerUnit.isNotEmpty &&
136-
Self.isWeightValid(weightPerUnit) &&
137-
selectedCountry != nil
138-
}
139-
.store(in: &cancellables)
140+
Publishers.CombineLatest4(
141+
$description,
142+
$valuePerUnit,
143+
$weightPerUnit,
144+
$selectedCountry
145+
)
146+
.combineLatest($hsTariffNumber)
147+
.sink { [weak self] result in
148+
guard let self else { return }
149+
150+
let ((description, valuePerUnit, weightPerUnit, selectedCountry), hsTariffNumber) = result
151+
152+
let hsTariffNumberRequirementMet = hsTariffNumber.isEmpty && !isHSTariffNumberRequired || isValidTariffNumber
153+
154+
requiredInformationIsEntered = description.isNotEmpty &&
155+
valuePerUnit.isNotEmpty &&
156+
Self.isWeightValid(weightPerUnit) &&
157+
selectedCountry != nil &&
158+
hsTariffNumberRequirementMet
159+
}
160+
.store(in: &cancellables)
140161
}
141162

142163
func combineHSTariffNumberTotalValue() {

0 commit comments

Comments
 (0)