Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from Upstream v13 #37

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
7f1d611
fix: Remove redundant description
GangaManoj Sep 1, 2021
d67460b
fix: Only display 'Role Allowed to Override Stop Action' if 'Maintain…
GangaManoj Sep 1, 2021
c128618
fix: Rename 'Action if Same Rate is Not Maintained' to 'Action if Sam…
GangaManoj Sep 2, 2021
d623eac
fix: Move related fields to the same section
GangaManoj Sep 1, 2021
7dce900
Merge branch 'version-13-hotfix' into backport-fix-selling-settings
GangaManoj Sep 7, 2021
a33de1b
chore: remove snyk from dev-dependencies (#27425)
ankush Sep 10, 2021
8337ec9
test: basic tests for controllers/queries (bp #27422)
frappe-pr-bot Sep 10, 2021
becf471
fix: fail migration due to None type during v13_0.update_returned_qty…
dj12djdjs Sep 11, 2021
0ecaf23
fix: Template Error due to use of single quote (#27433)
sagarvora Sep 11, 2021
dd352df
Merge pull request #27437 from frappe-pr-bot/backport/version-13-hotf…
sagarvora Sep 11, 2021
74fa6fa
fix(ux): apply proper filtering in stock reports (#27411) (#27443)
frappe-pr-bot Sep 12, 2021
00c4e34
fix(ux): clean invalid fields from variant setting (#27442)
frappe-pr-bot Sep 12, 2021
5c1f0c9
Revert "fix: Salary component account filter (#26605)" (#27446)
ankush Sep 13, 2021
bb8d90d
feat: (get_items_from) filter material request item in purchase order…
nextchamp-saqib Sep 13, 2021
64796d3
fix(Payroll): incorrect component amount calculation if dependent on …
frappe-pr-bot Sep 13, 2021
52a99d8
fix: editable price list rate field in sales transactions (#27455) (#…
frappe-pr-bot Sep 13, 2021
dab0fe5
feat: Validity dates in Tax Withholding Rates
deepeshgarg007 Aug 31, 2021
5c9f2bf
fix: Advance TDS test case
deepeshgarg007 Sep 1, 2021
e8edeec
fix: Linting and patch fixes
deepeshgarg007 Sep 1, 2021
7d61181
test: Update test case
deepeshgarg007 Sep 1, 2021
0bb16b6
fix: Debug CI
deepeshgarg007 Sep 3, 2021
f101241
fix: Hardcode fiscal year and posting date
deepeshgarg007 Sep 5, 2021
173ae56
fix: Test Case
deepeshgarg007 Sep 9, 2021
9708bf3
fix: Linting Issues
deepeshgarg007 Sep 9, 2021
8fd1aec
fix: employee advance return through multiple additional salaries (#2…
frappe-pr-bot Sep 14, 2021
c9e7e72
fix(HR): Ignore invalid fields when updating employee details (#27456…
frappe-pr-bot Sep 14, 2021
1075483
fix: Maintain same rate in Stock Ledger until stock become positive (…
nabinhait Sep 14, 2021
0b07107
Merge branch 'version-13-hotfix' of https://github.com/frappe/erpnext…
deepeshgarg007 Sep 14, 2021
ca2420f
fix: Update fiscal year
deepeshgarg007 Sep 14, 2021
49fa06f
Merge pull request #27473 from deepeshgarg007/tds_validity_v13
deepeshgarg007 Sep 14, 2021
d5f4160
Merge pull request #27481 from deepeshgarg007/gstin_filter_issue_v13
deepeshgarg007 Sep 14, 2021
b26da04
fix: Rename section break
GangaManoj Sep 14, 2021
d76e5dc
Merge pull request #27486 from marination/job-card-excess-transfer-ho…
marination Sep 14, 2021
4081ecf
chore: sort imports
ankush Sep 14, 2021
2a9fbc6
Merge pull request #27488 from marination/validate-cart-settings
marination Sep 14, 2021
e4cbe12
fix: calculate operating cost based on BOM Quantity (#27464) (#27501)
frappe-pr-bot Sep 14, 2021
247d9bf
fix: Patch for updating tax withholding category dates (#27489) (#27495)
frappe-pr-bot Sep 15, 2021
50fe233
fix: Tags getting fetched correctly in Get Supplier in RFQ (Request F…
vamagithub Sep 15, 2021
5f4a58f
fix: Autoname for customer and supplier (#27505)
frappe-pr-bot Sep 15, 2021
604f13c
fix: Values with same account and different account number in consoli…
frappe-pr-bot Sep 15, 2021
9e0fb74
Merge pull request #27508 from marination/shopping-cart-fixes
marination Sep 15, 2021
a87cc12
feat: provision to add scrap item in job card (#27483) (#27512)
frappe-pr-bot Sep 15, 2021
7d733af
feat: link items to supplier / customer (#27479)
frappe-pr-bot Sep 15, 2021
4bd1bce
fix: table data deleted on submitted maintenance schedule (bp #27513)
frappe-pr-bot Sep 15, 2021
978028c
fix(minor): Remove b2c limit check from CDNR Invoices (#27516)
deepeshgarg007 Sep 15, 2021
0fb1121
fix: not able to submit stock entry with 350 items (#27523) (#27526)
frappe-pr-bot Sep 15, 2021
8b3ef8e
test: automated test for running all stock reports (#27510) (#27522)
frappe-pr-bot Sep 15, 2021
5a34520
fix(minor): Employee filter in Unpaid Expense Claims report (#27530) …
frappe-pr-bot Sep 15, 2021
e9683fa
fix(ProdPlan): Get SubAssy Items does not work (bp #27537)
frappe-pr-bot Sep 16, 2021
adc5bf7
Merge pull request #27543 from frappe-pr-bot/backport/version-13-hotf…
frappe-pr-bot Sep 16, 2021
24c08f5
Merge branch 'version-13-hotfix' into backport-fix-selling-settings
nextchamp-saqib Sep 16, 2021
450e1e8
fix: no validation on item defaults (#27549)
frappe-pr-bot Sep 16, 2021
e2eb72e
fix: Deferred revenue entries post account freezing
deepeshgarg007 Sep 16, 2021
e990bb8
fix: Remove duplicates from customer_code field (bp #27555)
frappe-pr-bot Sep 17, 2021
6ed4046
fix: unecessary keyword args were passed in mapper functions (#27563)…
frappe-pr-bot Sep 17, 2021
5451aed
Merge branch 'version-13-hotfix' into backport-fix-selling-settings
nextchamp-saqib Sep 17, 2021
e6d0a57
ci: fix docs checker for empty body (#27569)
frappe-pr-bot Sep 17, 2021
9ffb65b
fix(healthcare): Duplicate Contact error on add Patient (#27427)
akurungadam Sep 17, 2021
666eaae
fix: PO/PINV - Check if doctype has company_address field before set…
vamagithub Sep 18, 2021
d6ed6d5
fix: Handle `is_search_module_loaded` for redis version < 4.0.0 (#27574)
marination Sep 18, 2021
846d128
fix: Test Case
deepeshgarg007 Sep 20, 2021
7aaecbc
fix: Move related fields together in Selling Settings (#27383)
nextchamp-saqib Sep 20, 2021
9b46dd5
fix(plaid): query to check if bank account exists (#27595)
frappe-pr-bot Sep 20, 2021
55393d1
perf: extract loop invariant db calls
ankush Sep 20, 2021
2dc590c
fix: warn when overbilling checks are skipped.
ankush Sep 20, 2021
8cdd6ea
refactor: add guard clause in for loop
ankush Sep 20, 2021
684ca45
fix(ux): better error message
ankush Sep 20, 2021
72c22a4
Merge pull request #27604 from frappe/mergify/bp/version-13-hotfix/pr…
ankush Sep 20, 2021
10cffe8
fix: Webform Permission for custom doctype (backport #26232) (#27592)
mergify[bot] Sep 20, 2021
1ba4afa
fix: Set parent_detail_docname to prevent overwriting Packed/Bundle I…
GangaManoj Sep 20, 2021
6ba1b03
fix: reference row added in allocation table (#27613)
mergify[bot] Sep 20, 2021
fec19a9
Update training_result.js (#27615) (#27620)
frappe-pr-bot Sep 21, 2021
19446a8
feat: Merge POS invoices based on customer group (#27553)
frappe-pr-bot Sep 21, 2021
47c6fba
fix: (ux) Use subassembly schedule date while making WO from Prod Pla…
frappe-pr-bot Sep 21, 2021
5a8d57f
fix: remove bad default for anniversary reminders (#27632) (#27633)
frappe-pr-bot Sep 21, 2021
9ebabb8
fix: remove unknown field employee_name from query (#27634)
bhavesh95863 Sep 21, 2021
e5a062c
feat: add `Partly Paid` status in Invoices (#27636)
frappe-pr-bot Sep 22, 2021
08e24bd
fix: holiday message reminder (#27654)
frappe-pr-bot Sep 26, 2021
646f8b7
fix: update default KSA VAT rate for setup (#27614) (#27622)
frappe-pr-bot Sep 26, 2021
986ca88
fix: local variable 'fiscal_year_details' referenced before assignmen…
frappe-pr-bot Sep 26, 2021
af53137
fix: setting of gain/loss if party account is in company currency
nextchamp-saqib Sep 26, 2021
677a59b
chore: hide exchange gain loss if empty
nextchamp-saqib Sep 26, 2021
2108bf9
fix: cost center in exchange gain loss gl entry
nextchamp-saqib Sep 26, 2021
19b06b0
patch: invalid gain loss gl entry
nextchamp-saqib Sep 26, 2021
705f094
chore: hide exchange gain loss if empty
nextchamp-saqib Sep 26, 2021
8a8921f
fix: unknown column 'ref_exchange_rate'
nextchamp-saqib Sep 26, 2021
7a8ff85
chore: log modified invoices
nextchamp-saqib Sep 27, 2021
904c592
fix: indentation
nextchamp-saqib Sep 27, 2021
1063ced
fix: linting errors
nextchamp-saqib Sep 27, 2021
0e59873
Merge pull request #27663 from frappe/mergify/bp/version-13-hotfix/pr…
nextchamp-saqib Sep 27, 2021
1b9e96f
fix: Tax Breakup table headers fix (#27596) (#27598)
frappe-pr-bot Sep 27, 2021
e8de8b8
fix: Improvements in COA Importer (#27584) (#27587)
frappe-pr-bot Sep 27, 2021
2ee9da3
fix: cannot set custom label for 'total' field in print format (#27667)
mergify[bot] Sep 27, 2021
1acdade
fix(ux): added exception of template item in filters (#27560) (#27675)
frappe-pr-bot Sep 27, 2021
745abef
fix: set item.qty as mandatory in picklist (#27680) (#27682)
frappe-pr-bot Sep 28, 2021
fbae3c7
fix: apply price list after batch or serial no insertion (#27566) (#2…
frappe-pr-bot Sep 28, 2021
2124922
fix: cannot delete a project if linked with sales order (#27536) (#27…
frappe-pr-bot Sep 28, 2021
6b32fa7
feat(regional): toggle for reduced depreciation rate as per IT Act (#…
mergify[bot] Sep 28, 2021
72986ab
Merge branch 'version-13-hotfix' of https://github.com/frappe/erpnext…
deepeshgarg007 Sep 29, 2021
633847c
fix: Ignore user permission for Represents Company field in Sales and…
frappe-pr-bot Sep 29, 2021
887e376
feat: TDS deduction using journal entry and other fixes (#27451) (#27…
frappe-pr-bot Sep 29, 2021
23863c7
fix: Test case
deepeshgarg007 Sep 29, 2021
aeffaf3
Merge branch 'version-13-hotfix' of https://github.com/frappe/erpnext…
deepeshgarg007 Sep 29, 2021
c8396f4
fix: added project name in the purchase order analysis
rohitwaghchaure Sep 29, 2021
26c1641
Merge pull request #27702 from frappe/mergify/bp/version-13-hotfix/pr…
rohitwaghchaure Sep 29, 2021
7fc7405
fix: Deferred revenue entries post account freezing (#27551)
deepeshgarg007 Sep 30, 2021
471a8dd
fix: distribution of additional costs in mfg stock entry (#27629) (#2…
mergify[bot] Sep 30, 2021
b478e72
fix: wrong company selected when marking attendance for all employees…
mohammedyusufshaikh Sep 30, 2021
49174cd
chore: Merge branch 'version-13-hotfix' into 'version-13-pre-release'
rohitwaghchaure Sep 30, 2021
348f082
Merge pull request #27716 from rohitwaghchaure/merge-v13-hotfix-to-pr…
rohitwaghchaure Sep 30, 2021
f572a4e
fix(Org Chart): use attribute selectors instead of ID selector for no…
mergify[bot] Sep 30, 2021
3e7a029
fix: option to limit reposting in certain timeslot (bp #27725)
mergify[bot] Oct 1, 2021
2c91621
fix: Creating unique hash for slider id instead of slider name
shariquerik Sep 20, 2021
b5fc307
fix: Fixed alignment of Title, Subtitle, Action Button
shariquerik Sep 27, 2021
477d364
chore: linter fix
shariquerik Sep 27, 2021
42f0a97
fix: Chart Of Accounts import button not visible
deepeshgarg007 Oct 2, 2021
0298455
fix: Remove unwanted comments
deepeshgarg007 Oct 2, 2021
c2e4bbe
fix: Linting issues
deepeshgarg007 Oct 2, 2021
6628688
Merge pull request #27752 from frappe/mergify/bp/version-13-pre-relea…
deepeshgarg007 Oct 2, 2021
00978a1
fix: Website Items with same Item name unhandled, thumbnails missing
marination Sep 30, 2021
a453fc6
fix: Pre-commit formatting
marination Sep 30, 2021
869c1be
Merge pull request #27744 from frappe/mergify/bp/version-13-pre-relea…
marination Oct 3, 2021
68cce8e
Merge pull request #27757 from frappe/mergify/bp/version-13-pre-relea…
marination Oct 3, 2021
e6909a0
fix(India): Internal transfer check fix
deepeshgarg007 Sep 30, 2021
953073b
fix(asset): expected value after useful life validation (#27787)
nextchamp-saqib Oct 5, 2021
28aa9a7
Merge pull request #27761 from frappe/mergify/bp/version-13-pre-relea…
deepeshgarg007 Oct 5, 2021
fa94438
fix: using DN for transfer w/o internal customer (backport #27798) (#…
mergify[bot] Oct 5, 2021
758939e
fix: COA Importer showing blank validations
deepeshgarg007 Oct 5, 2021
b4f06c0
fix: Use get_list instead of get_all to avoid perm issues
deepeshgarg007 Oct 5, 2021
c1c5aa7
Merge pull request #27810 from frappe/mergify/bp/version-13-pre-relea…
deepeshgarg007 Oct 5, 2021
a09647b
fix: ignore random periodicity in validations
ankush Oct 5, 2021
287a7b2
Merge pull request #27815 from frappe/mergify/bp/version-13-pre-relea…
noahjacob Oct 5, 2021
89e421a
fix: removed redundant piece of code (#27817) (#27822)
mergify[bot] Oct 5, 2021
633cd0c
chore: change log for v13_12_0
rohitwaghchaure Oct 5, 2021
047debf
Merge pull request #27825 from rohitwaghchaure/v13_12_0-change-log
rohitwaghchaure Oct 5, 2021
696a017
bumped to version 13.12.0
rohitwaghchaure Oct 5, 2021
0bc83de
Merge branch 'version-13-pre-release' into version-13
rohitwaghchaure Oct 5, 2021
0db3f06
Merge remote-tracking branch 'upstream/version-13' into parsimony-pro…
vjFaLk Oct 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/helper/documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def docs_link_exists(body):

if response.ok:
payload = response.json()
title = payload.get("title", "").lower().strip()
head_sha = payload.get("head", {}).get("sha")
body = payload.get("body", "").lower()
title = (payload.get("title") or "").lower().strip()
head_sha = (payload.get("head") or {}).get("sha")
body = (payload.get("body") or "").lower()

if (title.startswith("feat")
and head_sha
Expand Down
8 changes: 0 additions & 8 deletions .snyk

This file was deleted.

2 changes: 1 addition & 1 deletion cypress/integration/test_organizational_chart_desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ context('Organizational Chart', () => {

it('navigates to org chart', () => {
cy.visit('/app');
cy.awesomebar('Organizational Chart');
cy.visit('/app/organizational-chart');
cy.url().should('include', '/organizational-chart');

cy.window().its('frappe.csrf_token').then(csrf_token => {
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/test_organizational_chart_mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ context('Organizational Chart Mobile', () => {
it('navigates to org chart', () => {
cy.viewport(375, 667);
cy.visit('/app');
cy.awesomebar('Organizational Chart');
cy.visit('/app/organizational-chart');
cy.url().should('include', '/organizational-chart');

cy.window().its('frappe.csrf_token').then(csrf_token => {
Expand Down
2 changes: 1 addition & 1 deletion erpnext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from erpnext.hooks import regional_overrides

__version__ = '13.11.1'
__version__ = '13.12.0'

def get_default_company(user=None):
'''Get default company for user'''
Expand Down
15 changes: 9 additions & 6 deletions erpnext/accounts/deferred_revenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,12 +374,15 @@ def make_gl_entries(doc, credit_account, debit_account, against,
try:
make_gl_entries(gl_entries, cancel=(doc.docstatus == 2), merge_entries=True)
frappe.db.commit()
except Exception:
frappe.db.rollback()
traceback = frappe.get_traceback()
frappe.log_error(message=traceback)

frappe.flags.deferred_accounting_error = True
except Exception as e:
if frappe.flags.in_test:
raise e
else:
frappe.db.rollback()
traceback = frappe.get_traceback()
frappe.log_error(message=traceback)

frappe.flags.deferred_accounting_error = True

def send_mail(deferred_process):
title = _("Error while processing deferred accounting for {0}").format(deferred_process)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ frappe.ui.form.on('Chart of Accounts Importer', {
// make company mandatory
frm.set_df_property('company', 'reqd', frm.doc.company ? 0 : 1);
frm.set_df_property('import_file_section', 'hidden', frm.doc.company ? 0 : 1);
frm.set_df_property('chart_preview', 'hidden',
$(frm.fields_dict['chart_tree'].wrapper).html()!="" ? 0 : 1);

// Show import button when file is successfully attached
if (frm.page && frm.page.show_import_button) {
create_import_button(frm);
if (frm.doc.import_file) {
frappe.run_serially([
() => generate_tree_preview(frm),
() => create_import_button(frm),
() => frm.set_df_property('chart_preview', 'hidden', 0)
]);
}

frm.set_df_property('chart_preview', 'hidden',
$(frm.fields_dict['chart_tree'].wrapper).html()!="" ? 0 : 1);
},

download_template: function(frm) {
Expand Down Expand Up @@ -77,9 +81,6 @@ frappe.ui.form.on('Chart of Accounts Importer', {
if (!frm.doc.import_file) {
frm.page.set_indicator("");
$(frm.fields_dict['chart_tree'].wrapper).empty(); // empty wrapper on removing file
} else {
generate_tree_preview(frm);
validate_csv_data(frm);
}
},

Expand All @@ -104,26 +105,9 @@ frappe.ui.form.on('Chart of Accounts Importer', {
}
});

var validate_csv_data = function(frm) {
frappe.call({
method: "erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.validate_accounts",
args: {file_name: frm.doc.import_file},
callback: function(r) {
if(r.message && r.message[0]===true) {
frm.page["show_import_button"] = true;
frm.page["total_accounts"] = r.message[1];
frm.trigger("refresh");
} else {
frm.page.set_indicator(__('Resolve error and upload again.'), 'orange');
frappe.throw(__(r.message));
}
}
});
};

var create_import_button = function(frm) {
frm.page.set_primary_action(__("Import"), function () {
frappe.call({
return frappe.call({
method: "erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.import_coa",
args: {
file_name: frm.doc.import_file,
Expand All @@ -132,7 +116,7 @@ var create_import_button = function(frm) {
freeze: true,
freeze_message: __("Creating Accounts..."),
callback: function(r) {
if(!r.exc) {
if (!r.exc) {
clearInterval(frm.page["interval"]);
frm.page.set_indicator(__('Import Successful'), 'blue');
create_reset_button(frm);
Expand All @@ -150,12 +134,33 @@ var create_reset_button = function(frm) {
}).addClass('btn btn-primary');
};

var validate_coa = function(frm) {
if (frm.doc.import_file) {
let parent = __('All Accounts');
return frappe.call({
'method': 'erpnext.accounts.doctype.chart_of_accounts_importer.chart_of_accounts_importer.get_coa',
'args': {
file_name: frm.doc.import_file,
parent: parent,
doctype: 'Chart of Accounts Importer',
file_type: frm.doc.file_type,
for_validate: 1
},
callback: function(r) {
if (r.message['show_import_button']) {
frm.page['show_import_button'] = Boolean(r.message['show_import_button']);
}
}
});
}
};

var generate_tree_preview = function(frm) {
let parent = __('All Accounts');
$(frm.fields_dict['chart_tree'].wrapper).empty(); // empty wrapper to load new data

// generate tree structure based on the csv data
new frappe.ui.Tree({
return new frappe.ui.Tree({
parent: $(frm.fields_dict['chart_tree'].wrapper),
label: parent,
expandable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@

class ChartofAccountsImporter(Document):
def validate(self):
validate_accounts(self.import_file)
if self.import_file:
get_coa('Chart of Accounts Importer', 'All Accounts', file_name=self.import_file, for_validate=1)

def validate_columns(data):
if not data:
frappe.throw(_('No data found. Seems like you uploaded a blank file'))

no_of_columns = max([len(d) for d in data])

if no_of_columns > 7:
frappe.throw(_('More columns found than expected. Please compare the uploaded file with standard template'),
title=(_("Wrong Template")))

@frappe.whitelist()
def validate_company(company):
Expand Down Expand Up @@ -55,6 +66,7 @@ def import_coa(file_name, company):
else:
data = generate_data_from_excel(file_doc, extension)

frappe.local.flags.ignore_root_company_validation = True
forest = build_forest(data)
create_charts(company, custom_chart=forest)

Expand Down Expand Up @@ -119,7 +131,7 @@ def generate_data_from_excel(file_doc, extension, as_dict=False):
return data

@frappe.whitelist()
def get_coa(doctype, parent, is_root=False, file_name=None):
def get_coa(doctype, parent, is_root=False, file_name=None, for_validate=0):
''' called by tree view (to fetch node's children) '''

file_doc, extension = get_file(file_name)
Expand All @@ -130,13 +142,21 @@ def get_coa(doctype, parent, is_root=False, file_name=None):
else:
data = generate_data_from_excel(file_doc, extension)

forest = build_forest(data)
accounts = build_tree_from_json("", chart_data=forest) # returns alist of dict in a tree render-able form
validate_columns(data)
validate_accounts(file_doc, extension)

if not for_validate:
forest = build_forest(data)
accounts = build_tree_from_json("", chart_data=forest) # returns a list of dict in a tree render-able form

# filter out to show data for the selected node only
accounts = [d for d in accounts if d['parent_account']==parent]
# filter out to show data for the selected node only
accounts = [d for d in accounts if d['parent_account']==parent]

return accounts
return accounts
else:
return {
'show_import_button': 1
}


def build_forest(data):
Expand Down Expand Up @@ -307,10 +327,7 @@ def get_sample_template(writer):


@frappe.whitelist()
def validate_accounts(file_name):

file_doc, extension = get_file(file_name)

def validate_accounts(file_doc, extension):
if extension == 'csv':
accounts = generate_data_from_csv(file_doc, as_dict=True)
else:
Expand All @@ -329,15 +346,10 @@ def validate_accounts(file_name):

validate_root(accounts_dict)

validate_account_types(accounts_dict)

return [True, len(accounts)]

def validate_root(accounts):
roots = [accounts[d] for d in accounts if not accounts[d].get('parent_account')]
if len(roots) < 4:
frappe.throw(_("Number of root accounts cannot be less than 4"))

error_messages = []

for account in roots:
Expand All @@ -346,9 +358,19 @@ def validate_root(accounts):
elif account.get("root_type") not in get_root_types() and account.get("account_name"):
error_messages.append(_("Root Type for {0} must be one of the Asset, Liability, Income, Expense and Equity").format(account.get("account_name")))

validate_missing_roots(roots)

if error_messages:
frappe.throw("<br>".join(error_messages))

def validate_missing_roots(roots):
root_types_added = set(d.get('root_type') for d in roots)

missing = list(set(get_root_types()) - root_types_added)

if missing:
frappe.throw(_("Please add Root Account for - {0}").format(' , '.join(missing)))

def get_root_types():
return ('Asset', 'Liability', 'Expense', 'Income', 'Equity')

Expand All @@ -374,23 +396,6 @@ def get_mandatory_account_types():
{'account_type': 'Stock', 'root_type': 'Asset'}
]


def validate_account_types(accounts):
account_types_for_ledger = ["Cost of Goods Sold", "Depreciation", "Fixed Asset", "Payable", "Receivable", "Stock Adjustment"]
account_types = [accounts[d]["account_type"] for d in accounts if not accounts[d]['is_group'] == 1]

missing = list(set(account_types_for_ledger) - set(account_types))
if missing:
frappe.throw(_("Please identify/create Account (Ledger) for type - {0}").format(' , '.join(missing)))

account_types_for_group = ["Bank", "Cash", "Stock"]
# fix logic bug
account_groups = [accounts[d]["account_type"] for d in accounts if accounts[d]['is_group'] == 1]

missing = list(set(account_types_for_group) - set(account_groups))
if missing:
frappe.throw(_("Please identify/create Account (Group) for type - {0}").format(' , '.join(missing)))

def unset_existing_data(company):
linked = frappe.db.sql('''select fieldname from tabDocField
where fieldtype="Link" and options="Account" and parent="Company"''', as_dict=True)
Expand Down
Loading