[fixes] portal, issues, addresses etc

This commit is contained in:
Rushabh Mehta 2015-06-01 17:15:42 +05:30
parent ca23b5ecfd
commit a33d468d30
25 changed files with 330 additions and 570 deletions

View File

@ -334,7 +334,7 @@ class AccountsController(TransactionBase):
@frappe.whitelist()
def get_tax_rate(account_head):
return frappe.db.get_value("Account", account_head, "tax_rate")
@frappe.whitelist()
def get_default_taxes_and_charges(master_doctype):
default_tax = frappe.db.get_value(master_doctype, {"is_default": 1})

View File

@ -38,16 +38,14 @@ website_route_rules = [
{"from_route": "/invoices", "to_route": "Sales Invoice"},
{"from_route": "/invoices/<path:name>", "to_route": "print", "defaults": {"doctype": "Sales Invoice"}},
{"from_route": "/shipments", "to_route": "Delivery Note"},
{"from_route": "/shipments/<path:name>", "to_route": "print", "defaults": {"doctype": "Delivery Note"}},
{"from_route": "/issues", "to_route": "Issue"},
{"from_route": "/issues/<path:name>", "to_route": "print", "defaults": {"doctype": "Issue"}},
{"from_route": "/addresses", "to_route": "Address"},
{"from_route": "/shipments/<path:name>", "to_route": "print", "defaults": {"doctype": "Delivery Note"}}
]
has_website_permission = {
"Sales Order": "erpnext.controllers.website_list_for_contact.has_website_permission",
"Sales Invoice": "erpnext.controllers.website_list_for_contact.has_website_permission",
"Delivery Note": "erpnext.controllers.website_list_for_contact.has_website_permission"
"Delivery Note": "erpnext.controllers.website_list_for_contact.has_website_permission",
"Issue": "erpnext.support.doctype.issue.issue.has_website_permission"
}
dump_report_map = "erpnext.startup.report_data_map.data_map"

View File

@ -161,4 +161,5 @@ erpnext.patches.v5_0.set_footer_address
execute:frappe.db.set_value("Backup Manager", None, "send_backups_to_dropbox", 1 if frappe.db.get_value("Backup Manager", None, "upload_backups_to_dropbox") in ("Daily", "Weekly") else 0)
execute:frappe.db.sql_list("delete from `tabDocPerm` where parent='Issue' and modified_by='Administrator' and role='Guest'")
erpnext.patches.v5_0.update_item_and_description_again
erpnext.patches.v5_0.repost_gle_for_jv_with_multiple_party
erpnext.patches.v5_0.repost_gle_for_jv_with_multiple_party
erpnext.patches.v5_0.portal_fixes

View File

@ -0,0 +1,3 @@
def execute():
import erpnext.setup.install
erpnext.setup.install.add_web_forms()

View File

