Skip to content

Pincode lookup

lasalesi edited this page Mar 9, 2020 · 3 revisions

The pincode lookup allows to only enter the pincode of an address and resolve the city from it.

Preparation

Open Pincode List, then Menu > Import Pincodes. Select a file with pincodes, ERPNextSwiss contains a recent set which is available from /assets/erpnextswiss/res/pincodes.csv. Click import and all new pincodes will be loaded. The csv importer expects a UTF-8 encoded file with the column definition in the first row. The column sequence does not matter, but should contain the columns pincode, city, canton, canton_code, country and country_code.

For the forms, where the lookup should take place, include a custom script like

frappe.ui.form.on("Address", {
    pincode: function(frm) {
        if (frm.doc.pincode) {
            get_city_from_pincode(frm.doc.pincode, 'city');
        }
    }
});

Usage

Enter a pincode and hit tab. The lookup will try to find the code. If it finds it, it will fetch the city to the target field. If there are multiple matches, there is a select dialog to choose.

Distance calculation

The pincode module allows you to automatically calculate the distance between 2 pincodes (based on latitude/longitude, geographical distance, not actual road distance). This is especially useful when automatically computing the shipping cost.

function get_distance(pincode) {
    frappe.call({
       method: 'erpnextswiss.erpnextswiss.doctype.pincode.pincode.get_distance',
       args: {
           pincode1: '8400',
           pincode2: pincode
       },
       callback: function(r) {
            var distance = r.message;
            frappe.msgprint("Distance to Winterthur is " + distance + " km.");
       } 
    });
}

Disclaimer

This repository contains reference data for several countries in the public folder. Most countries are derived from data from http://www.geonames.org. If you are looking for other countries, please refer to http://www.geonames.org

Clone this wiki locally