Thanks to DanijelÂ
who is kindly updating the Northwind2 v7 application.
This is what he came about:
- check the Stock level and warn the user to raise a Purchase Order first:
This is the empty form before Quantity is entered:
The server side log:
{'product_id': 99, 'product_name': 'Northwind Traders Chicken Soup', 'quantity_on_back_order': 0, 'quantity_purchased': 0, 'quantity_on_hand': 0, 'quantity_sold': 0, 'quantity_on_hold': 0, 'quantity_on_order': 0, 'target_level': 200}
with the message:
This example demonstrates Form DETAILÂ on_field_changed executing the server side code:
function on_field_changed(field, lookup_item) {
  let item = field.owner;
 Â
  if (field.field_name ==='product_id' && lookup_item) {
    item.unit_price.value = lookup_item.standard_cost.value;
  }
 Â
  if (field.field_name ==='quantity') {
    if (field.value) {
      calc(item);
      item.edit_form.find('.quantity db-input').focus();
   Â
      let product_inv_data = item.server('check_product', [item.product_id.value]);
      console.log(product_inv_data.quantity_on_hold);
     Â
      if (product_inv_data.quantity_on_hold > 0) {
        calc(item);
        item.status_id.value = 1;
        item.status_id.lookup_value = 'Allocated';
        item.edit_form.find('#product_stock_info').show().text('Product is allocated with: '+ product_inv_data.quantity_on_hold + ' quantity on hold!');
      }
     Â
      else if (product_inv_data.quantity_on_hold === 0) {
        item.status_id.value = 5;
        item.status_id.lookup_value = 'No Stock';
        item.edit_form.find('#product_stock_info').show().append('<b>' + product_inv_data.quantity_on_hold + '</b>.<br> Product has insufficient inventory, you need to create a purchase order!');
        item.edit_form.find('#purchase_order_btn').show();
      }
    }
  }
 Â
  if (field.field_name === 'discount' && field.value) {
    calc(item);
  }
 Â
}
Cheers