@ -0,0 +1,167 @@
[
{
"allow_comments": 0,
"allow_delete": 0,
"allow_edit": 1,
"allow_multiple": 1,
"breadcrumbs": null,
"doc_type": "Address",
"docstatus": 0,
"doctype": "Web Form",
"introduction_text": null,
"login_required": 1,
"modified": "2015-06-01 06:53:43.699336",
"name": "addresses",
"page_name": "addresses",
"published": 1,
"success_message": null,
"success_url": "/addresses",
"title": "Addresses",
"web_form_fields": [
{
"default": null,
"description": "",
"fieldname": "address_title",
"fieldtype": "Data",
"hidden": 0,
"label": "Address Title",
"options": null,
"read_only": 0,
"reqd": 0
},
{
"default": null,
"description": null,
"fieldname": "address_type",
"fieldtype": "Select",
"hidden": 0,
"label": "Address Type",
"options": "Billing\nShipping\nOffice\nPersonal\nPlant\nPostal\nShop\nSubsidiary\nWarehouse\nOther",
"read_only": 0,
"reqd": 1
},
{
"default": null,
"description": null,
"fieldname": "address_line1",
"fieldtype": "Data",
"hidden": 0,
"label": "Address Line 1",
"options": null,
"read_only": 0,
"reqd": 1
},
{
"default": null,
"description": null,
"fieldname": "address_line2",
"fieldtype": "Data",
"hidden": 0,
"label": "Address Line 2",
"options": null,
"read_only": 0,
"reqd": 0
},
{
"default": null,
"description": null,
"fieldname": "city",
"fieldtype": "Data",
"hidden": 0,
"label": "City/Town",
"options": null,
"read_only": 0,
"reqd": 1
},
{
"default": null,
"description": null,
"fieldname": "state",
"fieldtype": "Data",
"hidden": 0,
"label": "State",
"options": null,
"read_only": 0,
"reqd": 0
},
{
"default": null,
"description": null,
"fieldname": "pincode",
"fieldtype": "Data",
"hidden": 0,
"label": "Pincode",
"options": null,
"read_only": 0,
"reqd": 0
},
{
"default": null,
"description": null,
"fieldname": "country",
"fieldtype": "Data",
"hidden": 0,
"label": "Country",
"options": "Country",
"read_only": 0,
"reqd": 1
},
{
"default": null,
"description": null,
"fieldname": null,
"fieldtype": "Column Break",
"hidden": null,
"label": null,
"options": null,
"read_only": null,
"reqd": null
},
{
"default": null,
"description": null,
"fieldname": "email_id",
"fieldtype": "Data",
"hidden": 0,
"label": "Email Id",
"options": null,
"read_only": 0,
"reqd": 0
},
{
"default": null,
"description": null,
"fieldname": "phone",
"fieldtype": "Data",
"hidden": 0,
"label": "Phone",
"options": null,
"read_only": 0,
"reqd": 1
},
{
"default": "0",
"description": "",
"fieldname": "is_primary_address",
"fieldtype": "Check",
"hidden": 0,
"label": "Preferred Billing Address",
"options": null,
"read_only": 0,
"reqd": 0
},
{
"default": "0",
"description": "",
"fieldname": "is_shipping_address",
"fieldtype": "Check",
"hidden": 0,
"label": "Preferred Shipping Address",
"options": null,
"read_only": 0,
"reqd": 0
}
],
"web_page_link_text": null
}
]

View File

@ -0,0 +1,57 @@
[
{
"allow_comments": 1,
"allow_delete": 1,
"allow_edit": 1,
"allow_multiple": 1,
"breadcrumbs": "[{\"title\":\"Issues\", \"name\":\"issues\"}]",
"doc_type": "Issue",
"docstatus": 0,
"doctype": "Web Form",
"introduction_text": null,
"login_required": 1,
"modified": "2015-06-01 05:59:03.697380",
"name": "issues",
"page_name": "issues",
"published": 1,
"success_message": "",
"success_url": "/issues",
"title": "Issues",
"web_form_fields": [
{
"default": null,
"description": null,
"fieldname": "subject",
"fieldtype": "Data",
"hidden": 0,
"label": "Subject",
"options": null,
"read_only": 0,
"reqd": 1
},
{
"default": "Open",
"description": null,
"fieldname": "status",
"fieldtype": "Select",
"hidden": null,
"label": "Status",
"options": "Open\nReplied\nHold\nClosed",
"read_only": 1,
"reqd": 0
},
{
"default": null,
"description": null,
"fieldname": "description",
"fieldtype": "Text",
"hidden": 0,
"label": "Description",
"options": null,
"read_only": 0,
"reqd": 0
}
],
"web_page_link_text": null
}
]

View File

@ -15,6 +15,7 @@ def after_install():
feature_setup()
from erpnext.setup.page.setup_wizard.setup_wizard import add_all_roles_to
add_all_roles_to("Administrator")
add_web_forms()
frappe.db.commit()
def feature_setup():
@ -48,3 +49,12 @@ def set_single_defaults():
pass
frappe.db.set_default("date_format", "dd-mm-yyyy")
def add_web_forms():
"""Import web forms for Issues and Addresses"""
from frappe.modules.import_file import import_file_by_path
import_file_by_path(frappe.get_app_path("erpnext", "setup/fixtures/web_form/issues.json"),
data_import=True)
import_file_by_path(frappe.get_app_path("erpnext", "setup/fixtures/web_form/addresses.json"),
data_import=True)

View File

