fix: Change dynamic_field name and minor fixes

This commit is contained in:
deepeshgarg007
2019-04-25 17:29:21 +05:30
parent 3959bf34ee
commit 3d31bccaf6
16 changed files with 75 additions and 90 deletions

View File

@@ -90,11 +90,11 @@ class Lead(SellingController):
return frappe.db.get_value("Customer", {"lead_name": self.name}) return frappe.db.get_value("Customer", {"lead_name": self.name})
def has_opportunity(self): def has_opportunity(self):
return frappe.db.get_value("Opportunity", {"customer_lead": self.name, "status": ["!=", "Lost"]}) return frappe.db.get_value("Opportunity", {"party_name": self.name, "status": ["!=", "Lost"]})
def has_quotation(self): def has_quotation(self):
return frappe.db.get_value("Quotation", { return frappe.db.get_value("Quotation", {
"customer_lead": self.name, "party_name": self.name,
"docstatus": 1, "docstatus": 1,
"status": ["!=", "Lost"] "status": ["!=", "Lost"]

View File

@@ -20,7 +20,7 @@ frappe.ui.form.on("Opportunity", {
}); });
}, },
customer_lead: function(frm) { party_name: function(frm) {
if (frm.doc.opportunity_from == "Customer") { if (frm.doc.opportunity_from == "Customer") {
frm.trigger('set_contact_link'); frm.trigger('set_contact_link');
erpnext.utils.get_party_details(frm); erpnext.utils.get_party_details(frm);
@@ -38,7 +38,7 @@ frappe.ui.form.on("Opportunity", {
contact_person: erpnext.utils.get_contact_details, contact_person: erpnext.utils.get_contact_details,
opportunity_from: function(frm) { opportunity_from: function(frm) {
frm.toggle_reqd("customer_lead", frm.doc.opportunity_from); frm.toggle_reqd("party_name", frm.doc.opportunity_from);
frm.trigger("set_dynamic_field_label"); frm.trigger("set_dynamic_field_label");
}, },
@@ -81,22 +81,17 @@ frappe.ui.form.on("Opportunity", {
}, },
set_contact_link: function(frm) { set_contact_link: function(frm) {
if(frm.doc.opportunity_from == "Customer" && frm.doc.customer_lead) { if(frm.doc.opportunity_from == "Customer" && frm.doc.party_name) {
frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'} frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'}
} else if(frm.doc.opportunity_from == "Lead" && frm.doc.customer_lead) { } else if(frm.doc.opportunity_from == "Lead" && frm.doc.party_name) {
frappe.dynamic_link = {doc: frm.doc, fieldname: 'lead', doctype: 'Lead'} frappe.dynamic_link = {doc: frm.doc, fieldname: 'lead', doctype: 'Lead'}
} }
}, },
set_dynamic_field_label: function(frm){ set_dynamic_field_label: function(frm){
if (frm.doc.opportunity_from == "Customer")
{
frm.set_df_property("customer_lead", "label", "Customer");
}
if (frm.doc.opportunity_from == "Lead") if (frm.doc.opportunity_from) {
{ frm.set_df_property("party_name", "label", frm.doc.opportunity_from);
frm.set_df_property("customer_lead", "label", "Lead");
} }
}, },
@@ -162,7 +157,7 @@ erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({
$.extend(cur_frm.cscript, new erpnext.crm.Opportunity({frm: cur_frm})); $.extend(cur_frm.cscript, new erpnext.crm.Opportunity({frm: cur_frm}));
cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) {
if(doc.opportunity_from == 'Lead' && doc.customer_lead) if(doc.opportunity_from == 'Lead' && doc.party_name)
cur_frm.cscript.lead(doc, cdt, cdn); cur_frm.cscript.lead(doc, cdt, cdn);
} }
@@ -185,10 +180,10 @@ cur_frm.cscript.item_code = function(doc, cdt, cdn) {
} }
cur_frm.cscript.lead = function(doc, cdt, cdn) { cur_frm.cscript.lead = function(doc, cdt, cdn) {
cur_frm.toggle_display("contact_info", doc.customer_lead); cur_frm.toggle_display("contact_info", doc.party_name);
erpnext.utils.map_current_doc({ erpnext.utils.map_current_doc({
method: "erpnext.crm.doctype.lead.lead.make_opportunity", method: "erpnext.crm.doctype.lead.lead.make_opportunity",
source_name: cur_frm.doc.customer_lead, source_name: cur_frm.doc.party_name,
frm: cur_frm frm: cur_frm
}); });
} }

View File

@@ -127,7 +127,7 @@
"columns": 0, "columns": 0,
"depends_on": "", "depends_on": "",
"fetch_if_empty": 0, "fetch_if_empty": 0,
"fieldname": "customer_lead", "fieldname": "party_name",
"fieldtype": "Dynamic Link", "fieldtype": "Dynamic Link",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
@@ -148,7 +148,7 @@
"read_only": 0, "read_only": 0,
"remember_last_selected_value": 0, "remember_last_selected_value": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 1,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"translatable": 0, "translatable": 0,
@@ -162,6 +162,7 @@
"collapsible": 0, "collapsible": 0,
"columns": 0, "columns": 0,
"depends_on": "", "depends_on": "",
"fetch_from": "party_name.customer_name",
"fetch_if_empty": 0, "fetch_if_empty": 0,
"fieldname": "customer_name", "fieldname": "customer_name",
"fieldtype": "Data", "fieldtype": "Data",
@@ -1467,7 +1468,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2019-04-14 21:00:16.007097", "modified": "2019-04-25 17:10:09.399721",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "CRM", "module": "CRM",
"name": "Opportunity", "name": "Opportunity",
@@ -1515,11 +1516,11 @@
"quick_entry": 0, "quick_entry": 0,
"read_only": 0, "read_only": 0,
"read_only_onload": 0, "read_only_onload": 0,
"search_fields": "status,transaction_date,customer_lead,opportunity_type,territory,company", "search_fields": "status,transaction_date,party_name,opportunity_type,territory,company",
"show_name_in_global_search": 1, "show_name_in_global_search": 1,
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"timeline_field": "customer_lead", "timeline_field": "party_name",
"title_field": "title", "title_field": "title",
"track_changes": 0, "track_changes": 0,
"track_seen": 1, "track_seen": 1,

View File

@@ -17,7 +17,7 @@ sender_field = "contact_email"
class Opportunity(TransactionBase): class Opportunity(TransactionBase):
def after_insert(self): def after_insert(self):
if self.opportunity_from == "Lead": if self.opportunity_from == "Lead":
frappe.get_doc("Lead", self.customer_lead).set_status(update=True) frappe.get_doc("Lead", self.party_name).set_status(update=True)
def validate(self): def validate(self):
self._prev = frappe._dict({ self._prev = frappe._dict({
@@ -29,9 +29,6 @@ class Opportunity(TransactionBase):
self.make_new_lead_if_required() self.make_new_lead_if_required()
if not self.opportunity_from:
frappe.throw(_("Opportunity From field is mandatory"))
self.validate_item_details() self.validate_item_details()
self.validate_uom_is_integer("uom", "qty") self.validate_uom_is_integer("uom", "qty")
self.validate_lead_cust() self.validate_lead_cust()
@@ -45,7 +42,7 @@ class Opportunity(TransactionBase):
def make_new_lead_if_required(self): def make_new_lead_if_required(self):
"""Set lead against new opportunity""" """Set lead against new opportunity"""
if (not self.get("customer_lead")) and self.contact_email: if (not self.get("party_name")) and self.contact_email:
# check if customer is already created agains the self.contact_email # check if customer is already created agains the self.contact_email
customer = frappe.db.sql("""select customer = frappe.db.sql("""select
distinct `tabDynamic Link`.link_name as customer distinct `tabDynamic Link`.link_name as customer
@@ -61,7 +58,7 @@ class Opportunity(TransactionBase):
`tabDynamic Link`.link_doctype='Customer' `tabDynamic Link`.link_doctype='Customer'
""".format(self.contact_email), as_dict=True) """.format(self.contact_email), as_dict=True)
if customer and customer[0].customer: if customer and customer[0].customer:
self.customer_lead = customer[0].customer self.party_name = customer[0].customer
self.opportunity_from = "Customer" self.opportunity_from = "Customer"
return return
@@ -90,7 +87,7 @@ class Opportunity(TransactionBase):
lead_name = lead.name lead_name = lead.name
self.opportunity_from = "Lead" self.opportunity_from = "Lead"
self.customer_lead = lead_name self.party_name = lead_name
def declare_enquiry_lost(self,arg): def declare_enquiry_lost(self,arg):
if not self.has_active_quotation(): if not self.has_active_quotation():
@@ -137,10 +134,10 @@ class Opportunity(TransactionBase):
return True return True
def validate_cust_name(self): def validate_cust_name(self):
if self.customer_lead and self.opportunity_from == 'Customer': if self.party_name and self.opportunity_from == 'Customer':
self.customer_name = frappe.db.get_value("Customer", self.customer_lead, "customer_name") self.customer_name = frappe.db.get_value("Customer", self.party_name, "customer_name")
elif self.customer_lead and self.opportunity_from == 'Lead': elif self.party_name and self.opportunity_from == 'Lead':
lead_name, company_name = frappe.db.get_value("Lead", self.customer_lead, ["lead_name", "company_name"]) lead_name, company_name = frappe.db.get_value("Lead", self.party_name, ["lead_name", "company_name"])
self.customer_name = company_name or lead_name self.customer_name = company_name or lead_name
def on_update(self): def on_update(self):
@@ -153,16 +150,16 @@ class Opportunity(TransactionBase):
opts.description = "" opts.description = ""
opts.contact_date = self.contact_date opts.contact_date = self.contact_date
if self.customer_lead and self.opportunity_from == 'Customer': if self.party_name and self.opportunity_from == 'Customer':
if self.contact_person: if self.contact_person:
opts.description = 'Contact '+cstr(self.contact_person) opts.description = 'Contact '+cstr(self.contact_person)
else: else:
opts.description = 'Contact customer '+cstr(self.customer_lead) opts.description = 'Contact customer '+cstr(self.party_name)
elif self.customer_lead and self.opportunity_from == 'Lead': elif self.party_name and self.opportunity_from == 'Lead':
if self.contact_display: if self.contact_display:
opts.description = 'Contact '+cstr(self.contact_display) opts.description = 'Contact '+cstr(self.contact_display)
else: else:
opts.description = 'Contact lead '+cstr(self.customer_lead) opts.description = 'Contact lead '+cstr(self.party_name)
opts.subject = opts.description opts.subject = opts.description
opts.description += '. By : ' + cstr(self.contact_by) opts.description += '. By : ' + cstr(self.contact_by)
@@ -187,14 +184,6 @@ class Opportunity(TransactionBase):
for key in item_fields: for key in item_fields:
if not d.get(key): d.set(key, item.get(key)) if not d.get(key): d.set(key, item.get(key))
def validate_lead_cust(self):
if self.opportunity_from == 'Lead':
if not self.customer_lead:
frappe.throw(_("Lead must be set if Opportunity is made from Lead"))
elif self.opportunity_from == 'Customer':
if not self.customer_lead:
msgprint(_("Customer is mandatory if 'Opportunity From' is selected as Customer"), raise_exception=1)
@frappe.whitelist() @frappe.whitelist()
def get_item_details(item_code): def get_item_details(item_code):
@@ -216,8 +205,11 @@ def make_quotation(source_name, target_doc=None):
quotation = frappe.get_doc(target) quotation = frappe.get_doc(target)
company_currency = frappe.get_cached_value('Company', quotation.company, "default_currency") company_currency = frappe.get_cached_value('Company', quotation.company, "default_currency")
party_account_currency = get_party_account_currency("Customer", quotation.customer_lead,
quotation.company) if quotation.customer_lead else company_currency if quotation.quotation_to == 'Customer' and quotation.party_name:
party_account_currency = get_party_account_currency("Customer", quotation.party_name, quotation.company)
else:
party_account_currency = company_currency
quotation.currency = party_account_currency or company_currency quotation.currency = party_account_currency or company_currency

View File

@@ -37,13 +37,13 @@ class TestOpportunity(unittest.TestCase):
# new lead should be created against the new.opportunity@example.com # new lead should be created against the new.opportunity@example.com
opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) opp_doc = frappe.get_doc(args).insert(ignore_permissions=True)
self.assertTrue(opp_doc.customer_lead) self.assertTrue(opp_doc.party_name)
self.assertEqual(opp_doc.opportunity_from, "Lead") self.assertEqual(opp_doc.opportunity_from, "Lead")
self.assertEqual(frappe.db.get_value("Lead", opp_doc.customer_lead, "email_id"), self.assertEqual(frappe.db.get_value("Lead", opp_doc.party_name, "email_id"),
'new.opportunity@example.com') 'new.opportunity@example.com')
# create new customer and create new contact against 'new.opportunity@example.com' # create new customer and create new contact against 'new.opportunity@example.com'
customer = make_customer(opp_doc.customer_lead).insert(ignore_permissions=True) customer = make_customer(opp_doc.party_name).insert(ignore_permissions=True)
frappe.get_doc({ frappe.get_doc({
"doctype": "Contact", "doctype": "Contact",
"email_id": "new.opportunity@example.com", "email_id": "new.opportunity@example.com",
@@ -55,9 +55,9 @@ class TestOpportunity(unittest.TestCase):
}).insert(ignore_permissions=True) }).insert(ignore_permissions=True)
opp_doc = frappe.get_doc(args).insert(ignore_permissions=True) opp_doc = frappe.get_doc(args).insert(ignore_permissions=True)
self.assertTrue(opp_doc.customer_lead) self.assertTrue(opp_doc.party_name)
self.assertEqual(opp_doc.opportunity_from, "Customer") self.assertEqual(opp_doc.opportunity_from, "Customer")
self.assertEqual(opp_doc.customer_lead, customer.name) self.assertEqual(opp_doc.party_name, customer.name)
def make_opportunity(**args): def make_opportunity(**args):
args = frappe._dict(args) args = frappe._dict(args)
@@ -72,10 +72,10 @@ def make_opportunity(**args):
}) })
if opp_doc.opportunity_from == 'Customer': if opp_doc.opportunity_from == 'Customer':
opp_doc.customer_lead= args.customer or "_Test Customer" opp_doc.party_name= args.customer or "_Test Customer"
if opp_doc.opportunity_from == 'Lead': if opp_doc.opportunity_from == 'Lead':
opp_doc.customer_lead = args.lead or "_T-Lead-00001" opp_doc.party_name = args.lead or "_T-Lead-00001"
if args.with_items: if args.with_items:
opp_doc.append('items', { opp_doc.append('items', {

View File

@@ -4,7 +4,7 @@
"name": "_Test Opportunity 1", "name": "_Test Opportunity 1",
"opportunity_from": "Lead", "opportunity_from": "Lead",
"enquiry_type": "Sales", "enquiry_type": "Sales",
"customer_lead": "_T-Lead-00001", "party_name": "_T-Lead-00001",
"transaction_date": "2013-12-12", "transaction_date": "2013-12-12",
"items": [{ "items": [{
"item_name": "Test Item", "item_name": "Test Item",

View File

@@ -6,9 +6,9 @@ import frappe
def execute(): def execute():
frappe.reload_doctype("Quotation") frappe.reload_doctype("Quotation")
frappe.db.sql(""" UPDATE `tabQuotation` set customer_lead = lead WHERE quotation_to = 'Lead' """) frappe.db.sql(""" UPDATE `tabQuotation` set party_name = lead WHERE quotation_to = 'Lead' """)
frappe.db.sql(""" UPDATE `tabQuotation` set customer_lead = customer WHERE quotation_to = 'Customer' """) frappe.db.sql(""" UPDATE `tabQuotation` set party_name = customer WHERE quotation_to = 'Customer' """)
frappe.reload_doctype("Opportunity") frappe.reload_doctype("Opportunity")
frappe.db.sql(""" UPDATE `tabOpportunity` set customer_lead = lead WHERE opportunity_from = 'Lead' """) frappe.db.sql(""" UPDATE `tabOpportunity` set party_name = lead WHERE opportunity_from = 'Lead' """)
frappe.db.sql(""" UPDATE `tabOpportunity` set customer_lead = customer WHERE opportunity_from = 'Customer' """) frappe.db.sql(""" UPDATE `tabOpportunity` set party_name = customer WHERE opportunity_from = 'Customer' """)

View File

@@ -104,9 +104,6 @@ class Customer(TransactionBase):
if self.lead_name: if self.lead_name:
frappe.db.set_value('Lead', self.lead_name, 'status', 'Converted', update_modified=False) frappe.db.set_value('Lead', self.lead_name, 'status', 'Converted', update_modified=False)
for d in frappe.get_all('Opportunity', {'customer_lead': self.lead_name}):
frappe.db.set_value('Opportunity', d.name, 'customer_lead', self.name, update_modified=False)
def create_lead_address_contact(self): def create_lead_address_contact(self):
if self.lead_name: if self.lead_name:
# assign lead address to customer (if already not set) # assign lead address to customer (if already not set)

View File

@@ -7,8 +7,8 @@ def get_data():
'heatmap_message': _('This is based on transactions against this Customer. See timeline below for details'), 'heatmap_message': _('This is based on transactions against this Customer. See timeline below for details'),
'fieldname': 'customer', 'fieldname': 'customer',
'non_standard_fieldnames': { 'non_standard_fieldnames': {
'Quotation': 'customer_lead', 'Quotation': 'party_name',
'Opportunity': 'customer_lead' 'Opportunity': 'party_name'
}, },
'transactions': [ 'transactions': [
{ {

View File

@@ -108,15 +108,15 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
set_dynamic_field_label: function(){ set_dynamic_field_label: function(){
if (this.frm.doc.quotation_to == "Customer") if (this.frm.doc.quotation_to == "Customer")
{ {
this.frm.set_df_property("customer_lead", "label", "Customer"); this.frm.set_df_property("party_name", "label", "Customer");
this.frm.fields_dict.customer_lead.get_query = null; this.frm.fields_dict.party_name.get_query = null;
} }
if (this.frm.doc.quotation_to == "Lead") if (this.frm.doc.quotation_to == "Lead")
{ {
this.frm.set_df_property("customer_lead", "label", "Lead"); this.frm.set_df_property("party_name", "label", "Lead");
this.frm.fields_dict.customer_lead.get_query = function() { this.frm.fields_dict.party_name.get_query = function() {
return{ query: "erpnext.controllers.queries.lead_query" } return{ query: "erpnext.controllers.queries.lead_query" }
} }
} }
@@ -126,7 +126,7 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
var me = this; var me = this;
// to overwrite the customer_filter trigger from queries.js // to overwrite the customer_filter trigger from queries.js
this.frm.toggle_reqd("customer_lead", this.frm.doc.quotation_to); this.frm.toggle_reqd("party_name", this.frm.doc.quotation_to);
this.frm.set_query('customer_address', erpnext.queries.address_query); this.frm.set_query('customer_address', erpnext.queries.address_query);
this.frm.set_query('shipping_address_name', erpnext.queries.address_query); this.frm.set_query('shipping_address_name', erpnext.queries.address_query);
}, },

View File

@@ -161,7 +161,7 @@
"columns": 0, "columns": 0,
"depends_on": "", "depends_on": "",
"fetch_if_empty": 0, "fetch_if_empty": 0,
"fieldname": "customer_lead", "fieldname": "party_name",
"fieldtype": "Dynamic Link", "fieldtype": "Dynamic Link",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
@@ -3224,7 +3224,7 @@
"istable": 0, "istable": 0,
"max_attachments": 1, "max_attachments": 1,
"menu_index": 0, "menu_index": 0,
"modified": "2019-04-02 10:18:58.506125", "modified": "2019-04-25 15:26:21.983298",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Selling", "module": "Selling",
"name": "Quotation", "name": "Quotation",
@@ -3390,11 +3390,11 @@
"quick_entry": 0, "quick_entry": 0,
"read_only": 0, "read_only": 0,
"read_only_onload": 1, "read_only_onload": 1,
"search_fields": "status,transaction_date,customer_lead,order_type", "search_fields": "status,transaction_date,party_name,order_type",
"show_name_in_global_search": 1, "show_name_in_global_search": 1,
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"timeline_field": "customer_lead", "timeline_field": "party_name",
"title_field": "title", "title_field": "title",
"track_changes": 0, "track_changes": 0,
"track_seen": 0, "track_seen": 0,

View File

@@ -43,8 +43,8 @@ class Quotation(SellingController):
super(Quotation, self).validate_order_type() super(Quotation, self).validate_order_type()
def update_lead(self): def update_lead(self):
if self.quotation_to == "Lead" and self.customer_lead: if self.quotation_to == "Lead" and self.party_name:
frappe.get_doc("Lead", self.customer_lead).set_status(update=True) frappe.get_doc("Lead", self.party_name).set_status(update=True)
def update_opportunity(self): def update_opportunity(self):
for opportunity in list(set([d.prevdoc_docname for d in self.get("items")])): for opportunity in list(set([d.prevdoc_docname for d in self.get("items")])):
@@ -204,7 +204,7 @@ def _make_sales_invoice(source_name, target_doc=None, ignore_permissions=False):
return doclist return doclist
def _make_customer(source_name, ignore_permissions=False): def _make_customer(source_name, ignore_permissions=False):
quotation = frappe.db.get_value("Quotation", source_name, ["order_type", "customer_lead", "customer_name"]) quotation = frappe.db.get_value("Quotation", source_name, ["order_type", "party_name", "customer_name"])
if quotation and quotation[1] and not quotation[2]: if quotation and quotation[1] and not quotation[2]:
lead_name = quotation[1] lead_name = quotation[1]
customer_name = frappe.db.get_value("Customer", {"lead_name": lead_name}, customer_name = frappe.db.get_value("Customer", {"lead_name": lead_name},

View File

@@ -203,15 +203,15 @@ class TestQuotation(unittest.TestCase):
test_records = frappe.get_test_records('Quotation') test_records = frappe.get_test_records('Quotation')
def get_quotation_dict(customer_lead=None, item_code=None): def get_quotation_dict(party_name=None, item_code=None):
if not customer_lead: if not party_name:
customer_lead = '_Test Customer' party_name = '_Test Customer'
if not item_code: if not item_code:
item_code = '_Test Item' item_code = '_Test Item'
return { return {
'doctype': 'Quotation', 'doctype': 'Quotation',
'customer_lead': customer_lead, 'party_name': party_name,
'items': [ 'items': [
{ {
'item_code': item_code, 'item_code': item_code,
@@ -229,7 +229,7 @@ def make_quotation(**args):
qo.transaction_date = args.transaction_date qo.transaction_date = args.transaction_date
qo.company = args.company or "_Test Company" qo.company = args.company or "_Test Company"
qo.customer_lead = args.customer_lead or "_Test Customer" qo.party_name = args.party_name or "_Test Customer"
qo.currency = args.currency or "INR" qo.currency = args.currency or "INR"
if args.selling_price_list: if args.selling_price_list:
qo.selling_price_list = args.selling_price_list qo.selling_price_list = args.selling_price_list

View File

@@ -3,7 +3,7 @@
"company": "_Test Company", "company": "_Test Company",
"conversion_rate": 1.0, "conversion_rate": 1.0,
"currency": "INR", "currency": "INR",
"customer_lead": "_Test Customer", "party_name": "_Test Customer",
"customer_group": "_Test Customer Group", "customer_group": "_Test Customer Group",
"customer_name": "_Test Customer", "customer_name": "_Test Customer",
"doctype": "Quotation", "doctype": "Quotation",

View File

@@ -196,7 +196,7 @@ def _get_cart_quotation(party=None):
party = get_party() party = get_party()
quotation = frappe.get_all("Quotation", fields=["name"], filters= quotation = frappe.get_all("Quotation", fields=["name"], filters=
{"customer_lead": party.name, "order_type": "Shopping Cart", "docstatus": 0}, {"party_name": party.name, "order_type": "Shopping Cart", "docstatus": 0},
order_by="modified desc", limit_page_length=1) order_by="modified desc", limit_page_length=1)
if quotation: if quotation:
@@ -211,7 +211,7 @@ def _get_cart_quotation(party=None):
"status": "Draft", "status": "Draft",
"docstatus": 0, "docstatus": 0,
"__islocal": 1, "__islocal": 1,
"customer_lead": party.name "party_name": party.name
}) })
qdoc.contact_person = frappe.db.get_value("Contact", {"email_id": frappe.session.user}) qdoc.contact_person = frappe.db.get_value("Contact", {"email_id": frappe.session.user})
@@ -291,9 +291,9 @@ def _set_price_list(quotation, cart_settings):
# check if customer price list exists # check if customer price list exists
selling_price_list = None selling_price_list = None
if quotation.customer_lead: if quotation.party_name:
from erpnext.accounts.party import get_default_price_list from erpnext.accounts.party import get_default_price_list
selling_price_list = get_default_price_list(frappe.get_doc("Customer", quotation.customer_lead)) selling_price_list = get_default_price_list(frappe.get_doc("Customer", quotation.party_name))
# else check for territory based price list # else check for territory based price list
if not selling_price_list: if not selling_price_list:
@@ -305,9 +305,9 @@ def set_taxes(quotation, cart_settings):
"""set taxes based on billing territory""" """set taxes based on billing territory"""
from erpnext.accounts.party import set_taxes from erpnext.accounts.party import set_taxes
customer_group = frappe.db.get_value("Customer", quotation.customer_lead, "customer_group") customer_group = frappe.db.get_value("Customer", quotation.party_name, "customer_group")
quotation.taxes_and_charges = set_taxes(quotation.customer_lead, "Customer", \ quotation.taxes_and_charges = set_taxes(quotation.party_name, "Customer", \
quotation.transaction_date, quotation.company, customer_group, None, \ quotation.transaction_date, quotation.company, customer_group, None, \
quotation.customer_address, quotation.shipping_address_name, 1) quotation.customer_address, quotation.shipping_address_name, 1)
# #

View File

@@ -43,7 +43,7 @@ class TestShoppingCart(unittest.TestCase):
# test if quotation with customer is fetched # test if quotation with customer is fetched
quotation = _get_cart_quotation() quotation = _get_cart_quotation()
self.assertEqual(quotation.quotation_to, "Customer") self.assertEqual(quotation.quotation_to, "Customer")
self.assertEqual(quotation.customer_lead, "_Test Customer") self.assertEqual(quotation.party_name, "_Test Customer")
self.assertEqual(quotation.contact_email, frappe.session.user) self.assertEqual(quotation.contact_email, frappe.session.user)
return quotation return quotation
@@ -105,7 +105,7 @@ class TestShoppingCart(unittest.TestCase):
from erpnext.accounts.party import set_taxes from erpnext.accounts.party import set_taxes
tax_rule_master = set_taxes(quotation.customer_lead, "Customer", \ tax_rule_master = set_taxes(quotation.party_name, "Customer", \
quotation.transaction_date, quotation.company, None, None, \ quotation.transaction_date, quotation.company, None, None, \
quotation.customer_address, quotation.shipping_address_name, 1) quotation.customer_address, quotation.shipping_address_name, 1)
self.assertEqual(quotation.taxes_and_charges, tax_rule_master) self.assertEqual(quotation.taxes_and_charges, tax_rule_master)
@@ -120,7 +120,7 @@ class TestShoppingCart(unittest.TestCase):
"doctype": "Quotation", "doctype": "Quotation",
"quotation_to": "Customer", "quotation_to": "Customer",
"order_type": "Shopping Cart", "order_type": "Shopping Cart",
"customer_lead": get_party(frappe.session.user).name, "party_name": get_party(frappe.session.user).name,
"docstatus": 0, "docstatus": 0,
"contact_email": frappe.session.user, "contact_email": frappe.session.user,
"selling_price_list": "_Test Price List Rest of the World", "selling_price_list": "_Test Price List Rest of the World",