feat: moved slide action functions from onboarding utils to doctypes
This commit is contained in:
parent
195893db0e
commit
3f8c460584
@ -56,3 +56,23 @@ class Supplier(TransactionBase):
|
|||||||
def after_rename(self, olddn, newdn, merge=False):
|
def after_rename(self, olddn, newdn, merge=False):
|
||||||
if frappe.defaults.get_global_default('supp_master_name') == 'Supplier Name':
|
if frappe.defaults.get_global_default('supp_master_name') == 'Supplier Name':
|
||||||
frappe.db.set(self, "supplier_name", newdn)
|
frappe.db.set(self, "supplier_name", newdn)
|
||||||
|
|
||||||
|
def create_onboarding_docs(self, args):
|
||||||
|
defaults = frappe.defaults.get_defaults()
|
||||||
|
for i in range(1, args.get('max_count')):
|
||||||
|
supplier = args.get('supplier_name_' + str(i))
|
||||||
|
if supplier:
|
||||||
|
try:
|
||||||
|
doc = frappe.get_doc({
|
||||||
|
'doctype': self.doctype,
|
||||||
|
'supplier_name': supplier,
|
||||||
|
'supplier_group': _('Local'),
|
||||||
|
'company': defaults.get('company')
|
||||||
|
}).insert()
|
||||||
|
|
||||||
|
if args.get('supplier_email_' + str(i)):
|
||||||
|
from erpnext.selling.doctype.customer.customer import create_contact
|
||||||
|
create_contact(supplier, 'Supplier',
|
||||||
|
doc.name, args.get('supplier_email_' + str(i)))
|
||||||
|
except frappe.NameError:
|
||||||
|
pass
|
@ -204,6 +204,40 @@ class Customer(TransactionBase):
|
|||||||
else:
|
else:
|
||||||
frappe.msgprint(_("Multiple Loyalty Program found for the Customer. Please select manually."))
|
frappe.msgprint(_("Multiple Loyalty Program found for the Customer. Please select manually."))
|
||||||
|
|
||||||
|
def create_onboarding_docs(self, args):
|
||||||
|
defaults = frappe.defaults.get_defaults()
|
||||||
|
for i in range(1, args.get('max_count')):
|
||||||
|
customer = args.get('customer_name_' + str(i))
|
||||||
|
if customer:
|
||||||
|
try:
|
||||||
|
doc = frappe.get_doc({
|
||||||
|
'doctype': self.doctype,
|
||||||
|
'customer_name': customer,
|
||||||
|
'customer_type': 'Company',
|
||||||
|
'customer_group': _('Commercial'),
|
||||||
|
'territory': defaults.get('country'),
|
||||||
|
'company': defaults.get('company')
|
||||||
|
}).insert()
|
||||||
|
|
||||||
|
if args.get('customer_email_' + str(i)):
|
||||||
|
create_contact(customer, self.doctype,
|
||||||
|
doc.name, args.get("customer_email_" + str(i)))
|
||||||
|
except frappe.NameError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def create_contact(contact, party_type, party, email):
|
||||||
|
"""Create contact based on given contact name"""
|
||||||
|
contact = contact.split(' ')
|
||||||
|
|
||||||
|
contact = frappe.get_doc({
|
||||||
|
'doctype': 'Contact',
|
||||||
|
'first_name': contact[0],
|
||||||
|
'last_name': len(contact) > 1 and contact[1] or ""
|
||||||
|
})
|
||||||
|
contact.append('email_ids', dict(email_id=email, is_primary=1))
|
||||||
|
contact.append('links', dict(link_doctype=party_type, link_name=party))
|
||||||
|
contact.insert()
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_loyalty_programs(doc):
|
def get_loyalty_programs(doc):
|
||||||
''' returns applicable loyalty programs for a customer '''
|
''' returns applicable loyalty programs for a customer '''
|
||||||
|
@ -884,6 +884,54 @@ class Item(WebsiteGenerator):
|
|||||||
if not enabled:
|
if not enabled:
|
||||||
frappe.msgprint(msg=_("You have to enable auto re-order in Stock Settings to maintain re-order levels."), title=_("Enable Auto Re-Order"), indicator="orange")
|
frappe.msgprint(msg=_("You have to enable auto re-order in Stock Settings to maintain re-order levels."), title=_("Enable Auto Re-Order"), indicator="orange")
|
||||||
|
|
||||||
|
def create_onboarding_docs(self, args):
|
||||||
|
defaults = frappe.defaults.get_defaults()
|
||||||
|
for i in range(1, args.get('max_count')):
|
||||||
|
item = args.get('item_' + str(i))
|
||||||
|
if item:
|
||||||
|
default_warehouse = ''
|
||||||
|
default_warehouse = frappe.db.get_value('Warehouse', filters={
|
||||||
|
'warehouse_name': _('Finished Goods'),
|
||||||
|
'company': defaults.get('company_name')
|
||||||
|
})
|
||||||
|
|
||||||
|
try:
|
||||||
|
frappe.get_doc({
|
||||||
|
'doctype': self.doctype,
|
||||||
|
'item_code': item,
|
||||||
|
'item_name': item,
|
||||||
|
'description': item,
|
||||||
|
'show_in_website': 1,
|
||||||
|
'is_sales_item': 1,
|
||||||
|
'is_purchase_item': 1,
|
||||||
|
'is_stock_item': 1,
|
||||||
|
'item_group': _('Products'),
|
||||||
|
'stock_uom': _(args.get('item_uom_' + str(i))),
|
||||||
|
'item_defaults': [{
|
||||||
|
'default_warehouse': default_warehouse,
|
||||||
|
'company': defaults.get('company_name')
|
||||||
|
}]
|
||||||
|
}).insert()
|
||||||
|
|
||||||
|
except frappe.NameError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if args.get('item_price_' + str(i)):
|
||||||
|
item_price = flt(args.get('tem_price_' + str(i)))
|
||||||
|
|
||||||
|
price_list_name = frappe.db.get_value('Price List', {'selling': 1})
|
||||||
|
make_item_price(item, price_list_name, item_price)
|
||||||
|
price_list_name = frappe.db.get_value('Price List', {'buying': 1})
|
||||||
|
make_item_price(item, price_list_name, item_price)
|
||||||
|
|
||||||
|
def make_item_price(item, price_list_name, item_price):
|
||||||
|
frappe.get_doc({
|
||||||
|
'doctype': 'Item Price',
|
||||||
|
'price_list': price_list_name,
|
||||||
|
'item_code': item,
|
||||||
|
'price_list_rate': item_price
|
||||||
|
}).insert()
|
||||||
|
|
||||||
def get_timeline_data(doctype, name):
|
def get_timeline_data(doctype, name):
|
||||||
'''returns timeline data based on stock ledger entry'''
|
'''returns timeline data based on stock ledger entry'''
|
||||||
out = {}
|
out = {}
|
||||||
|
@ -1,228 +0,0 @@
|
|||||||
# 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, erpnext
|
|
||||||
|
|
||||||
import json
|
|
||||||
from frappe import _
|
|
||||||
from frappe.utils import flt
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def create_customers(args_data):
|
|
||||||
args = json.loads(args_data)
|
|
||||||
defaults = frappe.defaults.get_defaults()
|
|
||||||
for i in range(1,args.get('max_count')):
|
|
||||||
customer = args.get("customer_name_" + str(i))
|
|
||||||
if customer:
|
|
||||||
try:
|
|
||||||
doc = frappe.get_doc({
|
|
||||||
"doctype": "Customer",
|
|
||||||
"customer_name": customer,
|
|
||||||
"customer_type": "Company",
|
|
||||||
"customer_group": _("Commercial"),
|
|
||||||
"territory": defaults.get("country"),
|
|
||||||
"company": defaults.get("company")
|
|
||||||
}).insert()
|
|
||||||
|
|
||||||
if args.get("customer_email_" + str(i)):
|
|
||||||
create_contact(customer, "Customer",
|
|
||||||
doc.name, args.get("customer_email_" + str(i)))
|
|
||||||
except frappe.NameError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def create_letterhead(args_data):
|
|
||||||
args = json.loads(args_data)
|
|
||||||
letterhead = args.get("letterhead")
|
|
||||||
if letterhead:
|
|
||||||
try:
|
|
||||||
frappe.get_doc({
|
|
||||||
"doctype": "Letter Head",
|
|
||||||
"image": letterhead,
|
|
||||||
"letter_head_name": _("Standard"),
|
|
||||||
"is_default": 1
|
|
||||||
}).insert()
|
|
||||||
except frappe.NameError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def create_suppliers(args_data):
|
|
||||||
args = json.loads(args_data)
|
|
||||||
defaults = frappe.defaults.get_defaults()
|
|
||||||
for i in range(1,args.get('max_count')):
|
|
||||||
supplier = args.get("supplier_name_" + str(i))
|
|
||||||
if supplier:
|
|
||||||
try:
|
|
||||||
doc = frappe.get_doc({
|
|
||||||
"doctype":"Supplier",
|
|
||||||
"supplier_name": supplier,
|
|
||||||
"supplier_group": _("Local"),
|
|
||||||
"company": defaults.get("company")
|
|
||||||
}).insert()
|
|
||||||
|
|
||||||
if args.get("supplier_email_" + str(i)):
|
|
||||||
create_contact(supplier, "Supplier",
|
|
||||||
doc.name, args.get("supplier_email_" + str(i)))
|
|
||||||
except frappe.NameError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def create_contact(contact, party_type, party, email):
|
|
||||||
"""Create contact based on given contact name"""
|
|
||||||
contact = contact.split(" ")
|
|
||||||
|
|
||||||
contact = frappe.get_doc({
|
|
||||||
"doctype": "Contact",
|
|
||||||
"first_name": contact[0],
|
|
||||||
"last_name": len(contact) > 1 and contact[1] or ""
|
|
||||||
})
|
|
||||||
contact.append('email_ids', dict(email_id=email, is_primary=1))
|
|
||||||
contact.append('links', dict(link_doctype=party_type, link_name=party))
|
|
||||||
contact.insert()
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def create_items(args_data):
|
|
||||||
args = json.loads(args_data)
|
|
||||||
defaults = frappe.defaults.get_defaults()
|
|
||||||
for i in range(1, args.get('max_count')):
|
|
||||||
item = args.get("item_" + str(i))
|
|
||||||
if item:
|
|
||||||
default_warehouse = ""
|
|
||||||
default_warehouse = frappe.db.get_value("Warehouse", filters={
|
|
||||||
"warehouse_name": _("Finished Goods"),
|
|
||||||
"company": defaults.get("company_name")
|
|
||||||
})
|
|
||||||
|
|
||||||
try:
|
|
||||||
frappe.get_doc({
|
|
||||||
"doctype":"Item",
|
|
||||||
"item_code": item,
|
|
||||||
"item_name": item,
|
|
||||||
"description": item,
|
|
||||||
"show_in_website": 1,
|
|
||||||
"is_sales_item": 1,
|
|
||||||
"is_purchase_item": 1,
|
|
||||||
"is_stock_item": 1,
|
|
||||||
"item_group": _("Products"),
|
|
||||||
"stock_uom": _(args.get("item_uom_" + str(i))),
|
|
||||||
"item_defaults": [{
|
|
||||||
"default_warehouse": default_warehouse,
|
|
||||||
"company": defaults.get("company_name")
|
|
||||||
}]
|
|
||||||
}).insert()
|
|
||||||
|
|
||||||
except frappe.NameError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
if args.get("item_price_" + str(i)):
|
|
||||||
item_price = flt(args.get("item_price_" + str(i)))
|
|
||||||
|
|
||||||
price_list_name = frappe.db.get_value("Price List", {"selling": 1})
|
|
||||||
make_item_price(item, price_list_name, item_price)
|
|
||||||
price_list_name = frappe.db.get_value("Price List", {"buying": 1})
|
|
||||||
make_item_price(item, price_list_name, item_price)
|
|
||||||
|
|
||||||
|
|
||||||
def make_item_price(item, price_list_name, item_price):
|
|
||||||
frappe.get_doc({
|
|
||||||
"doctype": "Item Price",
|
|
||||||
"price_list": price_list_name,
|
|
||||||
"item_code": item,
|
|
||||||
"price_list_rate": item_price
|
|
||||||
}).insert()
|
|
||||||
|
|
||||||
# Education
|
|
||||||
@frappe.whitelist()
|
|
||||||
def create_program(args_data):
|
|
||||||
args = json.loads(args_data)
|
|
||||||
for i in range(1,args.get('max_count')):
|
|
||||||
if args.get("program_" + str(i)):
|
|
||||||
program = frappe.new_doc("Program")
|
|
||||||
program.program_code = args.get("program_" + str(i))
|
|
||||||
program.program_name = args.get("program_" + str(i))
|
|
||||||
try:
|
|
||||||
program.save()
|
|
||||||
except frappe.DuplicateEntryError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def create_course(args_data):
|
|
||||||
args = json.loads(args_data)
|
|
||||||
for i in range(1,args.get('max_count')):
|
|
||||||
if args.get("course_" + str(i)):
|
|
||||||
course = frappe.new_doc("Course")
|
|
||||||
course.course_code = args.get("course_" + str(i))
|
|
||||||
course.course_name = args.get("course_" + str(i))
|
|
||||||
try:
|
|
||||||
course.save()
|
|
||||||
except frappe.DuplicateEntryError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def create_instructor(args_data):
|
|
||||||
args = json.loads(args_data)
|
|
||||||
for i in range(1,args.get('max_count')):
|
|
||||||
if args.get("instructor_" + str(i)):
|
|
||||||
instructor = frappe.new_doc("Instructor")
|
|
||||||
instructor.instructor_name = args.get("instructor_" + str(i))
|
|
||||||
try:
|
|
||||||
instructor.save()
|
|
||||||
except frappe.DuplicateEntryError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def create_room(args_data):
|
|
||||||
args = json.loads(args_data)
|
|
||||||
for i in range(1,args.get('max_count')):
|
|
||||||
if args.get("room_" + str(i)):
|
|
||||||
room = frappe.new_doc("Room")
|
|
||||||
room.room_name = args.get("room_" + str(i))
|
|
||||||
room.seating_capacity = args.get("room_capacity_" + str(i))
|
|
||||||
try:
|
|
||||||
room.save()
|
|
||||||
except frappe.DuplicateEntryError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def create_users(args_data):
|
|
||||||
if frappe.session.user == 'Administrator':
|
|
||||||
return
|
|
||||||
args = json.loads(args_data)
|
|
||||||
defaults = frappe.defaults.get_defaults()
|
|
||||||
for i in range(1,args.get('max_count')):
|
|
||||||
email = args.get("user_email_" + str(i))
|
|
||||||
fullname = args.get("user_fullname_" + str(i))
|
|
||||||
if email:
|
|
||||||
if not fullname:
|
|
||||||
fullname = email.split("@")[0]
|
|
||||||
|
|
||||||
parts = fullname.split(" ", 1)
|
|
||||||
|
|
||||||
user = frappe.get_doc({
|
|
||||||
"doctype": "User",
|
|
||||||
"email": email,
|
|
||||||
"first_name": parts[0],
|
|
||||||
"last_name": parts[1] if len(parts) > 1 else "",
|
|
||||||
"enabled": 1,
|
|
||||||
"user_type": "System User"
|
|
||||||
})
|
|
||||||
|
|
||||||
# default roles
|
|
||||||
user.append_roles("Projects User", "Stock User", "Support Team")
|
|
||||||
user.flags.delay_emails = True
|
|
||||||
|
|
||||||
if not frappe.db.get_value("User", email):
|
|
||||||
user.insert(ignore_permissions=True)
|
|
||||||
|
|
||||||
# create employee
|
|
||||||
emp = frappe.get_doc({
|
|
||||||
"doctype": "Employee",
|
|
||||||
"employee_name": fullname,
|
|
||||||
"user_id": email,
|
|
||||||
"status": "Active",
|
|
||||||
"company": defaults.get("company")
|
|
||||||
})
|
|
||||||
emp.flags.ignore_mandatory = True
|
|
||||||
emp.insert(ignore_permissions = True)
|
|
||||||
|
|
||||||
# Enumerate the setup hooks you're going to need, apart from the slides
|
|
Loading…
x
Reference in New Issue
Block a user