@ -5,17 +5,18 @@ from __future__ import unicode_literals
import frappe
from frappe import throw, _
import frappe.defaults
from frappe.utils import flt, get_fullname, fmt_money, cstr
from frappe.utils import cint, flt, get_fullname, fmt_money, cstr
from erpnext.utilities.doctype.address.address import get_address_display
from frappe.utils.nestedset import get_root_of
class WebsitePriceListMissingError(frappe.ValidationError): pass
def set_cart_count(quotation=None):
if not quotation:
quotation = _get_cart_quotation()
cart_count = cstr(len(quotation.get("items")))
frappe.local.cookie_manager.set_cookie("cart_count", cart_count)
if cint(frappe.db.get_singles_value("Shopping Cart Settings", "enabled")):
if not quotation:
quotation = _get_cart_quotation()
cart_count = cstr(len(quotation.get("items")))
frappe.local.cookie_manager.set_cookie("cart_count", cart_count)
@frappe.whitelist()
def get_cart_quotation(doc=None):
@ -29,7 +30,7 @@ def get_cart_quotation(doc=None):
return {
"doc": decorate_quotation_doc(doc),
"addresses": [{"name": address.name, "display": address.display}
for address in get_address_docs(party)],
for address in get_address_docs(party=party)],
"shipping_rules": get_applicable_shipping_rules(party)
}
@ -281,12 +282,13 @@ def get_lead_or_customer():
return lead_doc
def get_address_docs(party=None):
def get_address_docs(doctype, txt, filters, limit_start, limit_page_length=20, party=None):
if not party:
party = get_lead_or_customer()
address_docs = frappe.db.sql("""select * from `tabAddress`
where `%s`=%s order by name""" % (party.doctype.lower(), "%s"), party.name,
where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(),
limit_start, limit_page_length), party.name,
as_dict=True, update={"doctype": "Address"})
for address in address_docs:

View File

@ -8,7 +8,7 @@ import frappe
from frappe import _, msgprint
from frappe.utils import comma_and
from frappe.model.document import Document
from frappe.utils.nestedset import get_ancestors_of
from frappe.utils.nestedset import get_ancestors_of, get_root_of
from erpnext.utilities.doctype.address.address import get_territory_from_address
class ShoppingCartSetupError(frappe.ValidationError): pass
@ -42,7 +42,7 @@ class ShoppingCartSettings(Document):
return territory_name_map
def validate_price_lists(self):
territory_name_map = self.validate_overlapping_territories("price_lists", "selling_price_list")
self.validate_overlapping_territories("price_lists", "selling_price_list")
# validate that a Shopping Cart Price List exists for the default territory as a catch all!
price_list_for_default_territory = self.get_name_from_territory(self.default_territory, "price_lists",
@ -131,7 +131,8 @@ class ShoppingCartSettings(Document):
def get_price_list(self, billing_territory):
price_list = self.get_name_from_territory(billing_territory, "price_lists", "selling_price_list")
if not (price_list and price_list[0]):
price_list = self.get_name_from_territory(self.default_territory, "price_lists", "selling_price_list")
price_list = self.get_name_from_territory(self.default_territory or get_root_of("Territory"),
"price_lists", "selling_price_list")
return price_list and price_list[0] or None
@ -165,7 +166,7 @@ def is_cart_enabled():
return get_shopping_cart_settings().enabled
def get_default_territory():
return get_shopping_cart_settings().default_territory
return get_shopping_cart_settings().default_territory or get_root_of("Territory")
def check_shopping_cart_enabled():
if not get_shopping_cart_settings().enabled:

View File

@ -6,7 +6,6 @@ from __future__ import unicode_literals
import frappe
from frappe import _
import frappe.defaults
from frappe.utils import cint
from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import is_cart_enabled
def show_cart_count():
@ -44,6 +43,6 @@ def update_my_account_context(context):
{"label": _("Orders"), "url": "orders"},
{"label": _("Invoices"), "url": "invoices"},
{"label": _("Shipments"), "url": "shipments"},
# {"label": _("Issues"), "url": "tickets"},
{"label": _("Issues"), "url": "issues"},
{"label": _("Addresses"), "url": "addresses"},
])

View File

@ -66,7 +66,7 @@
"oldfieldtype": "Data",
"options": "Email",
"permlevel": 0,
"reqd": 1
"reqd": 0
},
{
"fieldname": "fold",
@ -233,7 +233,7 @@
],
"icon": "icon-ticket",
"idx": 1,
"modified": "2015-05-28 03:21:04.690112",
"modified": "2015-06-01 03:48:24.849210",
"modified_by": "Administrator",
"module": "Support",
"name": "Issue",

View File

