[webshop] Place Order - submits Quotation, creates Customer if required, creates and submits Sales Order

This commit is contained in:
Anand Doshi
2013-07-10 20:49:44 +05:30
parent afad0efca3
commit 2ac0a83bd8
19 changed files with 382 additions and 173 deletions

View File

@@ -132,8 +132,15 @@ class DocType(TransactionBase):
self.doc.name, raise_exception=1)
def delete_customer_address(self):
for rec in sql("select * from `tabAddress` where customer=%s", (self.doc.name,), as_dict=1):
sql("delete from `tabAddress` where name=%s", (rec['name']))
addresses = webnotes.conn.sql("""select name, lead from `tabAddress`
where customer=%s""", (self.doc.name,))
for name, lead in addresses:
if lead:
webnotes.conn.sql("""update `tabAddress` set customer=null, customer_name=null
where name=%s""", name)
else:
webnotes.conn.sql("""delete from `tabAddress` where name=%s""", name)
def delete_customer_contact(self):
for rec in sql("select * from `tabContact` where customer=%s", (self.doc.name,), as_dict=1):

View File

@@ -99,6 +99,9 @@ class DocType(SellingController):
@webnotes.whitelist()
def make_customer(source_name, target_doclist=None):
_make_customer(source_name, target_doclist)
def _make_customer(source_name, target_doclist=None, ignore_permissions=False):
from webnotes.model.mapper import get_mapped_doclist
def set_missing_values(source, target):
@@ -120,7 +123,7 @@ def make_customer(source_name, target_doclist=None):
"contact_no": "phone_1",
"fax": "fax_1"
}
}}, target_doclist, set_missing_values)
}}, target_doclist, set_missing_values, ignore_permissions=ignore_permissions)
return [d.fields for d in doclist]

View File

@@ -230,8 +230,18 @@ class DocType(SellingController):
@webnotes.whitelist()
def make_sales_order(source_name, target_doclist=None):
return _make_sales_order(source_name, target_doclist)
def _make_sales_order(source_name, target_doclist=None, ignore_permissions=False):
from webnotes.model.mapper import get_mapped_doclist
customer = _make_customer(source_name, ignore_permissions)
def set_missing_values(source, target):
if customer:
target[0].customer = customer.doc.name
target[0].customer_name = customer.doc.customer_name
doclist = get_mapped_doclist("Quotation", source_name, {
"Quotation": {
"doctype": "Sales Order",
@@ -255,8 +265,34 @@ def make_sales_order(source_name, target_doclist=None):
"Sales Team": {
"doctype": "Sales Team",
}
}, target_doclist)
}, target_doclist, set_missing_values, ignore_permissions=ignore_permissions)
# postprocess: fetch shipping address, set missing values
return [d.fields for d in doclist]
return [d.fields for d in doclist]
def _make_customer(source_name, ignore_permissions=False):
quotation = webnotes.conn.get_value("Quotation", source_name, ["lead", "order_type"])
if quotation and quotation[0]:
lead_name = quotation[0]
customer_name = webnotes.conn.get_value("Customer", {"lead_name": lead_name})
if not customer_name:
from selling.doctype.lead.lead import _make_customer
customer_doclist = _make_customer(lead_name, ignore_permissions=ignore_permissions)
customer = webnotes.bean(customer_doclist)
customer.ignore_permissions = ignore_permissions
if quotation[1] == "Shopping Cart":
customer.doc.customer_group = webnotes.conn.get_value("Shopping Cart Settings", None,
"default_customer_group")
try:
customer.insert()
return customer
except NameError, e:
if webnotes.defaults.get_global_default('cust_master_name') == "Customer Name":
customer.run_method("autoname")
customer.doc.name += "-" + lead_name
customer.insert()
return customer
else:
raise e

View File

@@ -319,7 +319,7 @@ def get_orders():
# find customer id
customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user},
"customer")
if customer:
orders = webnotes.conn.sql("""select
name, creation, currency from `tabSales Order`
@@ -334,6 +334,7 @@ def get_orders():
from `tabSales Order Item`
where parent=%s
order by idx""", order.name, as_dict=1)
return orders
else:
return []