brotherton-erpnext/erpnext/patches/v12_0/stock_entry_enhancements.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.7 KiB
Python
Raw Normal View History

# 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.custom.doctype.custom_field.custom_field import create_custom_fields
def execute():
2019-03-15 08:28:14 +00:00
create_stock_entry_types()
2019-03-15 08:28:14 +00:00
company = frappe.db.get_value("Company", {'country': 'India'}, 'name')
if company:
add_gst_hsn_code_field()
def create_stock_entry_types():
2019-03-15 08:28:14 +00:00
frappe.reload_doc('stock', 'doctype', 'stock_entry_type')
frappe.reload_doc('stock', 'doctype', 'stock_entry')
2019-03-15 08:28:14 +00:00
for purpose in ["Material Issue", "Material Receipt", "Material Transfer",
"Material Transfer for Manufacture", "Material Consumption for Manufacture", "Manufacture",
"Repack", "Send to Subcontractor"]:
2019-03-15 08:28:14 +00:00
ste_type = frappe.get_doc({
'doctype': 'Stock Entry Type',
'name': purpose,
'purpose': purpose
})
2019-03-15 08:28:14 +00:00
try:
ste_type.insert()
except frappe.DuplicateEntryError:
pass
frappe.db.sql(" UPDATE `tabStock Entry` set purpose = 'Send to Subcontractor' where purpose = 'Subcontract'")
2019-03-15 08:28:14 +00:00
frappe.db.sql(" UPDATE `tabStock Entry` set stock_entry_type = purpose ")
def add_gst_hsn_code_field():
2019-03-15 08:28:14 +00:00
custom_fields = {
'Stock Entry Detail': [dict(fieldname='gst_hsn_code', label='HSN/SAC',
fieldtype='Data', fetch_from='item_code.gst_hsn_code',
insert_after='description', allow_on_submit=1, print_hide=0)]
}
create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=True)
frappe.db.sql(""" update `tabStock Entry Detail`, `tabItem`
SET
`tabStock Entry Detail`.gst_hsn_code = `tabItem`.gst_hsn_code
Where
`tabItem`.name = `tabStock Entry Detail`.item_code and `tabItem`.gst_hsn_code is not null
""")