mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-01 23:53:21 +00:00
* ci: add prettier to pre-commit
(cherry picked from commit 2c16036ef3)
* style: format js files
---------
Co-authored-by: barredterra <14891507+barredterra@users.noreply.github.com>
Co-authored-by: Ankush Menat <ankush@frappe.io>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
frappe.provide("erpnext.setup");
|
||||
|
||||
frappe.pages['setup-wizard'].on_page_load = function(wrapper) {
|
||||
if(frappe.sys_defaults.company) {
|
||||
frappe.pages["setup-wizard"].on_page_load = function (wrapper) {
|
||||
if (frappe.sys_defaults.company) {
|
||||
frappe.set_route("desk");
|
||||
return;
|
||||
}
|
||||
@@ -14,38 +14,42 @@ frappe.setup.on("before_load", function () {
|
||||
erpnext.setup.slides_settings = [
|
||||
{
|
||||
// Organization
|
||||
name: 'organization',
|
||||
name: "organization",
|
||||
title: __("Setup your organization"),
|
||||
icon: "fa fa-building",
|
||||
fields: [
|
||||
{
|
||||
fieldname: 'company_name',
|
||||
label: __('Company Name'),
|
||||
fieldtype: 'Data',
|
||||
reqd: 1
|
||||
fieldname: "company_name",
|
||||
label: __("Company Name"),
|
||||
fieldtype: "Data",
|
||||
reqd: 1,
|
||||
},
|
||||
{ fieldtype: "Column Break" },
|
||||
{
|
||||
fieldname: 'company_abbr',
|
||||
label: __('Company Abbreviation'),
|
||||
fieldtype: 'Data',
|
||||
reqd: 1
|
||||
fieldname: "company_abbr",
|
||||
label: __("Company Abbreviation"),
|
||||
fieldtype: "Data",
|
||||
reqd: 1,
|
||||
},
|
||||
{ fieldtype: "Section Break" },
|
||||
{
|
||||
fieldname: 'chart_of_accounts', label: __('Chart of Accounts'),
|
||||
options: "", fieldtype: 'Select'
|
||||
fieldname: "chart_of_accounts",
|
||||
label: __("Chart of Accounts"),
|
||||
options: "",
|
||||
fieldtype: "Select",
|
||||
},
|
||||
{ fieldname: 'view_coa', label: __('View Chart of Accounts'), fieldtype: 'Button' },
|
||||
{ fieldname: 'fy_start_date', label: __('Financial Year Begins On'), fieldtype: 'Date', reqd: 1 },
|
||||
{ fieldname: "view_coa", label: __("View Chart of Accounts"), fieldtype: "Button" },
|
||||
{ fieldname: "fy_start_date", label: __("Financial Year Begins On"), fieldtype: "Date", reqd: 1 },
|
||||
// end date should be hidden (auto calculated)
|
||||
{ fieldname: 'fy_end_date', label: __('End Date'), fieldtype: 'Date', reqd: 1, hidden: 1 },
|
||||
{ fieldname: "fy_end_date", label: __("End Date"), fieldtype: "Date", reqd: 1, hidden: 1 },
|
||||
{ fieldtype: "Section Break" },
|
||||
{
|
||||
fieldname: 'setup_demo',
|
||||
label: __('Generate Demo Data for Exploration'),
|
||||
fieldtype: 'Check',
|
||||
description: __('If checked, we will create demo data for you to explore the system. This demo data can be erased later.')
|
||||
fieldname: "setup_demo",
|
||||
label: __("Generate Demo Data for Exploration"),
|
||||
fieldtype: "Check",
|
||||
description: __(
|
||||
"If checked, we will create demo data for you to explore the system. This demo data can be erased later."
|
||||
),
|
||||
},
|
||||
],
|
||||
|
||||
@@ -73,10 +77,10 @@ erpnext.setup.slides_settings = [
|
||||
return true;
|
||||
},
|
||||
|
||||
validate_fy_dates: function() {
|
||||
validate_fy_dates: function () {
|
||||
// validate fiscal year start and end dates
|
||||
const invalid = this.values.fy_start_date == 'Invalid date' ||
|
||||
this.values.fy_end_date == 'Invalid date';
|
||||
const invalid =
|
||||
this.values.fy_start_date == "Invalid date" || this.values.fy_end_date == "Invalid date";
|
||||
const start_greater_than_end = this.values.fy_start_date > this.values.fy_end_date;
|
||||
|
||||
if (invalid || start_greater_than_end) {
|
||||
@@ -104,26 +108,24 @@ erpnext.setup.slides_settings = [
|
||||
next_year = current_year;
|
||||
current_year -= 1;
|
||||
}
|
||||
slide.get_field("fy_start_date").set_value(current_year + '-' + fy[0]);
|
||||
slide.get_field("fy_end_date").set_value(next_year + '-' + fy[1]);
|
||||
slide.get_field("fy_start_date").set_value(current_year + "-" + fy[0]);
|
||||
slide.get_field("fy_end_date").set_value(next_year + "-" + fy[1]);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
load_chart_of_accounts: function (slide) {
|
||||
let country = frappe.wizard.values.country;
|
||||
|
||||
if (country) {
|
||||
frappe.call({
|
||||
method: "erpnext.accounts.doctype.account.chart_of_accounts.chart_of_accounts.get_charts_for_country",
|
||||
args: { "country": country, with_standard: true },
|
||||
args: { country: country, with_standard: true },
|
||||
callback: function (r) {
|
||||
if (r.message) {
|
||||
slide.get_input("chart_of_accounts").empty()
|
||||
.add_options(r.message);
|
||||
slide.get_input("chart_of_accounts").empty().add_options(r.message);
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -131,56 +133,74 @@ erpnext.setup.slides_settings = [
|
||||
let me = this;
|
||||
slide.get_input("fy_start_date").on("change", function () {
|
||||
var start_date = slide.form.fields_dict.fy_start_date.get_value();
|
||||
var year_end_date =
|
||||
frappe.datetime.add_days(frappe.datetime.add_months(start_date, 12), -1);
|
||||
var year_end_date = frappe.datetime.add_days(frappe.datetime.add_months(start_date, 12), -1);
|
||||
slide.form.fields_dict.fy_end_date.set_value(year_end_date);
|
||||
});
|
||||
|
||||
slide.get_input("view_coa").on("click", function() {
|
||||
slide.get_input("view_coa").on("click", function () {
|
||||
let chart_template = slide.form.fields_dict.chart_of_accounts.get_value();
|
||||
if(!chart_template) return;
|
||||
if (!chart_template) return;
|
||||
|
||||
me.charts_modal(slide, chart_template);
|
||||
});
|
||||
|
||||
slide.get_input("company_name").on("input", 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_name")
|
||||
.on("input", 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 () {
|
||||
let abbr = slide.get_input("company_abbr").val();
|
||||
if (abbr.length > 10) {
|
||||
frappe.msgprint(__("Company Abbreviation cannot have more than 5 characters"));
|
||||
abbr = abbr.slice(0, 10);
|
||||
}
|
||||
slide.get_field("company_abbr").set_value(abbr);
|
||||
}).val(frappe.boot.sysdefaults.company_abbr || "").trigger("change");
|
||||
slide
|
||||
.get_input("company_abbr")
|
||||
.on("change", function () {
|
||||
let abbr = slide.get_input("company_abbr").val();
|
||||
if (abbr.length > 10) {
|
||||
frappe.msgprint(__("Company Abbreviation cannot have more than 5 characters"));
|
||||
abbr = abbr.slice(0, 10);
|
||||
}
|
||||
slide.get_field("company_abbr").set_value(abbr);
|
||||
})
|
||||
.val(frappe.boot.sysdefaults.company_abbr || "")
|
||||
.trigger("change");
|
||||
},
|
||||
|
||||
charts_modal: function(slide, chart_template) {
|
||||
let parent = __('All Accounts');
|
||||
charts_modal: function (slide, chart_template) {
|
||||
let parent = __("All Accounts");
|
||||
|
||||
let dialog = new frappe.ui.Dialog({
|
||||
title: chart_template,
|
||||
fields: [
|
||||
{'fieldname': 'expand_all', 'label': __('Expand All'), 'fieldtype': 'Button',
|
||||
click: function() {
|
||||
{
|
||||
fieldname: "expand_all",
|
||||
label: __("Expand All"),
|
||||
fieldtype: "Button",
|
||||
click: function () {
|
||||
// expand all nodes on button click
|
||||
coa_tree.load_children(coa_tree.root_node, true);
|
||||
}
|
||||
},
|
||||
},
|
||||
{'fieldname': 'collapse_all', 'label': __('Collapse All'), 'fieldtype': 'Button',
|
||||
click: function() {
|
||||
{
|
||||
fieldname: "collapse_all",
|
||||
label: __("Collapse All"),
|
||||
fieldtype: "Button",
|
||||
click: function () {
|
||||
// collapse all nodes
|
||||
coa_tree.get_all_nodes(coa_tree.root_node.data.value, coa_tree.root_node.is_root)
|
||||
.then(data_list => {
|
||||
data_list.map(d => { coa_tree.toggle_node(coa_tree.nodes[d.parent]); });
|
||||
coa_tree
|
||||
.get_all_nodes(coa_tree.root_node.data.value, coa_tree.root_node.is_root)
|
||||
.then((data_list) => {
|
||||
data_list.map((d) => {
|
||||
coa_tree.toggle_node(coa_tree.nodes[d.parent]);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// render tree structure in the dialog modal
|
||||
@@ -188,49 +208,49 @@ erpnext.setup.slides_settings = [
|
||||
parent: $(dialog.body),
|
||||
label: parent,
|
||||
expandable: true,
|
||||
method: 'erpnext.accounts.utils.get_coa',
|
||||
method: "erpnext.accounts.utils.get_coa",
|
||||
args: {
|
||||
chart: chart_template,
|
||||
parent: parent,
|
||||
doctype: 'Account'
|
||||
doctype: "Account",
|
||||
},
|
||||
onclick: function(node) {
|
||||
onclick: function (node) {
|
||||
parent = node.value;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
// add class to show buttons side by side
|
||||
const form_container = $(dialog.body).find('form');
|
||||
const buttons = $(form_container).find('.frappe-control');
|
||||
form_container.addClass('flex');
|
||||
const form_container = $(dialog.body).find("form");
|
||||
const buttons = $(form_container).find(".frappe-control");
|
||||
form_container.addClass("flex");
|
||||
buttons.map((index, button) => {
|
||||
$(button).css({"margin-right": "1em"});
|
||||
})
|
||||
$(button).css({ "margin-right": "1em" });
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
coa_tree.load_children(coa_tree.root_node, true); // expand all node trigger
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
// Source: https://en.wikipedia.org/wiki/Fiscal_year
|
||||
// default 1st Jan - 31st Dec
|
||||
|
||||
erpnext.setup.fiscal_years = {
|
||||
"Afghanistan": ["12-21", "12-20"],
|
||||
"Australia": ["07-01", "06-30"],
|
||||
"Bangladesh": ["07-01", "06-30"],
|
||||
"Canada": ["04-01", "03-31"],
|
||||
Afghanistan: ["12-21", "12-20"],
|
||||
Australia: ["07-01", "06-30"],
|
||||
Bangladesh: ["07-01", "06-30"],
|
||||
Canada: ["04-01", "03-31"],
|
||||
"Costa Rica": ["10-01", "09-30"],
|
||||
"Egypt": ["07-01", "06-30"],
|
||||
Egypt: ["07-01", "06-30"],
|
||||
"Hong Kong": ["04-01", "03-31"],
|
||||
"India": ["04-01", "03-31"],
|
||||
"Iran": ["06-23", "06-22"],
|
||||
"Myanmar": ["04-01", "03-31"],
|
||||
India: ["04-01", "03-31"],
|
||||
Iran: ["06-23", "06-22"],
|
||||
Myanmar: ["04-01", "03-31"],
|
||||
"New Zealand": ["04-01", "03-31"],
|
||||
"Pakistan": ["07-01", "06-30"],
|
||||
"Singapore": ["04-01", "03-31"],
|
||||
Pakistan: ["07-01", "06-30"],
|
||||
Singapore: ["04-01", "03-31"],
|
||||
"South Africa": ["03-01", "02-28"],
|
||||
"Thailand": ["10-01", "09-30"],
|
||||
Thailand: ["10-01", "09-30"],
|
||||
"United Kingdom": ["04-01", "03-31"],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user