Merge branch 'website-wip' of github.com:webnotes/erpnext into website-wip

This commit is contained in:
Anand Doshi
2013-09-10 12:54:10 +05:30
169 changed files with 182 additions and 4434 deletions

View File

@@ -6,7 +6,7 @@
if webnotes.form_dict.lead_email and validate_email_add(webnotes.form_dict.lead_email):
import requests
response = requests.post(conf.demo_notify_url, data={
"cmd":"website.helpers.contact.send_message",
"cmd":"selling.utils.contact.send_message",
"subject":"Logged into Demo",
"sender": webnotes.form_dict.lead_email,
"message": "via demo.erpnext.com"

View File

@@ -0,0 +1,115 @@
{% extends "app/website/templates/html/page.html" %}
{% set title=doc and doc.name or "New Address" %}
{% set docname=(doc and doc.name or "") %}
{% macro render_fields(docfields) -%}
{% for df in docfields -%}
{% if df.fieldtype in ["Data", "Link"] -%}
<fieldset>
<label>{{ df.label }}</label>
<input class="form-control" type="text" placeholder="Type {{ df.label }}"
data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}"
{% if doc and doc.fields.get(df.fieldname) -%} value="{{ doc.fields[df.fieldname] }}" {%- endif %}>
</fieldset>
{% elif df.fieldtype == "Check" -%}
<fieldset class="checkbox">
<label><input type="checkbox" data-fieldname="{{ df.fieldname }}"
data-fieldtype="{{ df.fieldtype }}"
{% if doc and cint(doc.fields.get(df.fieldname)) -%} checked="checked" {%- endif %}>
{{ df.label }}</label>
</fieldset>
{% elif df.fieldtype == "Select" -%}
<fieldset>
<label>{{ df.label }}</label>
<select class="form-control" data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}">
{% for value in df.options.split("\n") -%}
{% if doc and doc.fields.get(df.fieldname) == value -%}
<option selected="selected">{{ value }}</option>
{% else -%}
<option>{{ value }}</option>
{%- endif %}
{%- endfor %}
</select>
</fieldset>
{%- endif %}
{%- endfor %}
{%- endmacro %}
{% block content %}
<div class="col-md-12">
<ul class="breadcrumb">
<li><a href="index">Home</a></li>
<li><a href="account">My Account</a></li>
<li><a href="addresses">My Addresses</a></li>
<li class="active"><i class="icon-map-marker icon-fixed-width"></i> {{ title }}</li>
</ul>
<h3><i class="icon-map-marker icon-fixed-width"></i> {{ title }}</h3>
<button type="button" class="btn btn-primary pull-right" id="address-save"><i class="icon-ok"></i>
{{ doc and "Save" or "Insert" }}</button>
<div class="clearfix"></div>
<hr>
<div id="address-error" class="alert alert-danger" style="display: none;"></div>
<form autocomplete="on">
<div class="row">
<section class="col-md-6">
{{ render_fields(meta.left_fields) }}
</section>
<section class="col-md-6">
{{ render_fields(meta.right_fields) }}
</section>
</section>
</form>
</div>
<script>
;(function() {
$(document).ready(function() {
bind_save();
});
var bind_save = function() {
$("#address-save").on("click", function() {
var fields = {
name: "{{ docname }}"
};
$("form").find("[data-fieldname]").each(function(i, input) {
var $input = $(input);
var fieldname = $(input).attr("data-fieldname");
var fieldtype = $(input).attr("data-fieldtype");
if(fieldtype == "Check") {
fields[fieldname] = $input.is(":checked") ? 1 : 0;
} else {
fields[fieldname] = $input.val();
}
});
wn.call({
btn: $(this),
type: "POST",
method: "selling.utils.cart.save_address",
args: { fields: fields, address_fieldname: get_url_arg("address_fieldname") },
callback: function(r) {
if(r.exc) {
var msg = "";
if(r._server_messages) {
msg = JSON.parse(r._server_messages || []).join("<br>");
}
$("#address-error")
.html(msg || "Something went wrong!")
.toggle(true);
} else if(get_url_arg("address_fieldname")) {
window.location.href = "cart";
} else {
window.location.href = "address?name=" + encodeURIComponent(r.message);
}
}
});
});
};
})();
</script>
{% endblock %}

View File

