mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-28 01:14:46 +00:00
[fix] address queries + tests
This commit is contained in:
@@ -75,7 +75,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
refresh: function(doc) {
|
refresh: function(doc) {
|
||||||
frappe.contact_link = {doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier'};
|
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier'};
|
||||||
|
|
||||||
this.frm.toggle_display("supplier_name",
|
this.frm.toggle_display("supplier_name",
|
||||||
(this.frm.doc.supplier_name && this.frm.doc.supplier_name!==this.frm.doc.supplier));
|
(this.frm.doc.supplier_name && this.frm.doc.supplier_name!==this.frm.doc.supplier));
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ frappe.ui.form.on("Supplier", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
frappe.contact_link = {doc: frm.doc, fieldname: 'name', doctype: 'Supplier'}
|
frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Supplier'}
|
||||||
|
|
||||||
if(frappe.defaults.get_default("supp_master_name")!="Naming Series") {
|
if(frappe.defaults.get_default("supp_master_name")!="Naming Series") {
|
||||||
frm.toggle_display("naming_series", false);
|
frm.toggle_display("naming_series", false);
|
||||||
|
|||||||
@@ -52,9 +52,9 @@ frappe.ui.form.on("Opportunity", {
|
|||||||
|
|
||||||
set_contact_link: function(frm) {
|
set_contact_link: function(frm) {
|
||||||
if(frm.doc.customer) {
|
if(frm.doc.customer) {
|
||||||
frappe.contact_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
||||||
} else if(frm.doc.lead) {
|
} else if(frm.doc.lead) {
|
||||||
frappe.contact_link = {doc: frm.doc, fieldname: 'lead', doctype: 'Lead'}
|
frappe.dynamic_link = {doc: frm.doc, fieldname: 'lead', doctype: 'Lead'}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ frappe.ui.form.on('Maintenance Schedule', {
|
|||||||
// TODO commonify this code
|
// TODO commonify this code
|
||||||
erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
|
erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
|
||||||
refresh: function() {
|
refresh: function() {
|
||||||
frappe.contact_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
||||||
|
|
||||||
var me = this;
|
var me = this;
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ frappe.ui.form.on('Maintenance Visit', {
|
|||||||
// TODO commonify this code
|
// TODO commonify this code
|
||||||
erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
|
erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
|
||||||
refresh: function() {
|
refresh: function() {
|
||||||
frappe.contact_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
||||||
|
|
||||||
if (this.frm.doc.docstatus===0) {
|
if (this.frm.doc.docstatus===0) {
|
||||||
cur_frm.add_custom_button(__('Maintenance Schedule'),
|
cur_frm.add_custom_button(__('Maintenance Schedule'),
|
||||||
|
|||||||
@@ -43,28 +43,28 @@ $.extend(erpnext.queries, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
contact_query: function(doc) {
|
contact_query: function(doc) {
|
||||||
if(frappe.contact_link) {
|
if(frappe.dynamic_link) {
|
||||||
if(!doc[frappe.contact_link.fieldname]) {
|
if(!doc[frappe.dynamic_link.fieldname]) {
|
||||||
frappe.throw(__("Please set {0}", __(frappe.meta.get_label(doc.doctype,
|
frappe.throw(__("Please set {0}", __(frappe.meta.get_label(doc.doctype,
|
||||||
frappe.contact_link.fieldname, doc.name))));
|
frappe.dynamic_link.fieldname, doc.name))));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
query: 'frappe.email.doctype.contact.contact.contact_query',
|
query: 'frappe.email.doctype.contact.contact.contact_query',
|
||||||
filters: { link_doctype: frappe.contact_link.doctype, link_name: doc[frappe.contact_link.fieldname] } };
|
filters: { link_doctype: frappe.dynamic_link.doctype, link_name: doc[frappe.dynamic_link.fieldname] } };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
address_query: function(doc) {
|
address_query: function(doc) {
|
||||||
if(frappe.contact_link) {
|
if(frappe.dynamic_link) {
|
||||||
if(!doc[frappe.contact_link.fieldname]) {
|
if(!doc[frappe.dynamic_link.fieldname]) {
|
||||||
frappe.throw(__("Please set {0}", __(frappe.meta.get_label(doc.doctype,
|
frappe.throw(__("Please set {0}", __(frappe.meta.get_label(doc.doctype,
|
||||||
frappe.contact_link.fieldname, doc.name))));
|
frappe.dynamic_link.fieldname, doc.name))));
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
query: 'frappe.email.doctype.address.address_query',
|
query: 'frappe.geo.doctype.address.address.address_query',
|
||||||
filters: { link_doctype: frappe.contact_link.doctype, link_name: doc[frappe.contact_link.fieldname] } };
|
filters: { link_doctype: frappe.dynamic_link.doctype, link_name: doc[frappe.dynamic_link.fieldname] } };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ frappe.ui.form.on("Customer", {
|
|||||||
erpnext.toggle_naming_series();
|
erpnext.toggle_naming_series();
|
||||||
}
|
}
|
||||||
|
|
||||||
frappe.contact_link = {doc: frm.doc, fieldname: 'name', doctype: 'Customer'}
|
frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Customer'}
|
||||||
|
|
||||||
frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal);
|
frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal);
|
||||||
|
|
||||||
|
|||||||
@@ -67,12 +67,8 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
|
|||||||
this.frm.toggle_reqd("customer", this.frm.doc.quotation_to == "Customer");
|
this.frm.toggle_reqd("customer", this.frm.doc.quotation_to == "Customer");
|
||||||
|
|
||||||
// to overwrite the customer_filter trigger from queries.js
|
// to overwrite the customer_filter trigger from queries.js
|
||||||
$.each(["customer_address", "shipping_address_name"],
|
this.frm.set_query('customer_address', erpnext.queries.address_query);
|
||||||
function(i, opts) {
|
this.frm.set_query('shipping_address_name', erpnext.queries.address_query);
|
||||||
me.frm.set_query(opts, me.frm.doc.quotation_to==="Lead"
|
|
||||||
? erpnext.queries["lead_filter"] : erpnext.queries["customer_filter"]);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
|
|
||||||
tc_name: function() {
|
tc_name: function() {
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
|||||||
refresh: function() {
|
refresh: function() {
|
||||||
this._super();
|
this._super();
|
||||||
|
|
||||||
frappe.contact_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
||||||
|
|
||||||
this.frm.toggle_display("customer_name",
|
this.frm.toggle_display("customer_name",
|
||||||
(this.frm.doc.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer));
|
(this.frm.doc.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer));
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
frappe.ui.form.on('Sales Partner', {
|
frappe.ui.form.on('Sales Partner', {
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
frappe.contact_link = {doc: frm.doc, fieldname: 'name', doctype: 'Sales Person'}
|
frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Sales Person'}
|
||||||
|
|
||||||
if(doc.__islocal){
|
if(doc.__islocal){
|
||||||
hide_field(['address_html', 'contact_html']);
|
hide_field(['address_html', 'contact_html']);
|
||||||
|
|||||||
@@ -375,15 +375,17 @@ def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_
|
|||||||
if not party:
|
if not party:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
address_docs = frappe.db.sql("""select * from `tabAddress`
|
address_names = frappe.db.get_all('Dyanamic Link', fields=('parent'),
|
||||||
where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(),
|
filters=dict(parenttype='Address', link_doctype=party.doctype, link_name=party.name))
|
||||||
limit_start, limit_page_length), party.name,
|
|
||||||
as_dict=True, update={"doctype": "Address"})
|
|
||||||
|
|
||||||
for address in address_docs:
|
out = []
|
||||||
address.display = get_address_display(address)
|
|
||||||
|
|
||||||
return address_docs
|
for address_name in address_names:
|
||||||
|
address = frappe.get_doc('Address', address_name)
|
||||||
|
address.display = get_address_display(address.as_dict())
|
||||||
|
out.append(address)
|
||||||
|
|
||||||
|
return out
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def apply_shipping_rule(shipping_rule):
|
def apply_shipping_rule(shipping_rule):
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ frappe.ui.form.on("Warranty Claim", {
|
|||||||
|
|
||||||
erpnext.support.WarrantyClaim = frappe.ui.form.Controller.extend({
|
erpnext.support.WarrantyClaim = frappe.ui.form.Controller.extend({
|
||||||
refresh: function() {
|
refresh: function() {
|
||||||
frappe.contact_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
|
||||||
|
|
||||||
if(!cur_frm.doc.__islocal &&
|
if(!cur_frm.doc.__islocal &&
|
||||||
(cur_frm.doc.status=='Open' || cur_frm.doc.status == 'Work In Progress')) {
|
(cur_frm.doc.status=='Open' || cur_frm.doc.status == 'Work In Progress')) {
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ def get_permitted_and_not_permitted_links(doctype):
|
|||||||
def delete_contact_and_address(doctype, name):
|
def delete_contact_and_address(doctype, name):
|
||||||
for parenttype in ('Contact', 'Address'):
|
for parenttype in ('Contact', 'Address'):
|
||||||
items = frappe.db.sql("""select parent from `tabDynamic Link`
|
items = frappe.db.sql("""select parent from `tabDynamic Link`
|
||||||
where parenttype=%s and link_type=%s and link_name=%s""",
|
where parenttype=%s and link_doctype=%s and link_name=%s""",
|
||||||
(parenttype, doctype, name))
|
(parenttype, doctype, name))
|
||||||
|
|
||||||
for name in items:
|
for name in items:
|
||||||
|
|||||||
Reference in New Issue
Block a user