Auto-update Inventory status
When inventory is saved (inserted or updated) the availabilityStatusCode
should be automatically updated if isAutoDeducted == "Y"
:
- if
quantity_on_hand <= distribution_critical_quantity
andavailability_status_code == "AVAIL"
, then setavailability_status_code = "LOW"
andis_available = "N"
. - if
quantity_on_hand > distribution_critical_quantity
setavailability_status_code = "AVAIL"
andis_available = "Y"
.
Original code:
if (helper.AllFieldsExist("is_auto_deducted", "quantity_on_hand", "distribution_critical_quantity") && helper.GetValue("is_auto_deducted", "N", true).ToString().ToUpper() == "Y") {
double onHand = Convert.ToDouble(helper.GetValue("quantity_on_hand", 0.0, true));
double critical = Convert.ToDouble(helper.GetValue("distribution_critical_quantity", 0.0, true));
if (onHand <= critical) {
if (helper.FieldExists("availability_status_code") && helper.GetValue("availability_status_code", "", true).ToString().ToUpper() == "AVAIL") {
helper.SetValue("availability_status_code", "LOW", null, false);
if (helper.FieldExists("is_available") && helper.GetValue("is_available", "Y", true).ToString().ToUpper() == "Y") {
helper.SetValue("is_available", "N", null, false);
}
}
} else if (onHand > critical) {
if (helper.FieldExists("availability_status_code") && helper.GetValue("availability_status_code", "", true).ToString().ToUpper() == "LOW") {
helper.SetValue("availability_status_code", "AVAIL", null, false);
if (helper.FieldExists("is_available") && helper.GetValue("is_available", "N", true).ToString().ToUpper() == "N") {
helper.SetValue("is_available", "Y", null, false);
}
}
}
}