@ -17,6 +17,8 @@ class Issue(Document):
return "{0}: {1}".format(_(self.status), self.subject)
def validate(self):
if not self.raised_by:
self.raised_by = frappe.session.user
self.update_status()
self.set_lead_contact(self.raised_by)
@ -54,7 +56,8 @@ class Issue(Document):
def get_list_context(context=None):
return {
"title": _("My Issues"),
"get_list": get_issue_list
"get_list": get_issue_list,
"row_template": "templates/includes/issue_row.html"
}
def get_issue_list(doctype, txt, filters, limit_start, limit_page_length=20):
@ -84,3 +87,6 @@ def set_multiple_status(names, status):
names = json.loads(names)
for name in names:
set_status(name, status)
def has_website_permission(doc, ptype, user, verbose=False):
return doc.raised_by==user

View File

@ -0,0 +1,20 @@
<div class="web-list-item">
<a href="/addresses?name={{ doc.name }}" no-pjax>
<div class="row">
<div class="col-sm-4">
<span class="strong">{{ doc.address_title }}</span>
</div>
<div class="col-sm-2">
{{ doc.address_type }}
</div>
<div class="col-sm-4">
{{ doc.address_line1 }}<br>
{% if doc.address_line2 %}{{ doc.address_line2 }}<br>{% endif %}
{{ doc.city }}<br>
</div>
<div class="col-sm-2">
{% if doc.state %}{{ doc.state }}, {% endif %}{{ doc.country }}
</div>
</div>
</a>
</div>

View File

@ -0,0 +1,16 @@
<div class="web-list-item">
<div class="row">
<div class="col-sm-8">
<a class="no-decoration" href="/issues?name={{ doc.name }}" no-pjax>
{{ doc.subject }}
</a>
</div>
<div class="col-sm-2">
<span class="indicator {{ "red" if doc.status=="Open" else "blue" }}">
{{ doc.status }}</span>
</div>
<div class="col-sm-2 text-muted text-right small">
{{ frappe.format_date(doc.creation) }}
</div>
</div>
</div>

View File

@ -1,5 +1,6 @@
{% set doc = frappe.get_doc(doc) %}
<a class="website-list-row" href="/{{ pathname }}/{{ doc.name }}" no-pjax>
<div class="web-list-item">
<a href="/{{ pathname }}/{{ doc.name }}" no-pjax>
<div class="row">
<div class="col-sm-6 col-xs-7">
<div class="row">
@ -12,7 +13,7 @@
<span class="indicator orange">{{ doc.status_display }}</span>
{%- endif -%}
{%- elif doc.status -%}
<span class="indicator">{{ doc.status }}</span>
<span class="indicator blue">{{ doc.status }}</span>
{%- endif -%}
</div>
</div>
@ -27,4 +28,4 @@
{{ frappe.utils.pretty_date(doc.creation) }}</div>
</div>
</a>
</div>

View File

@ -1,112 +0,0 @@
{% block title %} {{ title }} {% endblock %}
{% block header %}<h2>{{ title }}</h2>{% endblock %}
{% block content %}
{% macro render_fields(docfields) -%}
{% for df in docfields -%}
{% if df.fieldtype == "Data" -%}
<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.get(df.fieldname) -%} value="{{ doc[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 frappe.utils.cint(doc.get(df.fieldname)) -%} checked="checked" {%- endif %}>
{{ df.label }}</label>
</fieldset>
{% elif df.fieldtype in ("Select", "Link") -%}
<fieldset>
{% set select_options = frappe.get_list(df.options)|map(attribute="name")
if df.fieldtype == "Link" else df.options.split("\n") %}
<label>{{ df.label }}</label>
<select class="form-control" data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}">
{% for value in select_options -%}
{% if doc and doc.get(df.fieldname) == value -%}
<option selected="selected">{{ value }}</option>
{% else -%}
<option>{{ value }}</option>
{%- endif %}
{%- endfor %}
</select>
</fieldset>
{%- endif %}
{%- endfor %}
{%- endmacro %}
<div class="container content">
<ul class="breadcrumb">
<li><a href="/index">Home</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() {
console.log("yoyo");
frappe.ready(function() {
bind_save();
});
var bind_save = function() {
$("#address-save").on("click", function() {
console.log("clicked!");
var fields = {
name: "{{ docname or '' }}"
};
$("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();
}
});
frappe.call({
btn: $(this),
type: "POST",
method: "erpnext.templates.pages.address.save_address",
args: { fields: fields, address_fieldname: get_url_arg("address_fieldname") },
error_msg: "#address-error",
callback: function(r) {
if(get_url_arg("address_fieldname")) {
window.location.href = "cart";
} else {
window.location.href = "address?name=" + encodeURIComponent(r.message);
}
}
});
});
};
})();
</script>
<!-- no-sidebar -->
{% endblock %}

