[Partial] Fix to add Shipping address in Purchase order

This commit is contained in:
shreyas 2016-02-01 15:32:32 +05:30 committed by Nabin Hait
parent 91a69e4a8d
commit 22d26a1d82
4 changed files with 144 additions and 47 deletions

View File

@ -13,6 +13,12 @@ frappe.ui.form.on("Purchase Order", {
}
});
frappe.ui.form.on_change("Purchase Order", "company", function(frm){
erpnext.utils.get_shipping_address(frm.doc)
}
);
erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({
refresh: function(doc, cdt, cdn) {
var me = this;

View File

@ -20,18 +20,18 @@ erpnext.utils.get_party_details = function(frm, method, args, callback) {
price_list: frm.doc.buying_price_list
};
}
if (args) {
args.posting_date = frm.doc.posting_date || frm.doc.transaction_date;
}
}
if(!args) return;
if(frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
if(!erpnext.utils.validate_mandatory(frm, "Posting/Transaction Date",
if(!erpnext.utils.validate_mandatory(frm, "Posting/Transaction Date",
args.posting_date, args.party_type=="Customer" ? "customer": "supplier")) return;
}
args.currency = frm.doc.currency;
args.company = frm.doc.company;
args.doctype = frm.doc.doctype;
@ -51,7 +51,7 @@ erpnext.utils.get_party_details = function(frm, method, args, callback) {
erpnext.utils.get_address_display = function(frm, address_field, display_field) {
if(frm.updating_party_details) return;
if(!address_field) {
if(frm.doctype != "Purchase Order" && frm.doc.customer) {
address_field = "customer_address";
@ -59,7 +59,7 @@ erpnext.utils.get_address_display = function(frm, address_field, display_field)
address_field = "supplier_address";
} else return;
}
if(!display_field) display_field = "address_display";
if(frm.doc[address_field]) {
frappe.call({
@ -69,15 +69,15 @@ erpnext.utils.get_address_display = function(frm, address_field, display_field)
if(r.message){
frm.set_value(display_field, r.message)
}
if(frappe.meta.get_docfield(frm.doc.doctype, "taxes")) {
if(!erpnext.utils.validate_mandatory(frm, "Customer/Supplier",
if(!erpnext.utils.validate_mandatory(frm, "Customer/Supplier",
frm.doc.customer || frm.doc.supplier, address_field)) return;
if(!erpnext.utils.validate_mandatory(frm, "Posting/Transaction Date",
if(!erpnext.utils.validate_mandatory(frm, "Posting/Transaction Date",
frm.doc.posting_date || frm.doc.transaction_date, address_field)) return;
} else return;
frappe.call({
method: "erpnext.accounts.party.set_taxes",
args: {
@ -122,4 +122,19 @@ erpnext.utils.validate_mandatory = function(frm, label, value, trigger_on) {
return false;
}
return true;
}
}
erpnext.utils.get_shipping_address = function(doc){
if(doc.doctype === "Purchase Order"){
frappe.call({
method: "erpnext.utilities.doctype.address.address.get_shipping_address",
args: {company: doc.company},
callback: function(r){
if(r.message){
doc.customer_address = r.message[0] //Address title or name
doc.customer_address_display = r.message[1] //Address to be displayed on the page
}
}
});
}
}

View File

@ -24,6 +24,7 @@
"options": "icon-map-marker",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -47,6 +48,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -70,6 +72,7 @@
"options": "Billing\nShipping\nOffice\nPersonal\nPlant\nPostal\nShop\nSubsidiary\nWarehouse\nOther",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
@ -92,6 +95,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
@ -114,6 +118,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -136,6 +141,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
@ -158,6 +164,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -180,6 +187,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -203,6 +211,7 @@
"options": "Country",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
@ -224,6 +233,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -247,6 +257,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -269,6 +280,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -291,6 +303,32 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "company",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Company",
"length": 0,
"no_copy": 0,
"options": "Company",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -315,6 +353,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -339,6 +378,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -362,6 +402,7 @@
"options": "icon-pushpin",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -373,6 +414,32 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"default": "0",
"fieldname": "is_company_address",
"fieldtype": "Check",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Is Company Address",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"depends_on": "eval:!doc.is_company_address",
"fieldname": "customer",
"fieldtype": "Link",
"hidden": 0,
@ -385,6 +452,7 @@
"options": "Customer",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -396,6 +464,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"depends_on": "eval:!doc.is_company_address",
"fieldname": "customer_name",
"fieldtype": "Data",
"hidden": 0,
@ -407,6 +476,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
@ -418,6 +488,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"depends_on": "eval:!doc.is_company_address",
"fieldname": "supplier",
"fieldtype": "Link",
"hidden": 0,
@ -430,6 +501,7 @@
"options": "Supplier",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -441,6 +513,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"depends_on": "eval:!doc.is_company_address",
"fieldname": "supplier_name",
"fieldtype": "Data",
"hidden": 0,
@ -452,6 +525,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
@ -463,6 +537,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"depends_on": "eval: !doc.is_company_address",
"fieldname": "sales_partner",
"fieldtype": "Link",
"hidden": 0,
@ -475,6 +550,7 @@
"options": "Sales Partner",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -486,28 +562,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "column_break_22",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"depends_on": "eval:!doc.supplier && !doc.sales_partner",
"depends_on": "eval:!doc.supplier && !doc.sales_partner && !doc.is_company_address",
"fieldname": "lead",
"fieldtype": "Link",
"hidden": 0,
@ -520,6 +575,7 @@
"options": "Lead",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
@ -531,7 +587,7 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"depends_on": "eval:!doc.supplier && !doc.sales_partner",
"depends_on": "eval:!doc.supplier && !doc.sales_partner && !doc.is_company_address",
"fieldname": "lead_name",
"fieldtype": "Data",
"hidden": 0,
@ -543,6 +599,7 @@
"no_copy": 0,
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
@ -561,7 +618,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2015-11-16 06:29:41.719278",
"modified": "2016-02-01 03:53:26.219482",
"modified_by": "Administrator",
"module": "Utilities",
"name": "Address",

View File

@ -83,20 +83,12 @@ class Address(Document):
def get_address_display(address_dict):
if not address_dict:
return
if not isinstance(address_dict, dict):
address_dict = frappe.db.get_value("Address", address_dict, "*", as_dict=True) or {}
data = frappe.db.get_value("Address Template", \
{"country": address_dict.get("country")}, ["name", "template"])
if not data:
data = frappe.db.get_value("Address Template", \
{"is_default": 1}, ["name", "template"])
if not data:
frappe.throw(_("No default Address Template found. Please create a new one from Setup > Printing and Branding > Address Template."))
name, template = data
name, template = get_address_templates(address_dict)
try:
return frappe.render_template(template, address_dict)
except TemplateSyntaxError:
@ -138,3 +130,30 @@ def has_website_permission(doc, ptype, user, verbose=False):
return doc.lead == lead
return False
def get_address_templates(address):
name, template = frappe.db.get_value("Address Template", \
{"country": address.get("country")}, ["name", "template"])
if not template:
name, template = frappe.db.get_value("Address Template", \
{"is_default": 1}, ["name", "template"])
if not template:
frappe.throw(_("No default Address Template found. Please create a new one from Setup > Printing and Branding > Address Template."))
else:
return name, template
@frappe.whitelist()
def get_shipping_address(company):
filters = {"company": company, "is_company_address":1}
fieldname = ["name", "address_line1", "address_line2", "city", "state", "country"]
address_as_dict = frappe.db.get_value("Address", filters=filters, fieldname=fieldname, as_dict=True)
if not address_as_dict:
frappe.throw(_("Please add addresses for the company"))
else:
name, address_template = get_address_templates(address_as_dict)
return address_as_dict.get("name"), frappe.render_template(address_template, address_as_dict)