diff --git a/config.json b/config.json
index 46cd8c98f22..5f9ac5e8080 100644
--- a/config.json
+++ b/config.json
@@ -120,6 +120,14 @@
"tickets": {
"template": "app/website/templates/pages/tickets"
},
+ "address": {
+ "no_cache": true,
+ "template": "app/website/templates/pages/address",
+ "args_method": "utilities.doctype.address.address.get_website_args"
+ },
+ "addresses": {
+ "template": "app/website/templates/pages/addresses"
+ },
"writers": {
"template": "app/website/templates/pages/writers",
"args_method": "website.helpers.blog.get_writers_args"
diff --git a/public/js/website_utils.js b/public/js/website_utils.js
index 098f8da1887..59614c54a61 100644
--- a/public/js/website_utils.js
+++ b/public/js/website_utils.js
@@ -10,7 +10,7 @@ erpnext.send_message = function(opts) {
method: "website.helpers.contact.send_message",
args: opts,
callback: opts.callback
- })
+ });
}
wn.call = function(opts) {
diff --git a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index 3492931451a..b2a10853ac8 100644
--- a/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -121,8 +121,6 @@ class DocType(DocListController):
self.doc.posting_time = '00:00'
def on_doctype_update(self):
- webnotes.msgprint(webnotes.conn.sql("""show index from `tabStock Ledger Entry`
- where Key_name="posting_sort_index" """))
if not webnotes.conn.sql("""show index from `tabStock Ledger Entry`
where Key_name="posting_sort_index" """):
webnotes.conn.commit()
diff --git a/utilities/doctype/address/address.py b/utilities/doctype/address/address.py
index c475da12b55..90ada5fece2 100644
--- a/utilities/doctype/address/address.py
+++ b/utilities/doctype/address/address.py
@@ -18,7 +18,7 @@ from __future__ import unicode_literals
import webnotes
from webnotes import msgprint
-from webnotes.utils import cstr
+from webnotes.utils import cstr, cint
class DocType:
def __init__(self, doc, doclist=[]):
@@ -63,4 +63,26 @@ class DocType:
if self.doc.fields.get(fieldname):
webnotes.conn.sql("""update `tabAddress` set `%s`=0 where `%s`=%s and name!=%s""" %
(is_address_type, fieldname, "%s", "%s"), (self.doc.fields[fieldname], self.doc.name))
- break
\ No newline at end of file
+ break
+
+def get_website_args():
+ def _get_fields(fieldnames):
+ return [webnotes._dict(zip(["label", "fieldname", "fieldtype", "options"],
+ [df.label, df.fieldname, df.fieldtype, df.options]))
+ for df in webnotes.get_doctype("Address", processed=True).get({"fieldname": ["in", fieldnames]})]
+
+ bean = None
+ if webnotes.form_dict.name:
+ bean = webnotes.bean("Address", webnotes.form_dict.name)
+
+ return {
+ "doc": bean.doc if bean else None,
+ "meta": webnotes._dict({
+ "left_fields": _get_fields(["address_title", "address_type", "address_line1", "address_line2",
+ "city", "state", "pincode", "country"]),
+ "right_fields": _get_fields(["email_id", "phone", "fax", "is_primary_address",
+ "is_shipping_address"])
+ }),
+ "cint": cint
+ }
+
\ No newline at end of file
diff --git a/utilities/doctype/address/address.txt b/utilities/doctype/address/address.txt
index ed39c759c51..1b54abe7f75 100644
--- a/utilities/doctype/address/address.txt
+++ b/utilities/doctype/address/address.txt
@@ -2,7 +2,7 @@
{
"creation": "2013-01-10 16:34:32",
"docstatus": 0,
- "modified": "2013-06-28 17:06:32",
+ "modified": "2013-07-01 17:24:17",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -40,10 +40,12 @@
"name": "Address"
},
{
+ "description": "Name of person or organization that this address belongs to.",
"doctype": "DocField",
- "fieldname": "address_details",
- "fieldtype": "Section Break",
- "label": "Address Details"
+ "fieldname": "address_title",
+ "fieldtype": "Data",
+ "label": "Address Title",
+ "reqd": 1
},
{
"doctype": "DocField",
@@ -53,26 +55,18 @@
"options": "Billing\nShipping\nOffice\nPersonal\nPlant\nPostal\nShop\nSubsidiary\nWarehouse\nOther",
"reqd": 1
},
- {
- "description": "Name of person or organization that this address belongs to.",
- "doctype": "DocField",
- "fieldname": "address_title",
- "fieldtype": "Data",
- "label": "Address Title",
- "reqd": 1
- },
{
"doctype": "DocField",
"fieldname": "address_line1",
"fieldtype": "Data",
- "label": "Address Line1",
+ "label": "Address Line 1",
"reqd": 1
},
{
"doctype": "DocField",
"fieldname": "address_line2",
"fieldtype": "Data",
- "label": "Address Line2"
+ "label": "Address Line 2"
},
{
"doctype": "DocField",
@@ -84,6 +78,15 @@
"reqd": 1,
"search_index": 1
},
+ {
+ "doctype": "DocField",
+ "fieldname": "state",
+ "fieldtype": "Data",
+ "in_filter": 1,
+ "label": "State",
+ "options": "Suggest",
+ "search_index": 0
+ },
{
"doctype": "DocField",
"fieldname": "pincode",
@@ -103,15 +106,6 @@
"reqd": 1,
"search_index": 1
},
- {
- "doctype": "DocField",
- "fieldname": "state",
- "fieldtype": "Data",
- "in_filter": 1,
- "label": "State",
- "options": "Suggest",
- "search_index": 0
- },
{
"doctype": "DocField",
"fieldname": "column_break0",
@@ -119,6 +113,12 @@
"print_hide": 0,
"width": "50%"
},
+ {
+ "doctype": "DocField",
+ "fieldname": "email_id",
+ "fieldtype": "Data",
+ "label": "Email Id"
+ },
{
"doctype": "DocField",
"fieldname": "phone",
@@ -126,12 +126,6 @@
"label": "Phone",
"reqd": 1
},
- {
- "doctype": "DocField",
- "fieldname": "email_id",
- "fieldtype": "Data",
- "label": "Email Id"
- },
{
"doctype": "DocField",
"fieldname": "fax",
@@ -181,7 +175,7 @@
"read_only": 1
},
{
- "depends_on": "eval:!doc.customer && !doc.sales_partner",
+ "depends_on": "eval:!doc.customer && !doc.sales_partner && !doc.lead",
"doctype": "DocField",
"fieldname": "supplier",
"fieldtype": "Link",
@@ -189,7 +183,7 @@
"options": "Supplier"
},
{
- "depends_on": "eval:!doc.customer && !doc.sales_partner",
+ "depends_on": "eval:!doc.customer && !doc.sales_partner && !doc.lead",
"doctype": "DocField",
"fieldname": "supplier_name",
"fieldtype": "Data",
@@ -200,7 +194,7 @@
"search_index": 0
},
{
- "depends_on": "eval:!doc.customer && !doc.supplier",
+ "depends_on": "eval:!doc.customer && !doc.supplier && !doc.lead",
"doctype": "DocField",
"fieldname": "sales_partner",
"fieldtype": "Link",
diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py
index 2def0ea05f6..ab53575aee1 100644
--- a/utilities/transaction_base.py
+++ b/utilities/transaction_base.py
@@ -312,6 +312,20 @@ class TransactionBase(StatusUpdater):
})
webnotes.bean(event_doclist).insert()
+
+
+def get_address_display(address_dict):
+ meta = webnotes.get_doctype("Address")
+ address_sequence = (("", "address_line1"), ("\n", "address_line2"), ("\n", "city"),
+ ("\n", "state"), ("\n" + meta.get_label("pincode") + ": ", "pincode"), ("\n", "country"),
+ ("\n" + meta.get_label("phone") + ": ", "phone"), ("\n" + meta.get_label("fax") + ": ", "fax"))
+
+ address_display = ""
+ for separator, fieldname in address_sequence:
+ if address_dict.get(fieldname):
+ address_display += separator + address_dict.get(fieldname)
+
+ return address_display
def validate_conversion_rate(currency, conversion_rate, conversion_rate_label, company):
"""common validation for currency and price list currency"""
diff --git a/website/css/website.css b/website/css/website.css
index 737d3d0f4ee..34ff983b0b8 100644
--- a/website/css/website.css
+++ b/website/css/website.css
@@ -126,4 +126,8 @@ a {
.hidden-sm-inline {
display: inline;
}
+}
+
+.accordion-heading, .accordion-inner {
+ padding-left: 10px;
}
\ No newline at end of file
diff --git a/website/helpers/cart.py b/website/helpers/cart.py
index a24afb57a97..bc99e7bd4b6 100644
--- a/website/helpers/cart.py
+++ b/website/helpers/cart.py
@@ -8,6 +8,19 @@ from webnotes.utils import cint, get_fullname, fmt_money
class WebsitePriceListMissingError(webnotes.ValidationError): pass
+@webnotes.whitelist()
+def get_cart_quotation(doclist=None):
+ party = get_lead_or_customer()
+
+ if not doclist:
+ doclist = _get_cart_quotation(party).doclist
+
+ return {
+ "doclist": decorate_quotation_doclist(doclist),
+ "addresses": [{"name": address.name, "display": address.display}
+ for address in get_address_docs(party)]
+ }
+
@webnotes.whitelist()
def update_cart(item_code, qty, with_doclist=0):
quotation = _get_cart_quotation()
@@ -31,9 +44,79 @@ def update_cart(item_code, qty, with_doclist=0):
quotation.save()
if with_doclist:
- return decorate_quotation_doclist(quotation.doclist)
+ return get_cart_quotation(quotation.doclist)
else:
return quotation.doc.name
+
+@webnotes.whitelist()
+def update_cart_address(address_fieldname, address_name):
+ from utilities.transaction_base import get_address_display
+
+ quotation = _get_cart_quotation()
+ address_display = get_address_display(webnotes.doc("Address", address_name).fields)
+
+ if address_fieldname == "shipping_address_name":
+ quotation.doc.shipping_address_name = address_name
+ quotation.doc.shipping_address = address_display
+
+ if not quotation.doc.customer_address:
+ address_fieldname == "customer_address"
+
+ if address_fieldname == "customer_address":
+ quotation.doc.customer_address = address_name
+ quotation.doc.address_display = address_display
+
+
+ quotation.ignore_permissions = True
+ quotation.save()
+
+ return get_cart_quotation(quotation.doclist)
+
+@webnotes.whitelist()
+def get_addresses():
+ return [d.fields for d in get_address_docs()]
+
+@webnotes.whitelist()
+def save_address(fields, address_fieldname=None):
+ party = get_lead_or_customer()
+ fields = webnotes.load_json(fields)
+
+ if fields.get("name"):
+ bean = webnotes.bean("Address", fields.get("name"))
+ else:
+ bean = webnotes.bean({"doctype": "Address", "__islocal": 1})
+
+ bean.doc.fields.update(fields)
+
+ party_fieldname = party.doctype.lower()
+ bean.doc.fields.update({
+ party_fieldname: party.name,
+ (party_fieldname + "_name"): party.fields[party_fieldname + "_name"]
+ })
+ bean.ignore_permissions = True
+ bean.save()
+
+ if address_fieldname:
+ update_cart_address(address_fieldname, bean.doc.name)
+
+ return bean.doc.name
+
+def get_address_docs(party=None):
+ from webnotes.model.doclist import objectify
+ from utilities.transaction_base import get_address_display
+
+ if not party:
+ party = get_lead_or_customer()
+
+ address_docs = objectify(webnotes.conn.sql("""select * from `tabAddress`
+ where `%s`=%s order by name""" % (party.doctype.lower(), "%s"), party.name,
+ as_dict=True, update={"doctype": "Address"}))
+
+ for address in address_docs:
+ address.display = get_address_display(address.fields)
+ address.display = (address.display).replace("\n", "
\n")
+
+ return address_docs
def get_lead_or_customer():
customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user}, "customer")
@@ -56,12 +139,6 @@ def get_lead_or_customer():
lead_bean.insert()
return lead_bean.doc
-
-
-@webnotes.whitelist()
-def get_cart_quotation():
- doclist = _get_cart_quotation(get_lead_or_customer()).doclist
- return decorate_quotation_doclist(doclist)
def decorate_quotation_doclist(doclist):
for d in doclist:
diff --git a/website/templates/js/cart.js b/website/templates/js/cart.js
index 3e6a344c1c1..db6c5714ec3 100644
--- a/website/templates/js/cart.js
+++ b/website/templates/js/cart.js
@@ -30,6 +30,8 @@ $(document).ready(function() {
if(r.exc) {
if(r.exc.indexOf("WebsitePriceListMissingError")!==-1) {
wn.cart.show_error("Oops!", "Price List not configured.");
+ } else if(r["403"]) {
+ wn.cart.show_error("Hey!", "You need to be logged in to view your cart.");
} else {
wn.cart.show_error("Oops!", "Something went wrong.");
}
@@ -66,114 +68,145 @@ $.extend(wn.cart, {
},
});
});
+
+ $("#cart-add-shipping-address").on("click", function() {
+ window.location.href = "address?address_fieldname=shipping_address_name";
+ });
+
+ $("#cart-add-billing-address").on("click", function() {
+ window.location.href = "address?address_fieldname=customer_address";
+ });
},
- render: function(doclist) {
- var $cart_wrapper = $("#cart-items").empty();
+ render: function(out) {
+ var doclist = out.doclist;
+ var addresses = out.addresses;
+
+ var $cart_items = $("#cart-items").empty();
+ var $cart_taxes = $("#cart-taxes").empty();
+ var $cart_billing_address = $("#cart-billing-address").empty();
+ var $cart_shipping_address = $("#cart-shipping-address").empty();
- if($.map(doclist, function(d) { return d.item_code || null;}).length===0) {
+ var no_items = $.map(doclist, function(d) { return d.item_code || null;}).length===0;
+ if(no_items) {
wn.cart.show_error("Empty :-(", "Go ahead and add something to your cart.");
+ $("#cart-addresses").toggle(false);
return;
}
$.each(doclist, function(i, doc) {
if(doc.doctype === "Quotation Item") {
- doc.image_html = doc.image ?
- '
%(web_short_description)s
\ -at %(formatted_rate)s
\ - = %(formatted_amount)s\ -at ' + item.price + '
') : ""; - - $(repl('%(description)s
\ -No Items added to cart.
').appendTo($cart_wrapper); + wn.cart.render_address($cart_shipping_address, addresses, doclist[0].shipping_address_name); + wn.cart.render_address($cart_billing_address, addresses, doclist[0].customer_address); } }, - // bind_events: function() { - // // on change of qty - // $(".cart-input-qty").on("change", function on_change_of_qty() { - // wn.cart.set_value_in_cart($(this).attr("item_code"), "qty", $(this).val()); - // }); - // - // // shopping cart button - // $(".checkout-btn").on("click", function() { - // console.log("checkout!"); - // console.log(wn.cart.get_cart()); - // - // var user_is_logged_in = getCookie("full_name"); - // if(user_is_logged_in) { - // wn.call({ - // method: "website.helpers.cart.checkout", - // args: {cart: wn.cart.get_cart()}, - // btn: this, - // callback: function(r) { - // console.log(r); - // } - // }); - // } else { - // window.location.href = "login?from=cart"; - // } - // }); - // } + render_item_row: function($cart_items, doc) { + doc.image_html = doc.image ? + '' : + '{% include "app/website/templates/html/product_missing_image.html" %}'; + + if(!doc.web_short_description) doc.web_short_description = doc.description; + + $(repl('%(web_short_description)s
\ +at %(formatted_rate)s
\ + = %(formatted_amount)s\ +