View File

@ -1,62 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import json
import frappe
from erpnext.shopping_cart.cart import get_lead_or_customer, update_cart_address
from frappe.desk.form.meta import get_meta
no_cache = 1
no_sitemap = 1
def get_context(context):
def _get_fields(fieldnames):
return [frappe._dict(zip(["label", "fieldname", "fieldtype", "options"],
[df.label, df.fieldname, df.fieldtype, df.options]))
for df in get_meta("Address").get("fields", {"fieldname": ["in", fieldnames]})]
docname = doc = None
title = "New Address"
if frappe.form_dict.name:
doc = frappe.get_doc("Address", frappe.form_dict.name)
docname = doc.name
title = doc.name
return {
"doc": doc,
"meta": frappe._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"])
}),
"docname": docname,
"title": title
}
@frappe.whitelist()
def save_address(fields, address_fieldname=None):
party = get_lead_or_customer()
fields = json.loads(fields)
if fields.get("name"):
doc = frappe.get_doc("Address", fields.get("name"))
else:
doc = frappe.get_doc({"doctype": "Address", "__islocal": 1})
doc.update(fields)
party_fieldname = party.doctype.lower()
doc.update({
party_fieldname: party.name,
(party_fieldname + "_name"): party.get(party_fieldname + "_name")
})
doc.flags.ignore_permissions = True
doc.save()
if address_fieldname:
update_cart_address(address_fieldname, doc.name)
return doc.name

View File

@ -1,50 +0,0 @@
{% block title %} {{ "My Addresses" }} {% endblock %}
{% block header %}<h2>My Addresses</h2>{% endblock %}
{% block breadcrumbs %}{% include "templates/includes/breadcrumbs.html" %}{% endblock %}
{% block content %}
<div class="addresses-content">
<p><a class="btn btn-default" href="/address"><i class="icon-plus"> New Address</i></a></p>
<hr>
<div id="address-list">
<div class="text-muted progress">{{ _("Loading") }}...</div>
</div>
</div>
<script>
;(function() {
var fetch_addresses = function() {
frappe.call({
method: "erpnext.templates.pages.addresses.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);
});
}
});
};
$(document).ready(function() {
fetch_addresses();
});
})();
</script>
<!-- no-sidebar -->
{% endblock %}

View File

@ -1,13 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from erpnext.shopping_cart.cart import get_address_docs
no_cache = 1
no_sitemap = 1
@frappe.whitelist()
def get_addresses():
return get_address_docs()

View File