@@ -0,0 +1,52 @@
{% extends "app/website/templates/html/page.html" %}
{% set title="My Addresses" %}
{% block content %}
<div class="col-md-12">
<ul class="breadcrumb">
<li><a href="index">Home</a></li>
<li><a href="account">My Account</a></li>
<li class="active"><i class="icon-map-marker icon-fixed-width"></i> My Addresses</li>
</ul>
<p><a class="btn btn-default" href="address"><i class="icon-plus"> New Address</i></a></p>
<hr>
<div id="address-list">
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-info" style="width: 100%;"></div>
</div>
</div>
</div>
<script>
;(function() {
$(document).ready(function() {
fetch_addresses();
});
var fetch_addresses = function() {
wn.call({
method: "selling.utils.cart.get_addresses",
callback: function(r) {
$("#address-list .progress").remove();
var $list = $("#address-list");
if(!(r.message && r.message.length)) {
$list.html("<div class='alert'>No Addresses Found</div>");
return;
}
$.each(r.message, function(i, address) {
address.url_name = encodeURIComponent(address.name);
$(repl('<div> \
<p><a href="address?name=%(url_name)s">%(name)s</a></p> \
<p>%(display)s</p> \
<hr> \
</div>', address)).appendTo($list);
});
}
});
};
})();
</script>
{% endblock %}

View File

@@ -0,0 +1,139 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import webnotes
from webnotes.utils import cint, formatdate
import json
def get_transaction_list(doctype, start):
# find customer id
customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user},
"customer")
if customer:
transactions = webnotes.conn.sql("""select name, creation, currency, grand_total_export
from `tab%s` where customer=%s and docstatus=1
order by creation desc
limit %s, 20""" % (doctype, "%s", "%s"), (customer, cint(start)), as_dict=True)
for doc in transactions:
doc.items = ", ".join(webnotes.conn.sql_list("""select item_name
from `tab%s Item` where parent=%s limit 5""" % (doctype, "%s"), doc.name))
doc.creation = formatdate(doc.creation)
return transactions
else:
return []
def get_common_args():
return {
"global_number_format": webnotes.conn.get_default("number_format") or "#,###.##",
"currency": webnotes.conn.get_default("currency"),
"currency_symbols": json.dumps(dict(webnotes.conn.sql("""select name, symbol
from tabCurrency where ifnull(enabled,0)=1""")))
}
@webnotes.whitelist()
def get_orders(start=0):
return get_transaction_list("Sales Order", start)
def order_list_args():
args = get_common_args()
args.update({
"title": "My Orders",
"method": "utilities.website_transactions.get_orders",
"icon": "icon-list",
"empty_list_message": "No Orders Yet",
"page": "order",
})
return args
@webnotes.whitelist()
def get_invoices(start=0):
return get_transaction_list("Sales Invoice", start)
def invoice_list_args():
args = get_common_args()
args.update({
"title": "Invoices",
"method": "utilities.website_transactions.get_invoices",
"icon": "icon-file-text",
"empty_list_message": "No Invoices Found",
"page": "invoice"
})
return args
@webnotes.whitelist()
def get_shipments(start=0):
return get_transaction_list("Delivery Note", start)
def shipment_list_args():
args = get_common_args()
args.update({
"title": "Shipments",
"method": "utilities.website_transactions.get_shipments",
"icon": "icon-truck",
"empty_list_message": "No Shipments Found",
"page": "shipment"
})
return args
@webnotes.whitelist()
def get_tickets(start=0):
tickets = webnotes.conn.sql("""select name, subject, status, creation
from `tabSupport Ticket` where raised_by=%s
order by modified desc
limit %s, 20""", (webnotes.session.user, cint(start)), as_dict=True)
for t in tickets:
t.creation = formatdate(t.creation)
return tickets
def ticket_list_args():
return {
"title": "My Tickets",
"method": "utilities.website_transactions.get_tickets",
"icon": "icon-ticket",
"empty_list_message": "No Tickets Raised",
"page": "ticket"
}
def get_transaction_args(doctype, name):
customer = webnotes.conn.get_value("Contact", {"email_id": webnotes.session.user},
"customer")
bean = webnotes.bean(doctype, name)
if bean.doc.customer != customer:
return {
"doc": {"name": "Not Allowed"}
}
else:
return {
"doc": bean.doc,
"doclist": bean.doclist,
"webnotes": webnotes,
"utils": webnotes.utils
}
def get_order_args():
args = get_transaction_args("Sales Order", webnotes.form_dict.name)
args.update({
"parent_link": "orders",
"parent_title": "My Orders"
})
return args
def get_invoice_args():
args = get_transaction_args("Sales Invoice", webnotes.form_dict.name)
args.update({
"parent_link": "invoices",
"parent_title": "Invoices"
})
return args
def get_shipment_args():
args = get_transaction_args("Delivery Note", webnotes.form_dict.name)
args.update({
"parent_link": "shipments",
"parent_title": "Shipments"
})
return args