updated generators for wip-4.2
This commit is contained in:
@@ -210,7 +210,7 @@
|
|||||||
"icon": "icon-money",
|
"icon": "icon-money",
|
||||||
"idx": 1,
|
"idx": 1,
|
||||||
"in_create": 1,
|
"in_create": 1,
|
||||||
"modified": "2014-06-03 18:27:58.109303",
|
"modified": "2014-06-17 04:30:56.689314",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Accounts",
|
"module": "Accounts",
|
||||||
"name": "Account",
|
"name": "Account",
|
||||||
@@ -288,6 +288,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"amend": 0,
|
"amend": 0,
|
||||||
|
"apply_user_permissions": 0,
|
||||||
"create": 1,
|
"create": 1,
|
||||||
"delete": 1,
|
"delete": 1,
|
||||||
"email": 1,
|
"email": 1,
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ mail_footer = "erpnext.startup.mail_footer"
|
|||||||
on_session_creation = "erpnext.startup.event_handlers.on_session_creation"
|
on_session_creation = "erpnext.startup.event_handlers.on_session_creation"
|
||||||
before_tests = "erpnext.setup.utils.before_tests"
|
before_tests = "erpnext.setup.utils.before_tests"
|
||||||
|
|
||||||
|
website_generators = ["Item Group", "Item", "Sales Partner"]
|
||||||
|
|
||||||
standard_queries = "Customer:erpnext.selling.doctype.customer.customer.get_customer_list"
|
standard_queries = "Customer:erpnext.selling.doctype.customer.customer.get_customer_list"
|
||||||
|
|
||||||
permission_query_conditions = {
|
permission_query_conditions = {
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import frappe
|
|||||||
from frappe.utils.nestedset import NestedSet
|
from frappe.utils.nestedset import NestedSet
|
||||||
from frappe.website.website_generator import WebsiteGenerator
|
from frappe.website.website_generator import WebsiteGenerator
|
||||||
from frappe.website.render import clear_cache
|
from frappe.website.render import clear_cache
|
||||||
|
from frappe.website.doctype.website_slideshow.website_slideshow import get_slideshow
|
||||||
|
|
||||||
|
condition_field = "show_in_website"
|
||||||
|
|
||||||
class ItemGroup(NestedSet, WebsiteGenerator):
|
class ItemGroup(NestedSet, WebsiteGenerator):
|
||||||
nsm_parent_field = 'parent_item_group'
|
nsm_parent_field = 'parent_item_group'
|
||||||
@@ -39,6 +42,53 @@ class ItemGroup(NestedSet, WebsiteGenerator):
|
|||||||
if frappe.db.exists("Item", self.name):
|
if frappe.db.exists("Item", self.name):
|
||||||
frappe.throw(frappe._("An item exists with same name ({0}), please change the item group name or rename the item").format(self.name))
|
frappe.throw(frappe._("An item exists with same name ({0}), please change the item group name or rename the item").format(self.name))
|
||||||
|
|
||||||
|
def get_context(self, context):
|
||||||
|
context.update({
|
||||||
|
"items": get_product_list_for_group(product_group = self.name, limit=100),
|
||||||
|
"parent_groups": get_parent_item_groups(self.name),
|
||||||
|
"title": self.name
|
||||||
|
})
|
||||||
|
|
||||||
|
if self.slideshow:
|
||||||
|
context.update(get_slideshow(self))
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
|
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)])
|
||||||
|
|
||||||
|
# base query
|
||||||
|
query = """select t1.name, t1.item_name, t1.page_name, t1.website_image, t1.item_group,
|
||||||
|
t1.web_long_description as website_description, t2.name as route
|
||||||
|
from `tabItem` t1, `tabWebsite Route` t2
|
||||||
|
where t1.show_in_website = 1 and (item_group in (%s)
|
||||||
|
or t1.name in (select parent from `tabWebsite Item Group` where item_group in (%s)))
|
||||||
|
and t1.name = t2.docname and t2.ref_doctype='Item' """ % (child_groups, child_groups)
|
||||||
|
|
||||||
|
query += """order by t1.weightage desc, t1.modified desc limit %s, %s""" % (start, limit)
|
||||||
|
|
||||||
|
data = frappe.db.sql(query, {"product_group": product_group}, as_dict=1)
|
||||||
|
|
||||||
|
return [get_item_for_list_in_html(r) for r in data]
|
||||||
|
|
||||||
|
def get_child_groups(item_group_name):
|
||||||
|
item_group = frappe.get_doc("Item Group", item_group_name)
|
||||||
|
return frappe.db.sql("""select name
|
||||||
|
from `tabItem Group` where lft>=%(lft)s and rgt<=%(rgt)s
|
||||||
|
and show_in_website = 1""", {"lft": item_group.lft, "rgt": item_group.rgt})
|
||||||
|
|
||||||
|
def get_item_for_list_in_html(context):
|
||||||
|
return frappe.get_template("templates/includes/product_in_grid.html").render(context)
|
||||||
|
|
||||||
|
def get_group_item_count(item_group):
|
||||||
|
child_groups = ", ".join(['"' + i[0] + '"' for i in get_child_groups(item_group)])
|
||||||
|
return frappe.db.sql("""select count(*) from `tabItem`
|
||||||
|
where docstatus = 0 and show_in_website = 1
|
||||||
|
and (item_group in (%s)
|
||||||
|
or name in (select parent from `tabWebsite Item Group`
|
||||||
|
where item_group in (%s))) """ % (child_groups, child_groups))[0][0]
|
||||||
|
|
||||||
|
|
||||||
def get_parent_item_groups(item_group_name):
|
def get_parent_item_groups(item_group_name):
|
||||||
item_group = frappe.get_doc("Item Group", item_group_name)
|
item_group = frappe.get_doc("Item Group", item_group_name)
|
||||||
return frappe.db.sql("""select name, page_name from `tabItem Group`
|
return frappe.db.sql("""select name, page_name from `tabItem Group`
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import cint, cstr, filter_strip_join
|
from frappe.utils import cstr, filter_strip_join
|
||||||
from frappe.website.website_generator import WebsiteGenerator
|
from frappe.website.website_generator import WebsiteGenerator
|
||||||
|
|
||||||
class SalesPartner(WebsiteGenerator):
|
class SalesPartner(WebsiteGenerator):
|
||||||
@@ -25,3 +25,21 @@ class SalesPartner(WebsiteGenerator):
|
|||||||
|
|
||||||
def get_page_title(self):
|
def get_page_title(self):
|
||||||
return self.partner_name
|
return self.partner_name
|
||||||
|
|
||||||
|
def get_context(self, context):
|
||||||
|
address = frappe.db.get_value("Address",
|
||||||
|
{"sales_partner": self.name, "is_primary_address": 1},
|
||||||
|
"*", as_dict=True)
|
||||||
|
if address:
|
||||||
|
city_state = ", ".join(filter(None, [address.city, address.state]))
|
||||||
|
address_rows = [address.address_line1, address.address_line2,
|
||||||
|
city_state, address.pincode, address.country]
|
||||||
|
|
||||||
|
context.update({
|
||||||
|
"email": address.email_id,
|
||||||
|
"partner_address": filter_strip_join(address_rows, "\n<br>"),
|
||||||
|
"phone": filter_strip_join(cstr(address.phone).split(","), "\n<br>")
|
||||||
|
})
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,14 @@ import frappe
|
|||||||
from frappe import msgprint, _
|
from frappe import msgprint, _
|
||||||
from frappe.utils import cstr, flt, getdate, now_datetime, formatdate
|
from frappe.utils import cstr, flt, getdate, now_datetime, formatdate
|
||||||
from frappe.website.website_generator import WebsiteGenerator
|
from frappe.website.website_generator import WebsiteGenerator
|
||||||
from erpnext.setup.doctype.item_group.item_group import invalidate_cache_for
|
from erpnext.setup.doctype.item_group.item_group import invalidate_cache_for, get_parent_item_groups
|
||||||
from frappe.website.render import clear_cache
|
from frappe.website.render import clear_cache
|
||||||
|
from frappe.website.doctype.website_slideshow.website_slideshow import get_slideshow
|
||||||
|
|
||||||
class WarehouseNotSet(frappe.ValidationError): pass
|
class WarehouseNotSet(frappe.ValidationError): pass
|
||||||
|
|
||||||
|
condition_field = "show_in_website"
|
||||||
|
|
||||||
class Item(WebsiteGenerator):
|
class Item(WebsiteGenerator):
|
||||||
def onload(self):
|
def onload(self):
|
||||||
super(Item, self).onload()
|
super(Item, self).onload()
|
||||||
@@ -55,6 +58,14 @@ class Item(WebsiteGenerator):
|
|||||||
self.validate_name_with_item_group()
|
self.validate_name_with_item_group()
|
||||||
self.update_item_price()
|
self.update_item_price()
|
||||||
|
|
||||||
|
def get_context(self, context):
|
||||||
|
context["parent_groups"] = get_parent_item_groups(self.item_group) + \
|
||||||
|
[{"name": self.name}]
|
||||||
|
if self.slideshow:
|
||||||
|
context.update(get_slideshow(self))
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
def check_warehouse_is_set_for_stock_item(self):
|
def check_warehouse_is_set_for_stock_item(self):
|
||||||
if self.is_stock_item=="Yes" and not self.default_warehouse:
|
if self.is_stock_item=="Yes" and not self.default_warehouse:
|
||||||
frappe.msgprint(_("Default Warehouse is mandatory for stock Item."),
|
frappe.msgprint(_("Default Warehouse is mandatory for stock Item."),
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
|
||||||
# License: GNU General Public License v3. See license.txt
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import frappe
|
|
||||||
from erpnext.setup.doctype.item_group.item_group import get_parent_item_groups
|
|
||||||
from frappe.website.doctype.website_slideshow.website_slideshow import get_slideshow
|
|
||||||
|
|
||||||
doctype = "Item"
|
|
||||||
condition_field = "show_in_website"
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
item_context = context.doc.as_dict()
|
|
||||||
item_context["parent_groups"] = get_parent_item_groups(context.doc.item_group) + \
|
|
||||||
[{"name":context.doc.name}]
|
|
||||||
if context.doc.slideshow:
|
|
||||||
item_context.update(get_slideshow(context.doc))
|
|
||||||
|
|
||||||
return item_context
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
|
||||||
# License: GNU General Public License v3. See license.txt
|
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
|
||||||
|
|
||||||
import frappe
|
|
||||||
from frappe.website.doctype.website_slideshow.website_slideshow import get_slideshow
|
|
||||||
from erpnext.setup.doctype.item_group.item_group import get_parent_item_groups
|
|
||||||
|
|
||||||
doctype = "Item Group"
|
|
||||||
condition_field = "show_in_website"
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
item_group_context = context.doc.as_dict()
|
|
||||||
item_group_context.update({
|
|
||||||
"items": get_product_list_for_group(product_group = context.docname, limit=100),
|
|
||||||
"parent_groups": get_parent_item_groups(context.docname),
|
|
||||||
"title": context.docname
|
|
||||||
})
|
|
||||||
|
|
||||||
if context.doc.slideshow:
|
|
||||||
item_group_context.update(get_slideshow(context.doc))
|
|
||||||
|
|
||||||
return item_group_context
|
|
||||||
|
|
||||||
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)])
|
|
||||||
|
|
||||||
# base query
|
|
||||||
query = """select t1.name, t1.item_name, t1.page_name, t1.website_image, t1.item_group,
|
|
||||||
t1.web_long_description as website_description, t2.name as route
|
|
||||||
from `tabItem` t1, `tabWebsite Route` t2
|
|
||||||
where t1.show_in_website = 1 and (item_group in (%s)
|
|
||||||
or t1.name in (select parent from `tabWebsite Item Group` where item_group in (%s)))
|
|
||||||
and t1.name = t2.docname and t2.ref_doctype='Item' """ % (child_groups, child_groups)
|
|
||||||
|
|
||||||
query += """order by t1.weightage desc, t1.modified desc limit %s, %s""" % (start, limit)
|
|
||||||
|
|
||||||
data = frappe.db.sql(query, {"product_group": product_group}, as_dict=1)
|
|
||||||
|
|
||||||
return [get_item_for_list_in_html(r) for r in data]
|
|
||||||
|
|
||||||
def get_child_groups(item_group_name):
|
|
||||||
item_group = frappe.get_doc("Item Group", item_group_name)
|
|
||||||
return frappe.db.sql("""select name
|
|
||||||
from `tabItem Group` where lft>=%(lft)s and rgt<=%(rgt)s
|
|
||||||
and show_in_website = 1""", {"lft": item_group.lft, "rgt": item_group.rgt})
|
|
||||||
|
|
||||||
def get_item_for_list_in_html(context):
|
|
||||||
return frappe.get_template("templates/includes/product_in_grid.html").render(context)
|
|
||||||
|
|
||||||
def get_group_item_count(item_group):
|
|
||||||
child_groups = ", ".join(['"' + i[0] + '"' for i in get_child_groups(item_group)])
|
|
||||||
return frappe.db.sql("""select count(*) from `tabItem`
|
|
||||||
where docstatus = 0 and show_in_website = 1
|
|
||||||
and (item_group in (%s)
|
|
||||||
or name in (select parent from `tabWebsite Item Group`
|
|
||||||
where item_group in (%s))) """ % (child_groups, child_groups))[0][0]
|
|
||||||
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
# Copyright (c) 2013, Web Notes 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 filter_strip_join
|
|
||||||
|
|
||||||
doctype = "Sales Partner"
|
|
||||||
condition_field = "show_in_website"
|
|
||||||
|
|
||||||
def get_context(context):
|
|
||||||
partner_context = context.doc.as_dict()
|
|
||||||
|
|
||||||
address = frappe.db.get_value("Address",
|
|
||||||
{"sales_partner": context.doc.name, "is_primary_address": 1},
|
|
||||||
"*", as_dict=True)
|
|
||||||
if address:
|
|
||||||
city_state = ", ".join(filter(None, [address.city, address.state]))
|
|
||||||
address_rows = [address.address_line1, address.address_line2,
|
|
||||||
city_state, address.pincode, address.country]
|
|
||||||
|
|
||||||
partner_context.update({
|
|
||||||
"email": address.email_id,
|
|
||||||
"partner_address": filter_strip_join(address_rows, "\n<br>"),
|
|
||||||
"phone": filter_strip_join(cstr(address.phone).split(","), "\n<br>")
|
|
||||||
})
|
|
||||||
|
|
||||||
return partner_context
|
|
||||||
Reference in New Issue
Block a user