Custom field link multiple options

Hi All

I create doctype “Vendors” ,and I want to use this doctype in purchase invoice for example Specifically on supplier field , but supplier field contain one option “supplier” .
I created field “is vendor” Type “Check”, to fetch vendors in supplier field, But it’s no use

frappe.ui.form.on('Purchase Invoice', {
    
    is_vendor: function(frm) {
            // frm.set_df_property('institute_project', 'reqd', 1);
                frm.set_query('supplier', () => {
                    return {
                        query: 'erp_jordan.api_helper.filter_purchase_invoice.custom_query',
                        filters: frm.doc.is_vendor === 1 ? 
                            { }:{ }
                        }
                    }
                ) 
}
});

Is there a solution, or do I have to create a Purchase Invoice, Payment Entry for the Vendors?
I accept the advice
Thanks all
@ankush
@dj12djdjs

Hi,

First, you should update the “supplier” field in the Purchase Invoice doctype to be linked to the “Vendors” doctype instead of the default “Supplier” doctype.

Next, the set_query function needs to be called on the supplier field, not on the is_vendor field.

frappe.ui.form.on('Purchase Invoice', {
  vendor: function(frm) {
    frm.set_query('supplier', () => {
      return {
        query: 'frappe.contacts.doctype.contact.contact.autocomplete_search',
        filters: {
          link_doctype: 'Vendors',
          is_vendor: 1
        }
      }
    });
  }
});

With these changes, you should be able to select a vendor from the “Vendors” doctype in the supplier field of the Purchase Invoice form.

Hope this will help you out.

Thank you.

1 Like

Hi @VINOTH
I want to use both (vendors and supplier) in purchase invoice ,Is it possible to do that? Bro

Yes, it is possible to use both “Vendors” and “Supplier” in a Purchase Invoice. You can modify the “Supplier” field to allow it to fetch values from both the “Supplier” doctype and the “Vendors” doctype.

frappe.ui.form.on('Purchase Invoice', {
    supplier: function(frm) {
        var vendor_query = {
            filters: [
                ['Supplier', 'supplier_type', '=', 'Local'],
                ['Supplier', 'disabled', '=', 0]
            ]
        };

        var vendor_query_str = JSON.stringify(vendor_query);

        var supplier_query = {
            query: 'erpnext.controllers.queries.get_party_query',
            filters: [
                ['Party', 'party_type', '=', 'Supplier'],
                ['Party', 'disabled', '=', 0]
            ]
        };

        var supplier_query_str = JSON.stringify(supplier_query);

        frm.set_query('supplier', function() {
            if (frm.doc.is_vendor) {
                return {
                    'query': 'frappe.contacts.doctype.contact.contact.supplier_query',
                    'filters': [
                        ['Contact', 'is_vendor', '=', 1],
                        ['Contact', 'disabled', '=', 0]
                    ]
                };
            } else {
                return {
                    'query': 'frappe.contacts.doctype.contact.contact.supplier_query',
                    'filters': [
                        ['Contact', 'supplier', '=', 1],
                        ['Contact', 'disabled', '=', 0]
                    ]
                };
            }
        });
    }
});

Hope this will help you out.

Thank you.

3 Likes

Thanks You Very much bro

Bro ,The Vendors list is shown, but I can’t proceed to select it

select vendors3

what should I do ?

The problem is in the filter method, you can try the below code.

frappe.ui.form.on('Purchase Invoice', {
    supplier: function(frm) {
        var vendor_query = {
            filters: [
                ['Supplier', 'supplier_type', '=', 'Local'],
                ['Supplier', 'disabled', '=', 0]
            ]
        };

        var vendor_query_str = JSON.stringify(vendor_query);

        var supplier_query = {
            query: 'erpnext.controllers.queries.get_party_query',
            filters: [
                ['Party', 'party_type', '=', 'Supplier'],
                ['Party', 'disabled', '=', 0]
            ]
        };

        var supplier_query_str = JSON.stringify(supplier_query);

        frm.set_query('supplier', function() {
            if (frm.doc.is_vendor) {
                return {
                    'query': 'frappe.contacts.doctype.contact.contact.supplier_query',
                    'filters': [
                        ['Contact', 'is_vendor', '=', 1],
                        ['Contact', 'disabled', '=', 0]
                    ]
                };
            } else {
                var supplier_query = {
                    query: 'erpnext.controllers.queries.get_party_query',
                    filters: [
                        ['Party', 'party_type', '=', 'Supplier'],
                        ['Party', 'disabled', '=', 0]
                    ]
                };
                return supplier_query;
            }
        });
    }
});

Hope this will help you out.

Thank you.

2 Likes

Thanks for the response bro , but still not working

Can You Help me Sir @brian_pond

I think creating new doctype for vendor is not good way to handle this scinario
You can create one dropdow(select field ) in supplier master with options (Supplier, Vendor)
then you have to do vendor entry in supplier master only
that way you can use both in supplier field in purchase invoice and this way it’ll not break erpnext internal flow which base on Supplier master

1 Like

Hi,

The few thing you can check:

  1. Make sure that your custom query in the filter_purchase_invoice module is returning the correct data. You can test this by running the query directly in the database or using the bench console command to test it in the Frappe shell.
  2. Double-check that the supplier field is of the correct type and has been linked to the Vendors doctype. You can do this by going to the Purchase Invoice doctype in the Frappe Desk, clicking on the supplier field, and verifying that the Options field is set to Vendors.
  3. Check that there are no errors in the browser console when you try to select a vendor. Open the browser console (usually by pressing F12) and try to select a vendor. If there are any errors in the console, they may provide a clue as to what is going wrong.
  4. Try removing the is_vendor filter from the set_query function and see if you can select any vendors at all. If you can, then the problem may be with your filter. If you still can’t select any vendors, then the problem may be elsewhere in your code.
  5. Finally, consider adding some debug statements to your code to help you identify where the problem is. You can use the console.log() function to output messages to the browser console, which can help you track the flow of your code and see where things are going wrong.

Hope this will help you out.

Thank you.

1 Like

Hello Bro, This I did