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 9, 2016
2 parents 29637e4 + 25fca7e commit 273d597
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 110 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.1'
__version__ = '1.4.0'
49 changes: 42 additions & 7 deletions kiratplastics_erpnext/fixtures/custom_field.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"in_list_view": 0,
"insert_after": "parent_website_route",
"label": "Excise",
"modified": "2016-05-21 19:04:09.067652",
"modified": "2016-07-08 15:56:14.844298",
"name": "Item-excise",
"no_copy": 0,
"options": null,
Expand Down Expand Up @@ -193,7 +193,7 @@
"in_list_view": 0,
"insert_after": "excise",
"label": "Excise Chapter",
"modified": "2016-05-21 19:04:09.461064",
"modified": "2016-07-08 15:56:15.719703",
"name": "Item-excise_chapter",
"no_copy": 0,
"options": "Excise Chapter",
Expand Down Expand Up @@ -228,7 +228,7 @@
"in_list_view": 0,
"insert_after": "excise_price",
"label": "",
"modified": "2016-05-21 19:04:10.125637",
"modified": "2016-07-08 15:56:16.419629",
"name": "Item-col_break_excise_1",
"no_copy": 0,
"options": null,
Expand Down Expand Up @@ -256,14 +256,14 @@
"dt": "Item",
"fieldname": "excise_price",
"fieldtype": "Currency",
"hidden": 0,
"hidden": 1,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"insert_after": "excise_chapter",
"label": "Excise Price",
"modified": "2016-05-21 19:04:09.790276",
"modified": "2016-07-08 15:56:16.065567",
"name": "Item-excise_price",
"no_copy": 0,
"options": null,
Expand All @@ -274,7 +274,7 @@
"print_width": null,
"read_only": 0,
"report_hide": 0,
"reqd": 1,
"reqd": 0,
"search_index": 0,
"unique": 0,
"width": null
Expand Down Expand Up @@ -403,7 +403,7 @@
"in_list_view": 0,
"insert_after": "col_break_excise_1",
"label": "Excise Duty Rate",
"modified": "2016-05-21 19:04:10.507552",
"modified": "2016-07-08 15:56:16.789411",
"name": "Item-excise_duty_rate",
"no_copy": 0,
"options": "excise_chapter.rate_of_duty",
Expand Down Expand Up @@ -1188,5 +1188,40 @@
"search_index": 0,
"unique": 0,
"width": null
},
{
"allow_on_submit": 0,
"collapsible": 0,
"collapsible_depends_on": null,
"default": null,
"depends_on": null,
"description": null,
"docstatus": 0,
"doctype": "Custom Field",
"dt": "Item Price",
"fieldname": "kirat_excise_price",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"insert_after": "price_list_rate",
"label": "Excise Price",
"modified": "2016-07-08 23:27:45.981312",
"name": "Item Price-kirat_excise_price",
"no_copy": 0,
"options": null,
"permlevel": 0,
"precision": "3",
"print_hide": 0,
"print_hide_if_no_value": 0,
"print_width": null,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"unique": 0,
"width": null
}
]
60 changes: 47 additions & 13 deletions kiratplastics_erpnext/fixtures/property_setter.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"doctype": "Property Setter",
"doctype_or_field": "DocField",
"field_name": "naming_series",
"modified": "2016-04-21 16:35:46.082820",
"modified": "2016-07-09 11:25:02.641686",
"name": "Sales Invoice-naming_series-default",
"property": "default",
"property_type": "Text",
"value": "SINV-"
"value": "KP16-17/"
},
{
"_assign": null,
Expand All @@ -44,11 +44,11 @@
"doctype": "Property Setter",
"doctype_or_field": "DocField",
"field_name": "naming_series",
"modified": "2016-04-21 16:35:46.089366",
"modified": "2016-07-09 11:25:02.772940",
"name": "Sales Invoice-naming_series-options",
"property": "options",
"property_type": "Text",
"value": "SINV-\nSINV-RET-\nSINV-SUP-\nSINV-SMP-\nSINV-CHL-"
"value": "KP16-17/\nKPX16-17/\nSINV-\nSINV-RET-\nSINV-SUP-\nSINV-SMP-\nSINV-CHL-"
},
{
"_assign": null,
Expand Down Expand Up @@ -957,13 +957,13 @@
"_liked_by": null,
"_user_tags": null,
"default_value": null,
"doc_type": "Item",
"doc_type": "Sales Invoice Item",
"docstatus": 0,
"doctype": "Property Setter",
"doctype_or_field": "DocType",
"field_name": null,
"modified": "2016-05-21 19:04:08.673504",
"name": "Item-read_only_onload",
"modified": "2016-05-25 12:39:42.285287",
"name": "Sales Invoice Item-read_only_onload",
"property": "read_only_onload",
"property_type": "Check",
"value": null
Expand All @@ -974,13 +974,13 @@
"_liked_by": null,
"_user_tags": null,
"default_value": null,
"doc_type": "Sales Invoice Item",
"doc_type": "Sales Invoice",
"docstatus": 0,
"doctype": "Property Setter",
"doctype_or_field": "DocType",
"field_name": null,
"modified": "2016-05-25 12:39:42.285287",
"name": "Sales Invoice Item-read_only_onload",
"modified": "2016-06-06 12:17:18.757959",
"name": "Sales Invoice-read_only_onload",
"property": "read_only_onload",
"property_type": "Check",
"value": null
Expand All @@ -991,13 +991,47 @@
"_liked_by": null,
"_user_tags": null,
"default_value": null,
"doc_type": "Sales Invoice",
"doc_type": "Item Price",
"docstatus": 0,
"doctype": "Property Setter",
"doctype_or_field": "DocType",
"field_name": null,
"modified": "2016-06-06 12:17:18.757959",
"name": "Sales Invoice-read_only_onload",
"modified": "2016-07-08 15:52:33.255602",
"name": "Item Price-sort_order",
"property": "sort_order",
"property_type": "Data",
"value": "ASC"
},
{
"_assign": null,
"_comments": null,
"_liked_by": null,
"_user_tags": null,
"default_value": null,
"doc_type": "Item",
"docstatus": 0,
"doctype": "Property Setter",
"doctype_or_field": "DocType",
"field_name": null,
"modified": "2016-07-08 15:56:14.450657",
"name": "Item-read_only_onload",
"property": "read_only_onload",
"property_type": "Check",
"value": null
},
{
"_assign": null,
"_comments": null,
"_liked_by": null,
"_user_tags": null,
"default_value": null,
"doc_type": "Item Price",
"docstatus": 0,
"doctype": "Property Setter",
"doctype_or_field": "DocType",
"field_name": null,
"modified": "2016-07-08 23:27:45.852870",
"name": "Item Price-read_only_onload",
"property": "read_only_onload",
"property_type": "Check",
"value": null
Expand Down
105 changes: 37 additions & 68 deletions kiratplastics_erpnext/kirat_plastics_erpnext/kp_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

from __future__ import unicode_literals
import frappe
import json
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
Expand Down Expand Up @@ -56,76 +56,11 @@ def kp_sinv_item_query(doctype, txt, searchfield, start, page_len, filters=None)
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=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 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
def kp_get_item_details(args):

#frappe.msgprint(args)
result = get_item_details(args)

item_code = result.get("item_code")
Expand All @@ -137,7 +72,32 @@ def kp_get_item_details(args):
frappe.msgprint(_("Excise Chapter Head not specified for item '%s'!" % (item_code)))

result["kirat_excise_duty_rate"] = frappe.db.get_value("Item", item_code, "excise_duty_rate")
result["kirat_excise_price"] = frappe.db.get_value("Item", item_code, "excise_price")

#160709: Kirat Excise Price now pulled from Item Price doctype.
#Item Price records for Zero price list will not have any excise price.
#Also, ZPL will override the customer's price list when invoice type is Sample or Challan.
#Therefore, case of ZPL, excise price will have to be fetched from the customer's default price list if it exists or standard selling.

#Convert args to dict.
args_json = json.loads(args)
price_list_for_pulling_excise_price = args_json["price_list"] #Longname!

#If Zero Price List, lookup customer's default price list. If not found, use Standard Selling.
if (args_json["price_list"].find("Zero") != -1):
#frappe.msgprint("Zero Rate price list found. Attempting to find default price list to pull excise price from.")
price_list_for_pulling_excise_price = frappe.db.get_value("Customer", args_json["customer"], "default_price_list")
if (not price_list_for_pulling_excise_price) or (price_list_for_pulling_excise_price == ""):
#frappe.msgprint("Default price list not found. Pulling excise price from Standard Selling")
price_list_for_pulling_excise_price = "Standard Selling"

kep = frappe.db.get_value("Item Price", {"price_list": price_list_for_pulling_excise_price, "item_code": item_code}, "kirat_excise_price")

if not kep:
frappe.throw(_("Item '%s' does not have a valid excise price." % (item_code)))

result["kirat_excise_price"] = kep
#result["kirat_excise_price"] = frappe.db.get_value("Item", item_code, "excise_price")


#Calculate final amount.
item_rate = 0.0 #Set either to result[price_list_rate] or result[rate] depending on which is non-zero.
Expand Down Expand Up @@ -196,3 +156,12 @@ def validate_zero_amount_items(self):

if len(zero_rate_items) > 0:
frappe.throw(_("Items with zero rate cannot be added to invoices that are not Invoices for Sample or Challans"))

def validate_zero_excise_price_items(self):
zero_ep_items = []
for itm in self.items:
if not itm.kirat_excise_price or itm.kirat_excise_price == 0.0:
zero_ep_items.append(itm.item_code)

if len(zero_ep_items) > 0:
frappe.throw(_("Items must have valid excise price."))
Loading

0 comments on commit 273d597

Please sign in to comment.