Merge pull request #4125 from rmehta/variant-in-website
[enhancement] add variants in website
This commit is contained in:
commit
53f77ad5e8
@ -224,3 +224,5 @@ erpnext.patches.v6_4.email_digest_update
|
|||||||
execute:frappe.delete_doc_if_exists("DocType", "Applicable Territory")
|
execute:frappe.delete_doc_if_exists("DocType", "Applicable Territory")
|
||||||
execute:frappe.delete_doc_if_exists("DocType", "Shopping Cart Price List")
|
execute:frappe.delete_doc_if_exists("DocType", "Shopping Cart Price List")
|
||||||
execute:frappe.delete_doc_if_exists("DocType", "Shopping Cart Taxes and Charges Master")
|
execute:frappe.delete_doc_if_exists("DocType", "Shopping Cart Taxes and Charges Master")
|
||||||
|
erpnext.patches.v6_4.set_user_in_contact
|
||||||
|
erpnext.patches.v6_4.make_image_thumbnail
|
||||||
|
14
erpnext/patches/v6_4/make_image_thumbnail.py
Normal file
14
erpnext/patches/v6_4/make_image_thumbnail.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import frappe
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
frappe.reload_doctype("File")
|
||||||
|
frappe.reload_doctype("Item")
|
||||||
|
for item in frappe.get_all("Item", fields=("name", "website_image")):
|
||||||
|
if item.website_image:
|
||||||
|
item_doc = frappe.get_doc("Item", item.name)
|
||||||
|
try:
|
||||||
|
item_doc.make_thumbnail()
|
||||||
|
if item_doc.thumbnail:
|
||||||
|
item_doc.db_set("thumbnail", item_doc.thumbnail, update_modified=False)
|
||||||
|
except Exception:
|
||||||
|
print "Unable to make thumbnail for {0}".format(item.website_image)
|
6
erpnext/patches/v6_4/set_user_in_contact.py
Normal file
6
erpnext/patches/v6_4/set_user_in_contact.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import frappe
|
||||||
|
|
||||||
|
def execute():
|
||||||
|
frappe.reload_doctype("Contact")
|
||||||
|
frappe.db.sql("""update tabContact, tabUser set tabContact.user = tabUser.name
|
||||||
|
where tabContact.email_id = tabUser.email""")
|
@ -20,7 +20,6 @@ $.extend(shopping_cart, {
|
|||||||
if(!full_name || full_name==="Guest") {
|
if(!full_name || full_name==="Guest") {
|
||||||
if(localStorage) {
|
if(localStorage) {
|
||||||
localStorage.setItem("last_visited", window.location.pathname);
|
localStorage.setItem("last_visited", window.location.pathname);
|
||||||
localStorage.setItem("pending_add_to_cart", opts.item_code);
|
|
||||||
}
|
}
|
||||||
window.location.href = "/login";
|
window.location.href = "/login";
|
||||||
} else {
|
} else {
|
||||||
|
@ -19,6 +19,8 @@ class Quotation(SellingController):
|
|||||||
self.validate_order_type()
|
self.validate_order_type()
|
||||||
self.validate_uom_is_integer("stock_uom", "qty")
|
self.validate_uom_is_integer("stock_uom", "qty")
|
||||||
self.validate_quotation_to()
|
self.validate_quotation_to()
|
||||||
|
if self.items:
|
||||||
|
self.with_items = 1
|
||||||
|
|
||||||
def has_sales_order(self):
|
def has_sales_order(self):
|
||||||
return frappe.db.get_value("Sales Order Item", {"prevdoc_docname": self.name, "docstatus": 1})
|
return frappe.db.get_value("Sales Order Item", {"prevdoc_docname": self.name, "docstatus": 1})
|
||||||
|
@ -66,11 +66,12 @@ def get_product_list_for_group(product_group=None, start=0, limit=10):
|
|||||||
child_groups = ", ".join(['"' + i[0] + '"' for i in get_child_groups(product_group)])
|
child_groups = ", ".join(['"' + i[0] + '"' for i in get_child_groups(product_group)])
|
||||||
|
|
||||||
# base query
|
# base query
|
||||||
query = """select name, item_name, page_name, website_image, item_group,
|
query = """select name, item_name, page_name, website_image, thumbnail, item_group,
|
||||||
web_long_description as website_description,
|
web_long_description as website_description,
|
||||||
concat(parent_website_route, "/", page_name) as route
|
concat(parent_website_route, "/", page_name) as route
|
||||||
from `tabItem`
|
from `tabItem`
|
||||||
where show_in_website = 1
|
where show_in_website = 1
|
||||||
|
and (variant_of = '' or variant_of is null)
|
||||||
and (item_group in (%s)
|
and (item_group in (%s)
|
||||||
or name in (select parent from `tabWebsite Item Group` where item_group in (%s)))
|
or name in (select parent from `tabWebsite Item Group` where item_group in (%s)))
|
||||||
""" % (child_groups, child_groups)
|
""" % (child_groups, child_groups)
|
||||||
|
@ -143,7 +143,7 @@ def guess_territory():
|
|||||||
def decorate_quotation_doc(doc):
|
def decorate_quotation_doc(doc):
|
||||||
for d in doc.get("items", []):
|
for d in doc.get("items", []):
|
||||||
d.update(frappe.db.get_value("Item", d.item_code,
|
d.update(frappe.db.get_value("Item", d.item_code,
|
||||||
["website_image", "description", "page_name"], as_dict=True))
|
["thumbnail", "website_image", "description", "page_name"], as_dict=True))
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
@ -1902,6 +1902,28 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"fieldname": "thumbnail",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"label": "Thumbnail",
|
||||||
|
"no_copy": 0,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"read_only": 1,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
|
import json
|
||||||
from frappe import msgprint, _
|
from frappe import msgprint, _
|
||||||
from frappe.utils import cstr, flt, cint, getdate, now_datetime, formatdate
|
from frappe.utils import cstr, flt, cint, getdate, now_datetime, formatdate
|
||||||
from frappe.website.website_generator import WebsiteGenerator
|
from frappe.website.website_generator import WebsiteGenerator
|
||||||
@ -65,6 +66,7 @@ class Item(WebsiteGenerator):
|
|||||||
self.validate_has_variants()
|
self.validate_has_variants()
|
||||||
self.validate_attributes()
|
self.validate_attributes()
|
||||||
self.validate_variant_attributes()
|
self.validate_variant_attributes()
|
||||||
|
self.make_thumbnail()
|
||||||
|
|
||||||
if not self.get("__islocal"):
|
if not self.get("__islocal"):
|
||||||
self.old_item_group = frappe.db.get_value(self.doctype, self.name, "item_group")
|
self.old_item_group = frappe.db.get_value(self.doctype, self.name, "item_group")
|
||||||
@ -78,13 +80,64 @@ class Item(WebsiteGenerator):
|
|||||||
self.update_item_price()
|
self.update_item_price()
|
||||||
self.update_variants()
|
self.update_variants()
|
||||||
|
|
||||||
|
def make_thumbnail(self):
|
||||||
|
"""Make a thumbnail of `website_image`"""
|
||||||
|
if self.website_image and not self.thumbnail:
|
||||||
|
file_doc = frappe.get_doc("File", {
|
||||||
|
"file_url": self.website_image,
|
||||||
|
"attached_to_doctype": "Item",
|
||||||
|
"attached_to_name": self.name
|
||||||
|
})
|
||||||
|
|
||||||
|
if not file_doc:
|
||||||
|
file_doc = frappe.get_doc({
|
||||||
|
"doctype": "File",
|
||||||
|
"file_url": self.website_image,
|
||||||
|
"attached_to_doctype": "Item",
|
||||||
|
"attached_to_name": self.name
|
||||||
|
}).insert()
|
||||||
|
|
||||||
|
if file_doc:
|
||||||
|
self.thumbnail = file_doc.make_thumbnail()
|
||||||
|
|
||||||
def get_context(self, context):
|
def get_context(self, context):
|
||||||
context["parent_groups"] = get_parent_item_groups(self.item_group) + \
|
context.parent_groups = get_parent_item_groups(self.item_group) + \
|
||||||
[{"name": self.name}]
|
[{"name": self.name}]
|
||||||
if self.slideshow:
|
if self.slideshow:
|
||||||
context.update(get_slideshow(self))
|
context.update(get_slideshow(self))
|
||||||
|
|
||||||
context["parents"] = self.get_parents(context)
|
if self.has_variants:
|
||||||
|
attribute_values_available = {}
|
||||||
|
context.attribute_values = {}
|
||||||
|
|
||||||
|
# load variants
|
||||||
|
context.variants = frappe.get_all("Item",
|
||||||
|
filters={"variant_of": self.name, "show_in_website": 1})
|
||||||
|
|
||||||
|
# load attributes
|
||||||
|
for v in context.variants:
|
||||||
|
v.attributes = frappe.get_all("Item Variant Attribute",
|
||||||
|
fields=["attribute", "attribute_value"], filters={"parent": v.name})
|
||||||
|
|
||||||
|
for attr in v.attributes:
|
||||||
|
values = attribute_values_available.setdefault(attr.attribute, [])
|
||||||
|
if attr.attribute_value not in values:
|
||||||
|
values.append(attr.attribute_value)
|
||||||
|
|
||||||
|
# filter attributes, order based on attribute table
|
||||||
|
for attr in self.attributes:
|
||||||
|
values = context.attribute_values.setdefault(attr.attribute, [])
|
||||||
|
|
||||||
|
# get list of values defined (for sequence)
|
||||||
|
for attr_value in frappe.db.get_all("Item Attribute Value",
|
||||||
|
fields=["attribute_value"], filters={"parent": attr.attribute}, order_by="idx asc"):
|
||||||
|
|
||||||
|
if attr_value.attribute_value in attribute_values_available.get(attr.attribute, []):
|
||||||
|
values.append(attr_value.attribute_value)
|
||||||
|
|
||||||
|
context.variant_info = json.dumps(context.variants)
|
||||||
|
|
||||||
|
context.parents = self.get_parents(context)
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@ -30,6 +30,22 @@
|
|||||||
<h4 class="item-price" itemprop="price"></h4>
|
<h4 class="item-price" itemprop="price"></h4>
|
||||||
<div class="item-stock" itemprop="availablity"></div>
|
<div class="item-stock" itemprop="availablity"></div>
|
||||||
<div class="item-cart hide">
|
<div class="item-cart hide">
|
||||||
|
{% if has_variants %}
|
||||||
|
{% for d in attributes %}
|
||||||
|
<div class="item-view-attribute"
|
||||||
|
style="margin-bottom: 10px;">
|
||||||
|
<h6 class="text-muted">{{ _(d.attribute) }}</h6>
|
||||||
|
<select class="form-control"
|
||||||
|
style="max-width: 140px"
|
||||||
|
data-attribute="{{ d.attribute }}">
|
||||||
|
{% for value in attribute_values[d.attribute] %}
|
||||||
|
<option value="{{ value }}">{{ _(value) }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
</select>
|
||||||
<div id="item-add-to-cart">
|
<div id="item-add-to-cart">
|
||||||
<button class="btn btn-primary btn-sm">
|
<button class="btn btn-primary btn-sm">
|
||||||
{{ _("Add to Cart") }}</button>
|
{{ _("Add to Cart") }}</button>
|
||||||
@ -76,13 +92,10 @@
|
|||||||
<script>
|
<script>
|
||||||
{% include "templates/includes/product_page.js" %}
|
{% include "templates/includes/product_page.js" %}
|
||||||
|
|
||||||
$(function() {
|
{% if variant_info %}
|
||||||
if(window.logged_in && getCookie("system_user")==="yes") {
|
window.variant_info = {{ variant_info }};
|
||||||
frappe.has_permission("Item", "{{ name }}", "write", function(r) {
|
{% else %}
|
||||||
frappe.require("/assets/frappe/js/frappe/website/editable.js");
|
window.variant_info = null;
|
||||||
frappe.make_editable($('[itemprop="description"]'), "Item", "{{ name }}", "web_long_description");
|
{% endif %}
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<a class="product-link" href="{{ (route or page_name)|abs_url }}">
|
<a class="product-link" href="{{ (route or page_name)|abs_url }}">
|
||||||
<div class="col-sm-2 col-xs-4 product-image-wrapper">
|
<div class="col-sm-2 col-xs-4 product-image-wrapper">
|
||||||
{{ product_image_square(website_image) }}
|
{{ product_image_square(thumbnail or website_image) }}
|
||||||
<div class="text-ellipsis inline-block small product-text">{{ item_name }}</div>
|
<div class="text-ellipsis inline-block small product-text">{{ item_name }}</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
<div style="height: 120px; overflow: hidden;">
|
<div style="height: 120px; overflow: hidden;">
|
||||||
<a href="{{ (route or page_name)|abs_url }}">
|
<a href="{{ (route or page_name)|abs_url }}">
|
||||||
{%- if website_image -%}
|
{%- if website_image -%}
|
||||||
<img class="product-image" style="width: 80%; margin: auto;" src="{{ website_image|abs_url }}">
|
<img class="product-image" style="width: 80%; margin: auto;" src="{{
|
||||||
|
(thumbnail or website_image)|abs_url }}">
|
||||||
{%- else -%}
|
{%- else -%}
|
||||||
<div style="width: 80%; height: 120px; background-color: #F7FAFC;"></div>
|
<div style="width: 80%; height: 120px; background-color: #F7FAFC;"></div>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// License: GNU General Public License v3. See license.txt
|
// License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
frappe.ready(function() {
|
frappe.ready(function() {
|
||||||
var item_code = $('[itemscope] [itemprop="productID"]').text().trim();
|
window.item_code = $('[itemscope] [itemprop="productID"]').text().trim();
|
||||||
var qty = 0;
|
var qty = 0;
|
||||||
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
@ -12,7 +12,6 @@ frappe.ready(function() {
|
|||||||
item_code: "{{ name }}"
|
item_code: "{{ name }}"
|
||||||
},
|
},
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
console.log(r.message);
|
|
||||||
$(".item-cart").toggleClass("hide", !!!r.message.price);
|
$(".item-cart").toggleClass("hide", !!!r.message.price);
|
||||||
if(r.message && r.message.price) {
|
if(r.message && r.message.price) {
|
||||||
$(".item-price")
|
$(".item-price")
|
||||||
@ -38,7 +37,7 @@ frappe.ready(function() {
|
|||||||
|
|
||||||
$("#item-add-to-cart button").on("click", function() {
|
$("#item-add-to-cart button").on("click", function() {
|
||||||
shopping_cart.update_cart({
|
shopping_cart.update_cart({
|
||||||
item_code: item_code,
|
item_code: get_item_code(),
|
||||||
qty: 1,
|
qty: 1,
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
if(!r.exc) {
|
if(!r.exc) {
|
||||||
@ -52,7 +51,7 @@ frappe.ready(function() {
|
|||||||
|
|
||||||
$("#item-update-cart button").on("click", function() {
|
$("#item-update-cart button").on("click", function() {
|
||||||
shopping_cart.update_cart({
|
shopping_cart.update_cart({
|
||||||
item_code: item_code,
|
item_code: get_item_code(),
|
||||||
qty: $("#item-update-cart input").val(),
|
qty: $("#item-update-cart input").val(),
|
||||||
btn: this,
|
btn: this,
|
||||||
callback: function(r) {
|
callback: function(r) {
|
||||||
@ -64,11 +63,6 @@ frappe.ready(function() {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if(localStorage && localStorage.getItem("pending_add_to_cart") && full_name) {
|
|
||||||
localStorage.removeItem("pending_add_to_cart");
|
|
||||||
$("#item-add-to-cart button").trigger("click");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var toggle_update_cart = function(qty) {
|
var toggle_update_cart = function(qty) {
|
||||||
@ -77,3 +71,29 @@ var toggle_update_cart = function(qty) {
|
|||||||
.toggle(qty ? true : false)
|
.toggle(qty ? true : false)
|
||||||
.find("input").val(qty);
|
.find("input").val(qty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_item_code() {
|
||||||
|
if(window.variant_info) {
|
||||||
|
attributes = {};
|
||||||
|
$('[itemscope]').find(".item-view-attribute select").each(function() {
|
||||||
|
attributes[$(this).attr('data-attribute')] = $(this).val();
|
||||||
|
});
|
||||||
|
for(var i in variant_info) {
|
||||||
|
var variant = variant_info[i];
|
||||||
|
var match = true;
|
||||||
|
for(var j in variant.attributes) {
|
||||||
|
if(attributes[variant.attributes[j].attribute]
|
||||||
|
!= variant.attributes[j].attribute_value) {
|
||||||
|
match = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(match) {
|
||||||
|
return variant.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw "Unable to match variant";
|
||||||
|
} else {
|
||||||
|
return item_code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -12,9 +12,9 @@ no_sitemap = 1
|
|||||||
@frappe.whitelist(allow_guest=True)
|
@frappe.whitelist(allow_guest=True)
|
||||||
def get_product_list(search=None, start=0, limit=10):
|
def get_product_list(search=None, start=0, limit=10):
|
||||||
# base query
|
# base query
|
||||||
query = """select name, item_name, page_name, website_image, item_group,
|
query = """select name, item_name, page_name, website_image, thumbnail, item_group,
|
||||||
web_long_description as website_description, parent_website_route
|
web_long_description as website_description, parent_website_route
|
||||||
from `tabItem` where show_in_website = 1"""
|
from `tabItem` where show_in_website = 1 and (variant_of is null or variant_of = '')"""
|
||||||
|
|
||||||
# search term condition
|
# search term condition
|
||||||
if search:
|
if search:
|
||||||
|
@ -4,11 +4,28 @@
|
|||||||
{% include 'controllers/js/contact_address_common.js' %};
|
{% include 'controllers/js/contact_address_common.js' %};
|
||||||
|
|
||||||
cur_frm.email_field = "email_id";
|
cur_frm.email_field = "email_id";
|
||||||
frappe.ui.form.on("Contact", "validate", function(frm) {
|
frappe.ui.form.on("Contact", {
|
||||||
|
refresh: function(frm) {
|
||||||
|
if(!frm.doc.user && !frm.is_new() && frm.perm[0].write) {
|
||||||
|
frm.add_custom_button(__("Invite as User"), function() {
|
||||||
|
frappe.call({
|
||||||
|
method: "erpnext.utilities.doctype.contact.contact.invite_user",
|
||||||
|
args: {
|
||||||
|
contact: frm.doc.name
|
||||||
|
},
|
||||||
|
callback: function(r) {
|
||||||
|
frm.set_value("user", r.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
validate: function(frm) {
|
||||||
// clear linked customer / supplier / sales partner on saving...
|
// clear linked customer / supplier / sales partner on saving...
|
||||||
$.each(["Customer", "Supplier", "Sales Partner"], function(i, doctype) {
|
$.each(["Customer", "Supplier", "Sales Partner"], function(i, doctype) {
|
||||||
var name = frm.doc[doctype.toLowerCase().replace(/ /g, "_")];
|
var name = frm.doc[doctype.toLowerCase().replace(/ /g, "_")];
|
||||||
if(name && locals[doctype] && locals[doctype][name])
|
if(name && locals[doctype] && locals[doctype][name])
|
||||||
frappe.model.remove_from_locals(doctype, name);
|
frappe.model.remove_from_locals(doctype, name);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
@ -76,6 +76,30 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"fieldname": "email_id",
|
||||||
|
"fieldtype": "Data",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"label": "Email Id",
|
||||||
|
"no_copy": 0,
|
||||||
|
"oldfieldname": "email_id",
|
||||||
|
"oldfieldtype": "Data",
|
||||||
|
"options": "Email",
|
||||||
|
"permlevel": 0,
|
||||||
|
"print_hide": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 1,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -120,30 +144,6 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"allow_on_submit": 0,
|
|
||||||
"bold": 0,
|
|
||||||
"collapsible": 0,
|
|
||||||
"fieldname": "email_id",
|
|
||||||
"fieldtype": "Data",
|
|
||||||
"hidden": 0,
|
|
||||||
"ignore_user_permissions": 0,
|
|
||||||
"in_filter": 0,
|
|
||||||
"in_list_view": 0,
|
|
||||||
"label": "Email Id",
|
|
||||||
"no_copy": 0,
|
|
||||||
"oldfieldname": "email_id",
|
|
||||||
"oldfieldtype": "Data",
|
|
||||||
"options": "Email",
|
|
||||||
"permlevel": 0,
|
|
||||||
"print_hide": 0,
|
|
||||||
"read_only": 0,
|
|
||||||
"report_hide": 0,
|
|
||||||
"reqd": 0,
|
|
||||||
"search_index": 1,
|
|
||||||
"set_only_once": 0,
|
|
||||||
"unique": 0
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -189,6 +189,29 @@
|
|||||||
"set_only_once": 0,
|
"set_only_once": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"fieldname": "user",
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"label": "User Id",
|
||||||
|
"no_copy": 0,
|
||||||
|
"options": "User",
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_on_submit": 0,
|
"allow_on_submit": 0,
|
||||||
"bold": 0,
|
"bold": 0,
|
||||||
@ -471,7 +494,7 @@
|
|||||||
"is_submittable": 0,
|
"is_submittable": 0,
|
||||||
"issingle": 0,
|
"issingle": 0,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"modified": "2015-10-02 07:38:42.365280",
|
"modified": "2015-10-07 00:38:08.152183",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Utilities",
|
"module": "Utilities",
|
||||||
"name": "Contact",
|
"name": "Contact",
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import cstr, extract_email_id
|
from frappe.utils import cstr
|
||||||
|
|
||||||
from erpnext.controllers.status_updater import StatusUpdater
|
from erpnext.controllers.status_updater import StatusUpdater
|
||||||
|
|
||||||
@ -22,6 +22,11 @@ class Contact(StatusUpdater):
|
|||||||
def validate(self):
|
def validate(self):
|
||||||
self.set_status()
|
self.set_status()
|
||||||
self.validate_primary_contact()
|
self.validate_primary_contact()
|
||||||
|
self.set_user()
|
||||||
|
|
||||||
|
def set_user(self):
|
||||||
|
if not self.user and self.email_id:
|
||||||
|
self.user = frappe.db.get_value("User", {"email": self.email_id})
|
||||||
|
|
||||||
def validate_primary_contact(self):
|
def validate_primary_contact(self):
|
||||||
if self.is_primary_contact == 1:
|
if self.is_primary_contact == 1:
|
||||||
@ -53,6 +58,21 @@ class Contact(StatusUpdater):
|
|||||||
frappe.db.sql("""update `tabIssue` set contact='' where contact=%s""",
|
frappe.db.sql("""update `tabIssue` set contact='' where contact=%s""",
|
||||||
self.name)
|
self.name)
|
||||||
|
|
||||||
|
@frappe.whitelist()
|
||||||
|
def invite_user(contact):
|
||||||
|
contact = frappe.get_doc("Contact", contact)
|
||||||
|
if contact.has_permission("write"):
|
||||||
|
user = frappe.get_doc({
|
||||||
|
"doctype": "User",
|
||||||
|
"first_name": contact.first_name,
|
||||||
|
"last_name": contact.last_name,
|
||||||
|
"email": contact.email_id,
|
||||||
|
"user_type": "Website User",
|
||||||
|
"send_welcome_email": 1
|
||||||
|
}).insert(ignore_permissions = True)
|
||||||
|
|
||||||
|
return user.name
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_contact_details(contact):
|
def get_contact_details(contact):
|
||||||
contact = frappe.get_doc("Contact", contact)
|
contact = frappe.get_doc("Contact", contact)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user