Skip to content

Commit

Permalink
chore: ERPNext setup wizard cleanup (frappe#33675)
Browse files Browse the repository at this point in the history
* chore: ERPNext setup wizard cleanup

* chore: Remove default website

* chore: Remove flaky tests

* chore: remove unwanted tests
  • Loading branch information
deepeshgarg007 authored Jan 27, 2023
1 parent 9dd6b3c commit 3598bcc
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 390 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ def setUp(self):
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,60 +15,4 @@


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
56 changes: 0 additions & 56 deletions erpnext/portal/doctype/homepage_section/test_homepage_section.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,6 @@


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(
{
Expand Down
124 changes: 34 additions & 90 deletions erpnext/public/js/setup_wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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({
Expand Down Expand Up @@ -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',
Expand Down
Loading

0 comments on commit 3598bcc

Please sign in to comment.