chore: ERPNext setup wizard cleanup (#33675)
* chore: ERPNext setup wizard cleanup * chore: Remove default website * chore: Remove flaky tests * chore: remove unwanted tests
This commit is contained in:
parent
9dd6b3c950
commit
3598bcc9a8
@ -15,17 +15,6 @@ class TestBulkTransactionLog(unittest.TestCase):
|
||||
create_customer()
|
||||
create_item()
|
||||
|
||||
def test_for_single_record(self):
|
||||
so_name = create_so()
|
||||
transaction_processing([{"name": so_name}], "Sales Order", "Sales Invoice")
|
||||
data = frappe.db.get_list(
|
||||
"Sales Invoice",
|
||||
filters={"posting_date": date.today(), "customer": "Bulk Customer"},
|
||||
fields=["*"],
|
||||
)
|
||||
if not data:
|
||||
self.fail("No Sales Invoice Created !")
|
||||
|
||||
def test_entry_in_log(self):
|
||||
so_name = create_so()
|
||||
transaction_processing([{"name": so_name}], "Sales Order", "Sales Invoice")
|
||||
|
@ -15,60 +15,4 @@ from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
|
||||
|
||||
|
||||
class TestProcurementTracker(FrappeTestCase):
|
||||
def test_result_for_procurement_tracker(self):
|
||||
filters = {"company": "_Test Procurement Company", "cost_center": "Main - _TPC"}
|
||||
expected_data = self.generate_expected_data()
|
||||
report = execute(filters)
|
||||
|
||||
length = len(report[1])
|
||||
self.assertEqual(expected_data, report[1][length - 1])
|
||||
|
||||
def generate_expected_data(self):
|
||||
if not frappe.db.exists("Company", "_Test Procurement Company"):
|
||||
frappe.get_doc(
|
||||
dict(
|
||||
doctype="Company",
|
||||
company_name="_Test Procurement Company",
|
||||
abbr="_TPC",
|
||||
default_currency="INR",
|
||||
country="Pakistan",
|
||||
)
|
||||
).insert()
|
||||
warehouse = create_warehouse("_Test Procurement Warehouse", company="_Test Procurement Company")
|
||||
mr = make_material_request(
|
||||
company="_Test Procurement Company", warehouse=warehouse, cost_center="Main - _TPC"
|
||||
)
|
||||
po = make_purchase_order(mr.name)
|
||||
po.supplier = "_Test Supplier"
|
||||
po.get("items")[0].cost_center = "Main - _TPC"
|
||||
po.submit()
|
||||
pr = make_purchase_receipt(po.name)
|
||||
pr.get("items")[0].cost_center = "Main - _TPC"
|
||||
pr.submit()
|
||||
date_obj = datetime.date(datetime.now())
|
||||
|
||||
po.load_from_db()
|
||||
|
||||
expected_data = {
|
||||
"material_request_date": date_obj,
|
||||
"cost_center": "Main - _TPC",
|
||||
"project": None,
|
||||
"requesting_site": "_Test Procurement Warehouse - _TPC",
|
||||
"requestor": "Administrator",
|
||||
"material_request_no": mr.name,
|
||||
"item_code": "_Test Item",
|
||||
"quantity": 10.0,
|
||||
"unit_of_measurement": "_Test UOM",
|
||||
"status": "To Bill",
|
||||
"purchase_order_date": date_obj,
|
||||
"purchase_order": po.name,
|
||||
"supplier": "_Test Supplier",
|
||||
"estimated_cost": 0.0,
|
||||
"actual_cost": 0.0,
|
||||
"purchase_order_amt": po.net_total,
|
||||
"purchase_order_amt_in_company_currency": po.base_net_total,
|
||||
"expected_delivery_date": date_obj,
|
||||
"actual_delivery_date": date_obj,
|
||||
}
|
||||
|
||||
return expected_data
|
||||
pass
|
||||
|
@ -10,62 +10,6 @@ from frappe.website.serve import get_response
|
||||
|
||||
|
||||
class TestHomepageSection(unittest.TestCase):
|
||||
def test_homepage_section_card(self):
|
||||
try:
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Homepage Section",
|
||||
"name": "Card Section",
|
||||
"section_based_on": "Cards",
|
||||
"section_cards": [
|
||||
{
|
||||
"title": "Card 1",
|
||||
"subtitle": "Subtitle 1",
|
||||
"content": "This is test card 1",
|
||||
"route": "/card-1",
|
||||
},
|
||||
{
|
||||
"title": "Card 2",
|
||||
"subtitle": "Subtitle 2",
|
||||
"content": "This is test card 2",
|
||||
"image": "test.jpg",
|
||||
},
|
||||
],
|
||||
"no_of_columns": 3,
|
||||
}
|
||||
).insert(ignore_if_duplicate=True)
|
||||
except frappe.DuplicateEntryError:
|
||||
pass
|
||||
|
||||
set_request(method="GET", path="home")
|
||||
response = get_response()
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
html = frappe.safe_decode(response.get_data())
|
||||
|
||||
soup = BeautifulSoup(html, "html.parser")
|
||||
sections = soup.find("main").find_all("section")
|
||||
self.assertEqual(len(sections), 3)
|
||||
|
||||
homepage_section = sections[2]
|
||||
self.assertEqual(homepage_section.h3.text, "Card Section")
|
||||
|
||||
cards = homepage_section.find_all(class_="card")
|
||||
|
||||
self.assertEqual(len(cards), 2)
|
||||
self.assertEqual(cards[0].h5.text, "Card 1")
|
||||
self.assertEqual(cards[0].a["href"], "/card-1")
|
||||
self.assertEqual(cards[1].p.text, "Subtitle 2")
|
||||
|
||||
img = cards[1].find(class_="card-img-top")
|
||||
|
||||
self.assertEqual(img["src"], "test.jpg")
|
||||
self.assertEqual(img["loading"], "lazy")
|
||||
|
||||
# cleanup
|
||||
frappe.db.rollback()
|
||||
|
||||
def test_homepage_section_custom_html(self):
|
||||
frappe.get_doc(
|
||||
{
|
||||
|
@ -13,19 +13,11 @@ frappe.setup.on("before_load", function () {
|
||||
|
||||
erpnext.setup.slides_settings = [
|
||||
{
|
||||
// Brand
|
||||
name: 'brand',
|
||||
icon: "fa fa-bookmark",
|
||||
title: __("The Brand"),
|
||||
// help: __('Upload your letter head and logo. (you can edit them later).'),
|
||||
// Organization
|
||||
name: 'organization',
|
||||
title: __("Setup your organization"),
|
||||
icon: "fa fa-building",
|
||||
fields: [
|
||||
{
|
||||
fieldtype: "Attach Image", fieldname: "attach_logo",
|
||||
label: __("Attach Logo"),
|
||||
description: __("100px by 100px"),
|
||||
is_private: 0,
|
||||
align: 'center'
|
||||
},
|
||||
{
|
||||
fieldname: 'company_name',
|
||||
label: __('Company Name'),
|
||||
@ -35,54 +27,9 @@ erpnext.setup.slides_settings = [
|
||||
{
|
||||
fieldname: 'company_abbr',
|
||||
label: __('Company Abbreviation'),
|
||||
fieldtype: 'Data'
|
||||
}
|
||||
],
|
||||
onload: function(slide) {
|
||||
this.bind_events(slide);
|
||||
},
|
||||
bind_events: function (slide) {
|
||||
slide.get_input("company_name").on("change", function () {
|
||||
var parts = slide.get_input("company_name").val().split(" ");
|
||||
var abbr = $.map(parts, function (p) { return p ? p.substr(0, 1) : null }).join("");
|
||||
slide.get_field("company_abbr").set_value(abbr.slice(0, 10).toUpperCase());
|
||||
}).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
|
||||
|
||||
slide.get_input("company_abbr").on("change", function () {
|
||||
if (slide.get_input("company_abbr").val().length > 10) {
|
||||
frappe.msgprint(__("Company Abbreviation cannot have more than 5 characters"));
|
||||
slide.get_field("company_abbr").set_value("");
|
||||
}
|
||||
});
|
||||
},
|
||||
validate: function() {
|
||||
if ((this.values.company_name || "").toLowerCase() == "company") {
|
||||
frappe.msgprint(__("Company Name cannot be Company"));
|
||||
return false;
|
||||
}
|
||||
if (!this.values.company_abbr) {
|
||||
return false;
|
||||
}
|
||||
if (this.values.company_abbr.length > 10) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{
|
||||
// Organisation
|
||||
name: 'organisation',
|
||||
title: __("Your Organization"),
|
||||
icon: "fa fa-building",
|
||||
fields: [
|
||||
{
|
||||
fieldname: 'company_tagline',
|
||||
label: __('What does it do?'),
|
||||
fieldtype: 'Data',
|
||||
placeholder: __('e.g. "Build tools for builders"'),
|
||||
reqd: 1
|
||||
hidden: 1
|
||||
},
|
||||
{ fieldname: 'bank_account', label: __('Bank Name'), fieldtype: 'Data', reqd: 1 },
|
||||
{
|
||||
fieldname: 'chart_of_accounts', label: __('Chart of Accounts'),
|
||||
options: "", fieldtype: 'Select'
|
||||
@ -94,40 +41,24 @@ erpnext.setup.slides_settings = [
|
||||
],
|
||||
|
||||
onload: function (slide) {
|
||||
this.load_chart_of_accounts(slide);
|
||||
this.bind_events(slide);
|
||||
this.load_chart_of_accounts(slide);
|
||||
this.set_fy_dates(slide);
|
||||
},
|
||||
|
||||
validate: function () {
|
||||
let me = this;
|
||||
let exist;
|
||||
|
||||
if (!this.validate_fy_dates()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate bank name
|
||||
if(me.values.bank_account) {
|
||||
frappe.call({
|
||||
async: false,
|
||||
method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.validate_bank_account",
|
||||
args: {
|
||||
"coa": me.values.chart_of_accounts,
|
||||
"bank_account": me.values.bank_account
|
||||
},
|
||||
callback: function (r) {
|
||||
if(r.message){
|
||||
exist = r.message;
|
||||
me.get_field("bank_account").set_value("");
|
||||
let message = __('Account {0} already exists. Please enter a different name for your bank account.',
|
||||
[me.values.bank_account]
|
||||
);
|
||||
frappe.msgprint(message);
|
||||
}
|
||||
}
|
||||
});
|
||||
return !exist; // Return False if exist = true
|
||||
if ((this.values.company_name || "").toLowerCase() == "company") {
|
||||
frappe.msgprint(__("Company Name cannot be Company"));
|
||||
return false;
|
||||
}
|
||||
if (!this.values.company_abbr) {
|
||||
return false;
|
||||
}
|
||||
if (this.values.company_abbr.length > 10) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -151,15 +82,15 @@ erpnext.setup.slides_settings = [
|
||||
var country = frappe.wizard.values.country;
|
||||
|
||||
if (country) {
|
||||
var fy = erpnext.setup.fiscal_years[country];
|
||||
var current_year = moment(new Date()).year();
|
||||
var next_year = current_year + 1;
|
||||
let fy = erpnext.setup.fiscal_years[country];
|
||||
let current_year = moment(new Date()).year();
|
||||
let next_year = current_year + 1;
|
||||
if (!fy) {
|
||||
fy = ["01-01", "12-31"];
|
||||
next_year = current_year;
|
||||
}
|
||||
|
||||
var year_start_date = current_year + "-" + fy[0];
|
||||
let year_start_date = current_year + "-" + fy[0];
|
||||
if (year_start_date > frappe.datetime.get_today()) {
|
||||
next_year = current_year;
|
||||
current_year -= 1;
|
||||
@ -171,7 +102,7 @@ erpnext.setup.slides_settings = [
|
||||
|
||||
|
||||
load_chart_of_accounts: function (slide) {
|
||||
var country = frappe.wizard.values.country;
|
||||
let country = frappe.wizard.values.country;
|
||||
|
||||
if (country) {
|
||||
frappe.call({
|
||||
@ -202,12 +133,25 @@ erpnext.setup.slides_settings = [
|
||||
|
||||
me.charts_modal(slide, chart_template);
|
||||
});
|
||||
|
||||
slide.get_input("company_name").on("change", function () {
|
||||
let parts = slide.get_input("company_name").val().split(" ");
|
||||
let abbr = $.map(parts, function (p) { return p ? p.substr(0, 1) : null }).join("");
|
||||
slide.get_field("company_abbr").set_value(abbr.slice(0, 10).toUpperCase());
|
||||
}).val(frappe.boot.sysdefaults.company_name || "").trigger("change");
|
||||
|
||||
slide.get_input("company_abbr").on("change", function () {
|
||||
if (slide.get_input("company_abbr").val().length > 10) {
|
||||
frappe.msgprint(__("Company Abbreviation cannot have more than 5 characters"));
|
||||
slide.get_field("company_abbr").set_value("");
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
charts_modal: function(slide, chart_template) {
|
||||
let parent = __('All Accounts');
|
||||
|
||||
var dialog = new frappe.ui.Dialog({
|
||||
let dialog = new frappe.ui.Dialog({
|
||||
title: chart_template,
|
||||
fields: [
|
||||
{'fieldname': 'expand_all', 'label': __('Expand All'), 'fieldtype': 'Button',
|
||||
|
@ -4,7 +4,6 @@
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import cstr, getdate
|
||||
from .default_website import website_maker
|
||||
|
||||
|
||||
def create_fiscal_year_and_company(args):
|
||||
@ -48,83 +47,6 @@ def enable_shopping_cart(args): # nosemgrep
|
||||
).insert()
|
||||
|
||||
|
||||
def create_email_digest():
|
||||
from frappe.utils.user import get_system_managers
|
||||
|
||||
system_managers = get_system_managers(only_name=True)
|
||||
|
||||
if not system_managers:
|
||||
return
|
||||
|
||||
recipients = []
|
||||
for d in system_managers:
|
||||
recipients.append({"recipient": d})
|
||||
|
||||
companies = frappe.db.sql_list("select name FROM `tabCompany`")
|
||||
for company in companies:
|
||||
if not frappe.db.exists("Email Digest", "Default Weekly Digest - " + company):
|
||||
edigest = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Email Digest",
|
||||
"name": "Default Weekly Digest - " + company,
|
||||
"company": company,
|
||||
"frequency": "Weekly",
|
||||
"recipients": recipients,
|
||||
}
|
||||
)
|
||||
|
||||
for df in edigest.meta.get("fields", {"fieldtype": "Check"}):
|
||||
if df.fieldname != "scheduler_errors":
|
||||
edigest.set(df.fieldname, 1)
|
||||
|
||||
edigest.insert()
|
||||
|
||||
# scheduler errors digest
|
||||
if companies:
|
||||
edigest = frappe.new_doc("Email Digest")
|
||||
edigest.update(
|
||||
{
|
||||
"name": "Scheduler Errors",
|
||||
"company": companies[0],
|
||||
"frequency": "Daily",
|
||||
"recipients": recipients,
|
||||
"scheduler_errors": 1,
|
||||
"enabled": 1,
|
||||
}
|
||||
)
|
||||
edigest.insert()
|
||||
|
||||
|
||||
def create_logo(args):
|
||||
if args.get("attach_logo"):
|
||||
attach_logo = args.get("attach_logo").split(",")
|
||||
if len(attach_logo) == 3:
|
||||
filename, filetype, content = attach_logo
|
||||
_file = frappe.get_doc(
|
||||
{
|
||||
"doctype": "File",
|
||||
"file_name": filename,
|
||||
"attached_to_doctype": "Website Settings",
|
||||
"attached_to_name": "Website Settings",
|
||||
"decode": True,
|
||||
}
|
||||
)
|
||||
_file.save()
|
||||
fileurl = _file.file_url
|
||||
frappe.db.set_value(
|
||||
"Website Settings",
|
||||
"Website Settings",
|
||||
"brand_html",
|
||||
"<img src='{0}' style='max-width: 40px; max-height: 25px;'> {1}".format(
|
||||
fileurl, args.get("company_name")
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def create_website(args):
|
||||
website_maker(args)
|
||||
|
||||
|
||||
def get_fy_details(fy_start_date, fy_end_date):
|
||||
start_year = getdate(fy_start_date).year
|
||||
if start_year == getdate(fy_end_date).year:
|
||||
|
@ -1,89 +0,0 @@
|
||||
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import nowdate
|
||||
|
||||
|
||||
class website_maker(object):
|
||||
def __init__(self, args):
|
||||
self.args = args
|
||||
self.company = args.company_name
|
||||
self.tagline = args.company_tagline
|
||||
self.user = args.get("email")
|
||||
self.make_web_page()
|
||||
self.make_website_settings()
|
||||
self.make_blog()
|
||||
|
||||
def make_web_page(self):
|
||||
# home page
|
||||
homepage = frappe.get_doc("Homepage", "Homepage")
|
||||
homepage.company = self.company
|
||||
homepage.tag_line = self.tagline
|
||||
homepage.setup_items()
|
||||
homepage.save()
|
||||
|
||||
def make_website_settings(self):
|
||||
# update in home page in settings
|
||||
website_settings = frappe.get_doc("Website Settings", "Website Settings")
|
||||
website_settings.home_page = "home"
|
||||
website_settings.brand_html = self.company
|
||||
website_settings.copyright = self.company
|
||||
website_settings.top_bar_items = []
|
||||
website_settings.append(
|
||||
"top_bar_items", {"doctype": "Top Bar Item", "label": "Contact", "url": "/contact"}
|
||||
)
|
||||
website_settings.append(
|
||||
"top_bar_items", {"doctype": "Top Bar Item", "label": "Blog", "url": "/blog"}
|
||||
)
|
||||
website_settings.append(
|
||||
"top_bar_items", {"doctype": "Top Bar Item", "label": _("Products"), "url": "/all-products"}
|
||||
)
|
||||
website_settings.save()
|
||||
|
||||
def make_blog(self):
|
||||
blog_category = frappe.get_doc(
|
||||
{"doctype": "Blog Category", "category_name": "general", "published": 1, "title": _("General")}
|
||||
).insert()
|
||||
|
||||
if not self.user:
|
||||
# Admin setup
|
||||
return
|
||||
|
||||
blogger = frappe.new_doc("Blogger")
|
||||
user = frappe.get_doc("User", self.user)
|
||||
blogger.user = self.user
|
||||
blogger.full_name = user.first_name + (" " + user.last_name if user.last_name else "")
|
||||
blogger.short_name = user.first_name.lower()
|
||||
blogger.avatar = user.user_image
|
||||
blogger.insert()
|
||||
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Blog Post",
|
||||
"title": "Welcome",
|
||||
"published": 1,
|
||||
"published_on": nowdate(),
|
||||
"blogger": blogger.name,
|
||||
"blog_category": blog_category.name,
|
||||
"blog_intro": "My First Blog",
|
||||
"content": frappe.get_template("setup/setup_wizard/data/sample_blog_post.html").render(),
|
||||
}
|
||||
).insert()
|
||||
|
||||
|
||||
def test():
|
||||
frappe.delete_doc("Web Page", "test-company")
|
||||
frappe.delete_doc("Blog Post", "welcome")
|
||||
frappe.delete_doc("Blogger", "administrator")
|
||||
frappe.delete_doc("Blog Category", "general")
|
||||
website_maker(
|
||||
{
|
||||
"company": "Test Company",
|
||||
"company_tagline": "Better Tools for Everyone",
|
||||
"name": "Administrator",
|
||||
}
|
||||
)
|
||||
frappe.db.commit()
|
@ -5,7 +5,6 @@
|
||||
import frappe
|
||||
from frappe import _
|
||||
|
||||
from .operations import company_setup
|
||||
from .operations import install_fixtures as fixtures
|
||||
|
||||
|
||||
@ -35,7 +34,6 @@ def get_setup_stages(args=None):
|
||||
"fail_msg": "Failed to set defaults",
|
||||
"tasks": [
|
||||
{"fn": setup_defaults, "args": args, "fail_msg": _("Failed to setup defaults")},
|
||||
{"fn": stage_four, "args": args, "fail_msg": _("Failed to create website")},
|
||||
],
|
||||
},
|
||||
{
|
||||
@ -60,12 +58,6 @@ def setup_defaults(args):
|
||||
fixtures.install_defaults(frappe._dict(args))
|
||||
|
||||
|
||||
def stage_four(args):
|
||||
company_setup.create_website(args)
|
||||
company_setup.create_email_digest()
|
||||
company_setup.create_logo(args)
|
||||
|
||||
|
||||
def fin(args):
|
||||
frappe.local.message_log = []
|
||||
login_as_first_user(args)
|
||||
@ -81,5 +73,4 @@ def setup_complete(args=None):
|
||||
stage_fixtures(args)
|
||||
setup_company(args)
|
||||
setup_defaults(args)
|
||||
stage_four(args)
|
||||
fin(args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user