@ -1,116 +0,0 @@
{% block title %} {{ title }} {% endblock %}
{% block header %}<h2><i class="icon-ticket icon-fixed-width"></i> {{ title }}</h2>{% endblock %}
{% block content %}
{% set status_label = {
"Open": "label-success",
"To Reply": "label-danger",
"Closed": "label-default"
} %}
<div class="ticket-content">
<ul class="breadcrumb">
<li><a href="/index">Home</a></li>
<li><a href="/tickets">My Tickets</a></li>
<li class="active"><i class="icon-ticket icon-fixed-width"></i> {{ doc.name or "" }}</li>
</ul>
{% if not doc -%}
<script>ask_to_login();</script>
{% else %}
<hr>
{%- if doc.status -%}
{% if doc.status == "Waiting for Customer" -%}
{% set status = "To Reply" %}
{% else %}
{% set status = doc.status %}
{%- endif -%}
<div class="row">
<div class="col-md-2" style="margin-bottom: 7px;">
<span class="label {{ status_label.get(status) or 'label-default' }}">{{ status }}</span>
</div>
<div class="col-md-8">
<div class="row col-md-12">{{ doc.subject }}</div>
</div>
<div class="col-md-2">
<span class="text-muted pull-right">{{ frappe.utils.formatdate(doc.creation) }}</span>
</div>
</div>
<div class="row">
<h4 class="col-xs-6">Messages</h4>
<div class="col-xs-6">
<button class="btn btn-sm btn-primary pull-right" id="ticket-reply">
<i class="icon-envelope icon-fixed-width"></i> Reply</button>
<button class="btn btn-sm btn-success pull-right hide" id="ticket-reply-send">
<i class="icon-arrow-right icon-fixed-width"></i> Send</button>
</div>
</div>
<p id="ticket-alert" class="alert alert-danger"
style="display: none;">&nbsp;</p>
<div>
<table class="table table-bordered table-striped" id="ticket-thread">
<tbody>
{%- for comm in
(doc.get({"doctype":"Communication"})|sort(reverse=True, attribute="creation")) %}
<tr>
<td>
<h5 style="text-transform: none">
{{ comm.sender }} on {{ frappe.utils.formatdate(comm.creation) }}</h5>
<hr>
<p>{{ frappe.utils.is_html(comm.content) and comm.content or
comm.content.replace("\n", "<br>")}}</p>
</td>
</tr>
{% endfor -%}
</tbody>
</table>
</div>
{%- endif -%}
{% endif -%}
</div>
<script>
$(document).ready(function() {
$("#ticket-reply").on("click", function() {
if(!$("#ticket-reply-editor").length) {
$('<tr id="ticket-reply-editor"><td>\
<h5 style="text-transform: none">Reply</h5>\
<hr>\
<textarea rows=10 class="form-control" style="resize: vertical;"></textarea>\
</td></tr>').prependTo($("#ticket-thread").find("tbody"));
$("#ticket-reply").addClass("hide");
$("#ticket-reply-send").removeClass("hide");
}
});
$("#ticket-reply-send").on("click", function() {
var reply = $("#ticket-reply-editor").find("textarea").val().trim();
if(!reply) {
msgprint("Please write something in reply!");
} else {
frappe.call({
type: "POST",
method: "erpnext.templates.pages.ticket.add_reply",
btn: this,
args: { ticket: "{{ doc.name }}", message: reply },
callback: function(r) {
if(r.exc) {
msgprint(r._server_messages
? JSON.parse(r._server_messages).join("<br>")
: "Something went wrong!");
} else {
window.location.reload();
}
}
})
}
});
});
var msgprint = function(txt) {
if(txt) $("#ticket-alert").html(txt).toggle(true);
}
</script>
<!-- no-sidebar -->
{% endblock %}

View File

@ -1,41 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import today
no_cache = 1
no_sitemap = 1
def get_context(context):
doc = frappe.get_doc("Issue", frappe.form_dict.name)
if doc.raised_by == frappe.session.user:
ticket_context = {
"title": doc.name,
"doc": doc
}
else:
ticket_context = {"title": "Not Allowed", "doc": {}}
return ticket_context
@frappe.whitelist()
def add_reply(ticket, message):
if not message:
raise frappe.throw(_("Please write something"))
doc = frappe.get_doc("Issue", ticket)
if doc.raised_by != frappe.session.user:
raise frappe.throw(_("You are not allowed to reply to this ticket."), frappe.PermissionError)
comm = frappe.get_doc({
"doctype":"Communication",
"subject": doc.subject,
"content": message,
"sender": doc.raised_by,
"sent_or_received": "Received"
})
comm.insert(ignore_permissions=True)

View File

