[fix] address queries + tests
This commit is contained in:
parent
120461efef
commit
8d39fd9790
@ -75,7 +75,7 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
|
||||
},
|
||||
|
||||
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.doc.supplier_name && this.frm.doc.supplier_name!==this.frm.doc.supplier));
|
||||
|
@ -16,7 +16,7 @@ frappe.ui.form.on("Supplier", {
|
||||
});
|
||||
},
|
||||
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") {
|
||||
frm.toggle_display("naming_series", false);
|
||||
|
@ -52,9 +52,9 @@ frappe.ui.form.on("Opportunity", {
|
||||
|
||||
set_contact_link: function(frm) {
|
||||
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) {
|
||||
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
|
||||
erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
|
||||
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;
|
||||
|
||||
|
@ -25,7 +25,7 @@ frappe.ui.form.on('Maintenance Visit', {
|
||||
// TODO commonify this code
|
||||
erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
|
||||
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) {
|
||||
cur_frm.add_custom_button(__('Maintenance Schedule'),
|
||||
|
@ -43,28 +43,28 @@ $.extend(erpnext.queries, {
|
||||
},
|
||||
|
||||
contact_query: function(doc) {
|
||||
if(frappe.contact_link) {
|
||||
if(!doc[frappe.contact_link.fieldname]) {
|
||||
if(frappe.dynamic_link) {
|
||||
if(!doc[frappe.dynamic_link.fieldname]) {
|
||||
frappe.throw(__("Please set {0}", __(frappe.meta.get_label(doc.doctype,
|
||||
frappe.contact_link.fieldname, doc.name))));
|
||||
frappe.dynamic_link.fieldname, doc.name))));
|
||||
}
|
||||
|
||||
return {
|
||||
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) {
|
||||
if(frappe.contact_link) {
|
||||
if(!doc[frappe.contact_link.fieldname]) {
|
||||
if(frappe.dynamic_link) {
|
||||
if(!doc[frappe.dynamic_link.fieldname]) {
|
||||
frappe.throw(__("Please set {0}", __(frappe.meta.get_label(doc.doctype,
|
||||
frappe.contact_link.fieldname, doc.name))));
|
||||
frappe.dynamic_link.fieldname, doc.name))));
|
||||
}
|
||||
|
||||
return {
|
||||
query: 'frappe.email.doctype.address.address_query',
|
||||
filters: { link_doctype: frappe.contact_link.doctype, link_name: doc[frappe.contact_link.fieldname] } };
|
||||
query: 'frappe.geo.doctype.address.address.address_query',
|
||||
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();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -67,12 +67,8 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
|
||||
this.frm.toggle_reqd("customer", this.frm.doc.quotation_to == "Customer");
|
||||
|
||||
// to overwrite the customer_filter trigger from queries.js
|
||||
$.each(["customer_address", "shipping_address_name"],
|
||||
function(i, opts) {
|
||||
me.frm.set_query(opts, me.frm.doc.quotation_to==="Lead"
|
||||
? erpnext.queries["lead_filter"] : erpnext.queries["customer_filter"]);
|
||||
}
|
||||
);
|
||||
this.frm.set_query('customer_address', erpnext.queries.address_query);
|
||||
this.frm.set_query('shipping_address_name', erpnext.queries.address_query);
|
||||
},
|
||||
|
||||
tc_name: function() {
|
||||
|
@ -106,7 +106,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
|
||||
refresh: function() {
|
||||
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.doc.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer));
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
frappe.ui.form.on('Sales Partner', {
|
||||
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){
|
||||
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:
|
||||
return []
|
||||
|
||||
address_docs = frappe.db.sql("""select * from `tabAddress`
|
||||
where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(),
|
||||
limit_start, limit_page_length), party.name,
|
||||
as_dict=True, update={"doctype": "Address"})
|
||||
address_names = frappe.db.get_all('Dyanamic Link', fields=('parent'),
|
||||
filters=dict(parenttype='Address', link_doctype=party.doctype, link_name=party.name))
|
||||
|
||||
for address in address_docs:
|
||||
address.display = get_address_display(address)
|
||||
out = []
|
||||
|
||||
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()
|
||||
def apply_shipping_rule(shipping_rule):
|
||||
|
@ -21,7 +21,7 @@ frappe.ui.form.on("Warranty Claim", {
|
||||
|
||||
erpnext.support.WarrantyClaim = frappe.ui.form.Controller.extend({
|
||||
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 &&
|
||||
(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):
|
||||
for parenttype in ('Contact', 'Address'):
|
||||
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))
|
||||
|
||||
for name in items:
|
||||
|
Loading…
x
Reference in New Issue
Block a user