use open_mapped_doc instead of create_new_doc
This commit is contained in:
parent
797481f9d5
commit
5150c69ee6
@ -5,13 +5,13 @@ frappe.ui.form.on("Customer", {
|
|||||||
setup: function(frm) {
|
setup: function(frm) {
|
||||||
|
|
||||||
frm.make_methods = {
|
frm.make_methods = {
|
||||||
'Quotation': () => erpnext.utils.create_new_doc('Quotation', {
|
'Quotation': () => frappe.model.open_mapped_doc({
|
||||||
'quotation_to': frm.doc.doctype,
|
method: "erpnext.selling.doctype.customer.customer.make_quotation",
|
||||||
'party_name': frm.doc.name
|
frm: cur_frm
|
||||||
}),
|
}),
|
||||||
'Opportunity': () => erpnext.utils.create_new_doc('Opportunity', {
|
'Opportunity': () => frappe.model.open_mapped_doc({
|
||||||
'opportunity_from': frm.doc.doctype,
|
method: "erpnext.selling.doctype.customer.customer.make_opportunity",
|
||||||
'party_name': frm.doc.name
|
frm: cur_frm
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ from erpnext.utilities.transaction_base import TransactionBase
|
|||||||
from erpnext.accounts.party import validate_party_accounts, get_dashboard_info, get_timeline_data # keep this
|
from erpnext.accounts.party import validate_party_accounts, get_dashboard_info, get_timeline_data # keep this
|
||||||
from frappe.contacts.address_and_contact import load_address_and_contact, delete_contact_and_address
|
from frappe.contacts.address_and_contact import load_address_and_contact, delete_contact_and_address
|
||||||
from frappe.model.rename_doc import update_linked_doctypes
|
from frappe.model.rename_doc import update_linked_doctypes
|
||||||
|
from frappe.model.mapper import get_mapped_doc
|
||||||
|
|
||||||
class Customer(TransactionBase):
|
class Customer(TransactionBase):
|
||||||
def get_feed(self):
|
def get_feed(self):
|
||||||
@ -238,6 +239,64 @@ def create_contact(contact, party_type, party, email):
|
|||||||
contact.append('links', dict(link_doctype=party_type, link_name=party))
|
contact.append('links', dict(link_doctype=party_type, link_name=party))
|
||||||
contact.insert()
|
contact.insert()
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def make_quotation(source_name, target_doc=None):
|
||||||
|
|
||||||
|
def set_missing_values(source, target):
|
||||||
|
_set_missing_values(source,target)
|
||||||
|
|
||||||
|
target_doc = get_mapped_doc("Customer", source_name,
|
||||||
|
{"Customer": {
|
||||||
|
"doctype": "Quotation",
|
||||||
|
"field_map": {
|
||||||
|
"name":"party_name"
|
||||||
|
}
|
||||||
|
}}, target_doc, set_missing_values)
|
||||||
|
|
||||||
|
target_doc.quotation_to = "Customer"
|
||||||
|
target_doc.run_method("set_missing_values")
|
||||||
|
target_doc.run_method("set_other_charges")
|
||||||
|
target_doc.run_method("calculate_taxes_and_totals")
|
||||||
|
|
||||||
|
target_doc.selling_price_list = frappe.get_doc("Customer",source_name).default_price_list
|
||||||
|
return target_doc
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def make_opportunity(source_name, target_doc=None):
|
||||||
|
def set_missing_values(source, target):
|
||||||
|
_set_missing_values(source,target)
|
||||||
|
|
||||||
|
target_doc = get_mapped_doc("Customer", source_name,
|
||||||
|
{"Customer": {
|
||||||
|
"doctype": "Opportunity",
|
||||||
|
"field_map": {
|
||||||
|
"name": "party_name",
|
||||||
|
"doctype": "opportunity_from",
|
||||||
|
}
|
||||||
|
}}, target_doc, set_missing_values
|
||||||
|
)
|
||||||
|
|
||||||
|
return target_doc
|
||||||
|
|
||||||
|
def _set_missing_values(source, target):
|
||||||
|
address = frappe.get_all('Dynamic Link', {
|
||||||
|
'link_doctype': source.doctype,
|
||||||
|
'link_name': source.name,
|
||||||
|
'parenttype': 'Address',
|
||||||
|
}, ['parent'], limit=1)
|
||||||
|
|
||||||
|
contact = frappe.get_all('Dynamic Link', {
|
||||||
|
'link_doctype': source.doctype,
|
||||||
|
'link_name': source.name,
|
||||||
|
'parenttype': 'Contact',
|
||||||
|
}, ['parent'], limit=1)
|
||||||
|
|
||||||
|
if address:
|
||||||
|
target.customer_address = address[0].parent
|
||||||
|
|
||||||
|
if contact:
|
||||||
|
target.contact_person = contact[0].parent
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_loyalty_programs(doc):
|
def get_loyalty_programs(doc):
|
||||||
''' returns applicable loyalty programs for a customer '''
|
''' returns applicable loyalty programs for a customer '''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user