Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
revant committed Jul 2, 2016
2 parents abfc73a + 85ffe1a commit 29637e4
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 14 deletions.
2 changes: 1 addition & 1 deletion kiratplastics_erpnext/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.0'
__version__ = '1.3.1'
4 changes: 2 additions & 2 deletions kiratplastics_erpnext/fixtures/custom_script.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"docstatus": 0,
"doctype": "Custom Script",
"dt": "Sales Invoice",
"modified": "2016-06-06 17:47:34.476095",
"modified": "2016-07-01 22:02:04.627463",
"name": "Sales Invoice-Client",
"script": "frappe.ui.form.on(\"Sales Invoice Item\", \"rate\", function(frm, cdt, cdn) {\n var sii = locals[cdt][cdn];\n if ((frm.doc.kirat_invoice_type != \"Invoice for Sample\") && (frm.doc.kirat_invoice_type != \"Challan\")) {\n if (sii.rate == 0.0) {\n msgprint(\"Rate cannot be zero for invoices other than Sample and Challan.\");\n }\n }\n});\n\nfrappe.ui.form.on(\"Sales Invoice Item\", \"kirat_excise_price\", function(frm, cdt, cdn) { \n cur_frm.cscript.calculate_item_values();\n refresh_field(\"items\"); //This updates excise duty amount in the dialog when the excise rate is changed.\n});\n\n//Toggle readonly for Customer and Chapter Head depending on whether items exist.\nfrappe.ui.form.on(\"Sales Invoice Item\", \"items_add\", function(frm, cdt, cdn) {\n set_customer_readonly(frm);\n set_chapter_head_readonly(frm);\n set_invoice_type_and_series_readonly(frm);\n set_excise_price_readonly(frm);\n});\n\nfrappe.ui.form.on(\"Sales Invoice Item\", \"items_remove\", function(frm) {\n set_customer_readonly(frm);\n set_chapter_head_readonly(frm);\n set_invoice_type_and_series_readonly(frm);\n});\nfrappe.ui.form.on(\"Sales Invoice\", \"refresh\", function(frm) { \n set_excise_chapter_filter(frm);\n make_taxes_unsortable(frm);\n set_item_filter_query(frm);\n set_invoice_type_and_series_readonly(frm);\n set_chapter_head_readonly(frm);\n set_customer_readonly(frm);\n //set_naming_series_and_price_list(frm);\n});\n\nfrappe.ui.form.on(\"Sales Invoice\", \"onload\", function(frm) {\n make_taxes_unsortable(frm);\n get_company_account(frm); //Load excise account from settings and keep in global var for 1.\n get_zero_price_list(frm); //Load zero price list name from settings for 2\n set_excise_price_readonly(frm);\n});\n\n// Add Excise Row to Taxes and Charges\nfrappe.ui.form.on(\"Sales Invoice\", \"validate\", function(frm) {\n inject_excise_row_and_append_taxes(frm);\n});\n\nfrappe.ui.form.on(\"Sales Invoice\", \"kirat_invoice_type\", function(frm) {\n set_naming_series_and_price_list(frm);\n});\n\nfrappe.ui.form.on(\"Sales Invoice\", \"kirat_excise_chapter_head\", function(frm) {\n frappe.model.with_doc(\"Excise Chapter\", frm.doc.kirat_excise_chapter_head, function() { \n var ec = frappe.model.get_doc(\"Excise Chapter\", frm.doc.kirat_excise_chapter_head);\n frm.set_value(\"kirat_excise_chapter_name\", ec.excise_chapter_name);\n frm.set_value(\"kirat_excise_chapter_rate\", ec.rate_of_duty);\n });\n});\n\nfrappe.ui.form.on(\"Sales Invoice\", \"customer\", function(frm) {\n frappe.model.with_doc(\"Customer\", frm.doc.customer, function() { \n var cu = frappe.model.get_doc(\"Customer\", frm.doc.customer);\n frm.set_value(\"kirat_cust_ecc_no\", cu.kirat_ecc_no);\n frm.set_value(\"kirat_cust_cst_lst_no\", cu.kirat_cst_lst_no);\n frm.set_value(\"kirat_cust_cst_lst_date\", cu.kirat_cst_lst_date);\n //set_naming_series_and_price_list(frm);\n });\n});\n\ncur_frm.cscript.customer = function() {\n var me = this;\n if(this.frm.updating_party_details) return;\n\n erpnext.utils.get_party_details(this.frm,\n \"erpnext.accounts.party.get_party_details\", {\n posting_date: this.frm.doc.posting_date,\n party: this.frm.doc.customer,\n party_type: \"Customer\",\n account: this.frm.doc.debit_to,\n price_list: this.frm.doc.selling_price_list,\n }, function() {\n me.apply_pricing_rule();\n set_naming_series_and_price_list(cur_frm);\n })\n}\n\n//Replaces calculation of item value\ncur_frm.cscript.calculate_item_values = function() { \n var me = this;\n if (!this.discount_amount_applied) {\n $.each(this.frm.doc[\"items\"] || [], function(i, item) {\n frappe.model.round_floats_in(item);\n item.net_rate = item.rate;\n item.amount = flt(item.rate * item.qty, precision(\"amount\", item));\n item.net_amount = item.amount;\n item.item_tax_amount = 0.0;\n calculate_excise_duty_amount(item);\n me.set_in_company_currency(item, [\"price_list_rate\", \"rate\", \"amount\", \"net_rate\", \"net_amount\"]);\n });\n }\n}\n",
"script": "\n\nfrappe.ui.form.on(\"Sales Invoice Item\", \"rate\", function(frm, cdt, cdn) {\n var sii = locals[cdt][cdn];\n if ((frm.doc.kirat_invoice_type != \"Invoice for Sample\") && (frm.doc.kirat_invoice_type != \"Challan\")) {\n if (sii.rate == 0.0) {\n msgprint(\"Rate cannot be zero for invoices other than Sample and Challan.\");\n }\n }\n});\n\nfrappe.ui.form.on(\"Sales Invoice Item\", \"kirat_excise_price\", function(frm, cdt, cdn) { \n cur_frm.cscript.calculate_item_values();\n refresh_field(\"items\"); //This updates excise duty amount in the dialog when the excise rate is changed.\n});\n\n//Toggle readonly for Customer and Chapter Head depending on whether items exist.\nfrappe.ui.form.on(\"Sales Invoice Item\", \"items_add\", function(frm, cdt, cdn) {\n set_customer_readonly(frm);\n set_chapter_head_readonly(frm);\n set_invoice_type_and_series_readonly(frm);\n set_excise_price_readonly(frm);\n});\n\nfrappe.ui.form.on(\"Sales Invoice Item\", \"items_remove\", function(frm) {\n set_customer_readonly(frm);\n set_chapter_head_readonly(frm);\n set_invoice_type_and_series_readonly(frm);\n});\nfrappe.ui.form.on(\"Sales Invoice\", \"refresh\", function(frm) { \n set_excise_chapter_filter(frm);\n make_taxes_unsortable(frm);\n set_invoice_type_and_series_readonly(frm);\n set_chapter_head_readonly(frm);\n set_customer_readonly(frm);\n set_item_filter_query(frm);\n});\n\nfrappe.ui.form.on(\"Sales Invoice\", \"onload\", function(frm) {\n make_taxes_unsortable(frm);\n get_company_account(frm); //Load excise account from settings and keep in global var for 1.\n get_zero_price_list(frm); //Load zero price list name from settings for 2\n set_excise_price_readonly(frm);\n});\n\n// Add Excise Row to Taxes and Charges\nfrappe.ui.form.on(\"Sales Invoice\", \"validate\", function(frm) {\n inject_excise_row_and_append_taxes(frm);\n});\n\nfrappe.ui.form.on(\"Sales Invoice\", \"kirat_invoice_type\", function(frm) {\n set_naming_series_and_price_list(frm);\n});\n\nfrappe.ui.form.on(\"Sales Invoice\", \"kirat_excise_chapter_head\", function(frm) {\n frappe.model.with_doc(\"Excise Chapter\", frm.doc.kirat_excise_chapter_head, function() { \n var ec = frappe.model.get_doc(\"Excise Chapter\", frm.doc.kirat_excise_chapter_head);\n frm.set_value(\"kirat_excise_chapter_name\", ec.excise_chapter_name);\n frm.set_value(\"kirat_excise_chapter_rate\", ec.rate_of_duty);\n });\n});\n\nfrappe.ui.form.on(\"Sales Invoice\", \"customer\", function(frm) {\n frappe.model.with_doc(\"Customer\", frm.doc.customer, function() { \n var cu = frappe.model.get_doc(\"Customer\", frm.doc.customer);\n frm.set_value(\"kirat_cust_ecc_no\", cu.kirat_ecc_no);\n frm.set_value(\"kirat_cust_cst_lst_no\", cu.kirat_cst_lst_no);\n frm.set_value(\"kirat_cust_cst_lst_date\", cu.kirat_cst_lst_date);\n });\n});\n\ncur_frm.cscript.customer = function() {\n var me = this;\n if(this.frm.updating_party_details) return;\n\n erpnext.utils.get_party_details(this.frm,\n \"erpnext.accounts.party.get_party_details\", {\n posting_date: this.frm.doc.posting_date,\n party: this.frm.doc.customer,\n party_type: \"Customer\",\n account: this.frm.doc.debit_to,\n price_list: this.frm.doc.selling_price_list,\n }, function() {\n me.apply_pricing_rule();\n set_naming_series_and_price_list(cur_frm);\n })\n}\n\n//Replaces calculation of item value\ncur_frm.cscript.calculate_item_values = function() { \n var me = this;\n if (!this.discount_amount_applied) {\n $.each(this.frm.doc[\"items\"] || [], function(i, item) {\n frappe.model.round_floats_in(item);\n item.net_rate = item.rate;\n item.amount = flt(item.rate * item.qty, precision(\"amount\", item));\n item.net_amount = item.amount;\n item.item_tax_amount = 0.0;\n calculate_excise_duty_amount(item);\n me.set_in_company_currency(item, [\"price_list_rate\", \"rate\", \"amount\", \"net_rate\", \"net_amount\"]);\n });\n }\n}\n\n//Prevent duplicate items. \n//Description property isnt added to the json until after the row gets added to the items list\n//OR the line-item form is closed.\nfrappe.ui.form.on(\"Sales Invoice Item\", \"item_code\", function(frm, cdt, cdn) {\n var sii = locals[cdt][cdn];\n for (var i = 0; i < frm.doc.items.length; i++) {\n if ((frm.doc.items[i].item_code == sii.item_code)) {\n if (frm.doc.items[i].hasOwnProperty(\"description\")) {\n msgprint(\"Item \" + sii.item_code + \" has already been added!\");\n sii.item_code = \"\";\n break;\n }\n }\n }\n});",
"script_type": "Client"
},
{
Expand Down
117 changes: 112 additions & 5 deletions kiratplastics_erpnext/kirat_plastics_erpnext/kp_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,121 @@
from frappe import _
from frappe.utils import money_in_words
from erpnext.stock.get_item_details import get_item_details, get_item_code
from erpnext.controllers.queries import get_filters_cond
from frappe.desk.reportview import get_match_cond
from frappe.utils import nowdate
#set_item_filter_qu

def kp_sinv_item_query(doctype, txt, searchfield, start, page_len, filters=None):
kp_filters = filters
filters = {}

conditions = []

x = None

try:
x = frappe.db.sql("""select tabItem.name,tabItem.item_group,
if(length(tabItem.item_name) > 40,
concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name,
if(length(tabItem.description) > 40, \
concat(substr(tabItem.description, 1, 40), "..."), description) as decription
from tabItem INNER JOIN `tabItem Customer Detail` AS B ON tabItem.name = B.parent
where
tabItem.excise_chapter = '{exc}' AND B.customer_name = '{cn}'
and tabItem.docstatus < 2
and tabItem.has_variants=0
and tabItem.disabled=0
and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00')
and (tabItem.`{key}` LIKE %(txt)s
or tabItem.item_group LIKE %(txt)s
or tabItem.item_name LIKE %(txt)s
or tabItem.description LIKE %(txt)s)
{fcond} {mcond}
order by
if(locate(%(_txt)s, tabItem.name), locate(%(_txt)s, tabItem.name), 99999),
if(locate(%(_txt)s, tabItem.item_name), locate(%(_txt)s, tabItem.item_name), 99999),
tabItem.idx desc,
tabItem.name, tabItem.item_name
limit %(start)s, %(page_len)s """.format(key=searchfield,
fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
mcond=get_match_cond(doctype).replace('%', '%%'),
exc=kp_filters.get("excise_chapter"), cn=kp_filters.get("cust_name")), {
"today": nowdate(),
"txt": "%%%s%%" % txt,
"_txt": txt.replace("%", ""),
"start": start,
"page_len": page_len
})
except Exception, e:
frappe.msgprint(e)
else:
return x
# out = item_query(doctype, txt, searchfield, start, page_len, filters)
# return out

# x = frappe.db.sql("""SELECT B.name, A.ref_code, B.item_group, B.item_name, B.description as description
# FROM `tabItem Customer Detail` AS A
# INNER JOIN `tabItem` AS B ON A.parent = B.name
# WHERE A.customer_name = '%s' AND B.excise_chapter = '%s';""" % (filters.get("cust_name"), filters.get("excise_chapter")))

# return x


#Query for filtering items.
def kp_sinv_item_query(doctype, txt, searchfield, start, page_len, filters):
#def kp_sinv_item_query(doctype, txt, searchfield, start, page_len, filters):
# def kp_sinv_item_query(doctype, txt, searchfield, start, page_len, filters=None):
# kp_filters = filters
# filters = {}

# conditions = []
# sql = frappe.db.sql("""select tabItem.name,tabItem.item_group,
# if(length(tabItem.item_name) > 40,
# concat(substr(tabItem.item_name, 1, 40), "..."), item_name) as item_name,
# if(length(tabItem.description) > 40, \
# concat(substr(tabItem.description, 1, 40), "..."), description) as decription
# from tabItem INNER JOIN `tabItem Customer Detail` AS B ON tabItem.name = B.parent
# where
# tabItem.excise_chapter = '{exc}' AND B.customer_name = '{cn}'
# and tabItem.docstatus < 2
# and tabItem.has_variants=0
# and tabItem.disabled=0
# and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00')
# and (tabItem.`{key}` LIKE %(txt)s
# or tabItem.item_group LIKE %(txt)s
# or tabItem.item_name LIKE %(txt)s
# or tabItem.description LIKE %(txt)s)
# {fcond} {mcond}
# order by
# if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
# if(locate(%(_txt)s, item_name), locate(%(_txt)s, item_name), 99999),
# idx desc,
# name, item_name
# limit %(start)s, %(page_len)s """.format(key=searchfield,
# fcond=get_filters_cond(doctype, filters, conditions).replace('%', '%%'),
# mcond=get_match_cond(doctype).replace('%', '%%'),
# exc=kp_filters.get("excise_chapter"), cn=kp_filters.get("cust_name")),
# {
# "today": nowdate(),
# "txt": "%%%s%%" % txt,
# "_txt": txt.replace("%", ""),
# "start": start,
# "page_len": page_len
# })

# frappe.msgprint(sql)

return frappe.db.sql("""SELECT B.name, A.ref_code, B.item_group, B.item_name, B.description as description
FROM `tabItem Customer Detail` AS A
INNER JOIN `tabItem` AS B ON A.parent = B.name
WHERE A.customer_name = '%s' AND B.excise_chapter = '%s';""" % (filters.get("cust_name"), filters.get("excise_chapter")))

# return sql
# out = item_query(doctype, txt, searchfield, start, page_len, filters)
# return out

# x = frappe.db.sql("""SELECT B.name, A.ref_code, B.item_group, B.item_name, B.description as description
# FROM `tabItem Customer Detail` AS A
# INNER JOIN `tabItem` AS B ON A.parent = B.name
# WHERE A.customer_name = '%s' AND B.excise_chapter = '%s';""" % (filters.get("cust_name"), filters.get("excise_chapter")))

# return x

#Retrieve item details.
@frappe.whitelist() #overridden in hooks.py
Expand Down
12 changes: 6 additions & 6 deletions kiratplastics_erpnext/public/js/kp_si.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,10 @@ function inject_excise_row_and_append_taxes(frm) {
}

function set_item_filter_query(frm) {
frm.set_query("item_code", "items", function() {
cur_frm.set_query("item_code", "items", function() {
return {
query: "kiratplastics_erpnext.kirat_plastics_erpnext.kp_api.kp_sinv_item_query",
filters: {
filters: {
"cust_name": frm.doc.customer,
"excise_chapter": frm.doc.kirat_excise_chapter_head
}
Expand Down Expand Up @@ -176,19 +176,19 @@ function set_excise_price_readonly(frm) {
function set_naming_series_and_price_list(frm) {
switch (frm.doc.kirat_invoice_type) {
case "Supplementary Invoice":
frm.set_value("naming_series", "SINV-SUP-");
//frm.set_value("naming_series", "SINV-SUP-");
frm.set_value("selling_price_list", "Standard Selling");
break;
case "Invoice for Sample":
frm.set_value("naming_series", "SINV-SMP-");
//frm.set_value("naming_series", "SINV-SMP-");
frm.set_value("selling_price_list", zero_price_list); //2
break;
case "Challan":
frm.set_value("naming_series", "SINV-CHL-");
//frm.set_value("naming_series", "SINV-CHL-");
frm.set_value("selling_price_list", zero_price_list); //2
break;
default:
frm.set_value("naming_series", "SINV-");
//frm.set_value("naming_series", "SINV-");
frm.set_value("selling_price_list", "Standard Selling");
break;
}
Expand Down

0 comments on commit 29637e4

Please sign in to comment.