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

70 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
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()
2022-03-28 13:22:46 +00:00
company = frappe.db.get_value("Company", {"country": "India"}, "name")
2019-03-15 08:28:14 +00:00
if company:
add_gst_hsn_code_field()
2022-03-28 13:22:46 +00:00
def create_stock_entry_types():
2022-03-28 13:22:46 +00:00
frappe.reload_doc("stock", "doctype", "stock_entry_type")
frappe.reload_doc("stock", "doctype", "stock_entry")
2022-03-28 13:22:46 +00:00
for purpose in [
"Material Issue",
"Material Receipt",
"Material Transfer",
"Material Transfer for Manufacture",
"Material Consumption for Manufacture",
"Manufacture",
"Repack",
"Send to Subcontractor",
]:
2022-03-28 13:22:46 +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
2022-03-28 13:22:46 +00:00
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 ")
2022-03-28 13:22:46 +00:00
def add_gst_hsn_code_field():
2019-03-15 08:28:14 +00:00
custom_fields = {
2022-03-28 13:22:46 +00:00
"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,
)
]
2019-03-15 08:28:14 +00:00
}
2022-03-28 13:22:46 +00:00
create_custom_fields(custom_fields, ignore_validate=frappe.flags.in_patch, update=True)
2019-03-15 08:28:14 +00:00
2022-03-28 13:22:46 +00:00
frappe.db.sql(
""" update `tabStock Entry Detail`, `tabItem`
2019-03-15 08:28:14 +00:00
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
2022-03-28 13:22:46 +00:00
"""
)