Getting Default values in child table

Can someone help me with the script for setting default value for default warehouse, based on customer entered.

Basically I have a mutli-company setup, with 2 warehouses. In sales order I want to auto-populate delivery warehouse of salesorderitem with pre-defined value. For this I made a custom field in customer called default warehouse.How do I fill in the default warehouse value in the table for every product.

@LifeP

frappe.ui.form.on("Sales Order", "customer", function(frm, cdt, cdn){
    frappe.call({
        'method': 'frappe.client.get_value',
        'args': {
            'doctype': 'Customer',
            'fieldname': 'delivery_warehouse',
            'filters': {
              'name': frm.doc.customer
            },
           callback: function(res){
               if (res && res.message){
                       frappe.meta.get_docfield("Sales Order Item", "delivery_warehouse").default = res.message.delivery_warehouse;
               }
           }
        }
    });
});

3 Likes

@max_morais_dmm you seem to be using this pattern a lot.

We should just have a wrap function in js like:

frappe.db.get_value(doctype, filters, fieldname, function(value) { });

let me push it :smile:

Edit: [enhancement] added frappe.db.get_value in js by rmehta · Pull Request #1533 · frappe/frappe · GitHub

5 Likes

Would this be the same method for getting a specific address item into a print format for a sales invoice? I am trying to get only address_line1 and city from the address for a customer, so it can be printed in the Sales Invoice but cannot get around doing this, given the current methods. I have been successful in getting custom field values using: {{ frappe.db.get_value(“Customer”, doc.customer, “tax_id”) }}, however, gettin specific address fields, I have not been so lucky.

@Tropicalrambler pass {‘customer’: doc.customer} instead of doc.customer for address!