@ -1,92 +0,0 @@
{% block title %} {{ title }} {% endblock %}
{% block header %}<h2>{{ title }}</h2>{% endblock %}
{% block content %}
{% include "templates/includes/transactions.html" %}
<script>
var status_label = {
"Open": "label-success",
"Waiting for Customer": "label-danger",
"Closed": "label-default"
}
var render = function(doc) {
doc.status = doc.status.trim();
doc.label_class = status_label[doc.status] || "label-default";
if(doc.status==="Waiting for Customer") doc.status = "To Reply";
$(repl('<a href="{{ page }}?name=%(name)s" class="list-group-item">\
<div class="row">\
<div class="col-md-2" style="margin-bottom: 7px;"><span class="label %(label_class)s">\
%(status)s</span></div>\
<div class="col-md-8">\
<div class="row col-md-12">%(name)s</div>\
<div class="row col-md-12 text-muted">%(subject)s</div>\
</div>\
<div class="col-md-2 pull-right">\
<span class="text-muted">%(creation)s</span>\
</div>\
</div>\
</a>', doc)).appendTo($list);
};
frappe.ready(function() {
if(!window.$new_ticket) {
window.$new_ticket = $('<div>\
<button class="btn btn-primary" style="margin-bottom: 15px;" id="new-ticket">\
<i class="icon-tag icon-fixed-width"></i> New Ticket\
</button>\
<button class="btn btn-success hide" style="margin-bottom: 15px;" id="new-ticket-send">\
<i class="icon-arrow-right icon-fixed-width"></i> Send\
</button>\
</div>').insertBefore(".transaction-list");
}
window.$new_ticket.find("#new-ticket").on("click", function() {
$(this).addClass("hide");
$(window.$new_ticket).find("#new-ticket-send").removeClass("hide");
$('<div class="well" id="ticket-editor">\
<div class="form-group"><input class="form-control" type="data"\
placeholder="Subject" data-fieldname="subject"></div>\
<div class="form-group"><textarea rows=10 class="form-control" \
style="resize: vertical;" placeholder="Message" \
data-fieldname="message"></textarea></div>\
</div>')
.insertAfter(window.$new_ticket);
});
window.$new_ticket.find("#new-ticket-send").on("click", function() {
var subject = $("#ticket-editor").find('[data-fieldname="subject"]').val().trim();
var message = $("#ticket-editor").find('[data-fieldname="message"]').val().trim();
if(!(subject && message)) {
msgprint("Please write something in subject and message!");
} else {
frappe.call({
type: "POST",
method: "erpnext.templates.pages.tickets.make_new_ticket",
btn: this,
args: { subject: subject, message: message },
callback: function(r) {
if(r.exc) {
msgprint(r._server_messages
? JSON.parse(r._server_messages).join("<br>")
: "Something went wrong!");
} else {
window.location.href = "ticket?name=" + encodeURIComponent(r.message);
}
}
})
}
});
});
var msgprint = function(txt) {
if(txt) $("#msgprint-alert").html(txt).toggle(true);
}
</script>
<!-- no-sidebar -->
{% endblock %}

View File

@ -1,54 +0,0 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.utils import cint, formatdate
no_cache = 1
no_sitemap = 1
def get_context(context):
return {
"title": "My Tickets",
"method": "erpnext.templates.pages.tickets.get_tickets",
"icon": "icon-ticket",
"empty_list_message": "No Tickets Raised",
"page": "ticket"
}
@frappe.whitelist()
def get_tickets(start=0):
tickets = frappe.db.sql("""select name, subject, status, creation
from `tabIssue` where raised_by=%s
order by modified desc
limit %s, 20""", (frappe.session.user, cint(start)), as_dict=True)
for t in tickets:
t.creation = formatdate(t.creation)
return tickets
@frappe.whitelist()
def make_new_ticket(subject, message):
if not (subject and message):
raise frappe.throw(_("Please write something in subject and message!"))
ticket = frappe.get_doc({
"doctype":"Issue",
"subject": subject,
"raised_by": frappe.session.user,
})
ticket.insert(ignore_permissions=True)
comm = frappe.get_doc({
"doctype":"Communication",
"subject": subject,
"content": message,
"sender": frappe.session.user,
"sent_or_received": "Received",
"reference_doctype": "Issue",
"reference_name": ticket.name
})
comm.insert(ignore_permissions=True)
return ticket.name

View File

@ -112,7 +112,7 @@
},
{
"default": "0",
"description": "Check to make primary address",
"description": "",
"fieldname": "is_primary_address",
"fieldtype": "Check",
"label": "Preferred Billing Address",
@ -120,7 +120,7 @@
},
{
"default": "0",
"description": "Check to make Shipping Address",
"description": "",
"fieldname": "is_shipping_address",
"fieldtype": "Check",
"in_list_view": 0,
@ -199,7 +199,7 @@
"icon": "icon-map-marker",
"idx": 1,
"in_dialog": 0,
"modified": "2015-02-20 05:07:56.567822",
"modified": "2015-06-01 06:42:18.331818",
"modified_by": "Administrator",
"module": "Utilities",
"name": "Address",

View File

@ -84,5 +84,24 @@ def get_territory_from_address(address):
return territory
def get_list_context(context=None):
from erpnext.shopping_cart.cart import get_address_docs
return {
"title": _("My Addresses"),
"get_list": get_address_docs,
"row_template": "templates/includes/address_row.html",
}
def has_website_permission(doc, ptype, user, verbose=False):
"""Returns true if customer or lead matches with user"""
customer = frappe.db.get_value("Contact", {"email_id": frappe.session.user}, "customer")
if customer:
return doc.customer == customer
else:
lead = frappe.db.get_value("Lead", {"email_id": frappe.session.user})
if lead:
return doc.lead == lead
return False