From 8aeb340dc8bd87651a73bbfdef9e3d2c681de878 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Thu, 19 Nov 2020 19:18:48 +0530 Subject: [PATCH 01/37] fix: add remarks to sales invoice --- .../doctype/sales_invoice/sales_invoice.py | 9 ++++-- erpnext/patches.txt | 1 + .../v12_0/update_sales_invoice_remarks.py | 32 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 erpnext/patches/v12_0/update_sales_invoice_remarks.py diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index af6c6968dc..0530aa2d23 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe, erpnext import frappe.defaults -from frappe.utils import cint, flt, add_months, today, date_diff, getdate, add_days, cstr, nowdate, get_link_to_form +from frappe.utils import cint, flt, getdate, add_days, cstr, nowdate, get_link_to_form, formatdate from frappe import _, msgprint, throw from erpnext.accounts.party import get_party_account, get_due_date from frappe.model.mapper import get_mapped_doc @@ -535,7 +535,12 @@ class SalesInvoice(SellingController): self.against_income_account = ','.join(against_acc) def add_remarks(self): - if not self.remarks: self.remarks = 'No Remarks' + if not self.remarks: + if self.po_no and self.po_date: + self.remarks = _("Against Customer Order {0} dated {1}").format(self.po_no, + formatdate(self.po_date)) + else: + self.remarks = _("No Remarks") def validate_auto_set_posting_time(self): # Don't auto set the posting date and time if invoice is amended diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 25be884117..4a38cb3ab8 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -735,3 +735,4 @@ erpnext.patches.v13_0.create_healthcare_custom_fields_in_stock_entry_detail erpnext.patches.v13_0.update_reason_for_resignation_in_employee erpnext.patches.v13_0.update_custom_fields_for_shopify execute:frappe.delete_doc("Report", "Quoted Item Comparison") +erpnext.patches.v12_0.update_sales_invoice_remarks \ No newline at end of file diff --git a/erpnext/patches/v12_0/update_sales_invoice_remarks.py b/erpnext/patches/v12_0/update_sales_invoice_remarks.py new file mode 100644 index 0000000000..7e8feaaca6 --- /dev/null +++ b/erpnext/patches/v12_0/update_sales_invoice_remarks.py @@ -0,0 +1,32 @@ +from __future__ import unicode_literals +import frappe + +from frappe import _ +from frappe.utils import formatdate + +def execute(): + si_list = frappe.db.get_all('Sales Invoice', filters = { + 'docstatus': 1, + 'remarks': 'No Remarks', + 'po_no' : ['!=', ''], + 'po_date' : ['!=', ''] + }, + fields = ['name', 'po_no', 'po_date'] + ) + + for doc in si_list: + remarks = _("Against Customer Order {0} dated {1}").format(doc.po_no, + formatdate(doc.po_date)) + + frappe.db.set_value('Sales Invoice', doc.name, 'remarks', remarks) + + gl_entry_list = frappe.db.get_all('GL Entry', filters = { + 'voucher_type': 'Sales Invoice', + 'remarks': 'No Remarks', + 'voucher_no' : doc.name + }, + fields = ['name'] + ) + + for entry in gl_entry_list: + frappe.db.set_value('GL Entry', entry.name, 'remarks', remarks) \ No newline at end of file From 9962ba86d0db913d53bf87736e1fdd2194436f09 Mon Sep 17 00:00:00 2001 From: "hasnain2808@gmail.com" Date: Wed, 16 Dec 2020 14:41:04 +0530 Subject: [PATCH 02/37] fix: charts not displaying when tree_type changed --- .../purchase_analytics/purchase_analytics.js | 72 +++++++++-------- .../report/sales_analytics/sales_analytics.js | 79 ++++++++++--------- 2 files changed, 81 insertions(+), 70 deletions(-) diff --git a/erpnext/buying/report/purchase_analytics/purchase_analytics.js b/erpnext/buying/report/purchase_analytics/purchase_analytics.js index e17973c337..7ee9f2c372 100644 --- a/erpnext/buying/report/purchase_analytics/purchase_analytics.js +++ b/erpnext/buying/report/purchase_analytics/purchase_analytics.js @@ -75,62 +75,66 @@ frappe.query_reports["Purchase Analytics"] = { return Object.assign(options, { checkboxColumn: true, events: { - onCheckRow: function(data) { + onCheckRow: function (data) { + if (!data) return; + + const data_doctype = $( + data[2].html + )[0].attributes.getNamedItem("data-doctype").value; + const tree_type = frappe.query_report.filters[0].value; + if (data_doctype != tree_type) return; + row_name = data[2].content; length = data.length; - var tree_type = frappe.query_report.filters[0].value; - - if(tree_type == "Supplier" || tree_type == "Item") { - row_values = data.slice(4,length-1).map(function (column) { - return column.content; - }) - } - else { - row_values = data.slice(3,length-1).map(function (column) { - return column.content; - }) + if (tree_type == "Supplier" || tree_type == "Item") { + row_values = data + .slice(4, length - 1) + .map(function (column) { + return column.content; + }); + } else { + row_values = data + .slice(3, length - 1) + .map(function (column) { + return column.content; + }); } - entry = { - 'name':row_name, - 'values':row_values - } + entry = { + name: row_name, + values: row_values, + }; let raw_data = frappe.query_report.chart.data; let new_datasets = raw_data.datasets; - var found = false; + let found = false; - for(var i=0; i < new_datasets.length;i++){ - if(new_datasets[i].name == row_name){ + for (let i = 0; i < new_datasets.length; i++) { + if (new_datasets[i].name == row_name) { found = true; - new_datasets.splice(i,1); + new_datasets.splice(i, 1); break; } } - if(!found){ + if (!found) { new_datasets.push(entry); } - let new_data = { labels: raw_data.labels, - datasets: new_datasets - } - - setTimeout(() => { - frappe.query_report.chart.update(new_data) - },500) - - - setTimeout(() => { - frappe.query_report.chart.draw(true); - }, 1000) + datasets: new_datasets, + }; + chart_options = { + data: new_data, + type: "line", + }; + frappe.query_report.render_chart(chart_options); frappe.query_report.raw_chart_data = new_data; }, - } + }, }); } } diff --git a/erpnext/selling/report/sales_analytics/sales_analytics.js b/erpnext/selling/report/sales_analytics/sales_analytics.js index 0e565a3fb6..aad6bfd5ef 100644 --- a/erpnext/selling/report/sales_analytics/sales_analytics.js +++ b/erpnext/selling/report/sales_analytics/sales_analytics.js @@ -74,67 +74,74 @@ frappe.query_reports["Sales Analytics"] = { return Object.assign(options, { checkboxColumn: true, events: { - onCheckRow: function(data) { + onCheckRow: function (data) { + if (!data) return; + + const data_doctype = $( + data[2].html + )[0].attributes.getNamedItem("data-doctype").value; + const tree_type = frappe.query_report.filters[0].value; + if (data_doctype != tree_type) return; + row_name = data[2].content; length = data.length; - var tree_type = frappe.query_report.filters[0].value; - - if(tree_type == "Customer") { - row_values = data.slice(4,length-1).map(function (column) { - return column.content; - }) + if (tree_type == "Customer") { + row_values = data + .slice(4, length - 1) + .map(function (column) { + return column.content; + }); } else if (tree_type == "Item") { - row_values = data.slice(5,length-1).map(function (column) { - return column.content; - }) - } - else { - row_values = data.slice(3,length-1).map(function (column) { - return column.content; - }) + row_values = data + .slice(5, length - 1) + .map(function (column) { + return column.content; + }); + } else { + row_values = data + .slice(3, length - 1) + .map(function (column) { + return column.content; + }); } entry = { - 'name':row_name, - 'values':row_values - } + name: row_name, + values: row_values, + }; let raw_data = frappe.query_report.chart.data; let new_datasets = raw_data.datasets; - var found = false; + let found = false; - for(var i=0; i < new_datasets.length;i++){ - if(new_datasets[i].name == row_name){ + for (let i = 0; i < new_datasets.length; i++) { + if (new_datasets[i].name == row_name) { found = true; - new_datasets.splice(i,1); + new_datasets.splice(i, 1); break; } } - if(!found){ + if (!found) { new_datasets.push(entry); } let new_data = { labels: raw_data.labels, - datasets: new_datasets - } - - setTimeout(() => { - frappe.query_report.chart.update(new_data) - }, 500) - - - setTimeout(() => { - frappe.query_report.chart.draw(true); - }, 1000) + datasets: new_datasets, + }; + chart_options = { + data: new_data, + type: "line", + }; + frappe.query_report.render_chart(chart_options); frappe.query_report.raw_chart_data = new_data; }, - } - }) + }, + }); }, } From 04f48a011d343cad2dbe667b68408db6d523982e Mon Sep 17 00:00:00 2001 From: Ganga Manoj Date: Fri, 18 Dec 2020 01:31:00 +0530 Subject: [PATCH 03/37] feat: Add year_to_date field --- erpnext/payroll/doctype/salary_slip/salary_slip.json | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.json b/erpnext/payroll/doctype/salary_slip/salary_slip.json index 386618cf08..b64e5a08fe 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.json +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.json @@ -69,6 +69,7 @@ "net_pay_info", "net_pay", "base_net_pay", + "year_to_date", "column_break_53", "rounded_total", "base_rounded_total", @@ -578,13 +579,18 @@ { "fieldname": "column_break_69", "fieldtype": "Column Break" + }, + { + "fieldname": "year_to_date", + "fieldtype": "Currency", + "label": "Year To Date" } ], "icon": "fa fa-file-text", "idx": 9, "is_submittable": 1, "links": [], - "modified": "2020-10-21 23:02:59.400249", + "modified": "2020-12-17 21:51:19.612940", "modified_by": "Administrator", "module": "Payroll", "name": "Salary Slip", From 9f1e018e4f868220a985af6784c1940a67d47b82 Mon Sep 17 00:00:00 2001 From: Ganga Manoj Date: Fri, 18 Dec 2020 01:35:27 +0530 Subject: [PATCH 04/37] feat: Compute year_to_date --- .../doctype/salary_slip/salary_slip.py | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 20365b191d..27de46acc3 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -35,6 +35,9 @@ class SalarySlip(TransactionBase): def autoname(self): self.name = make_autoname(self.series) + def before_save(self): + self.compute_year_to_date() + def validate(self): self.status = self.get_status() self.validate_dates() @@ -1125,6 +1128,26 @@ class SalarySlip(TransactionBase): self.gross_pay += self.earnings[i].amount self.net_pay = flt(self.gross_pay) - flt(self.total_deduction) + def compute_year_to_date(self): + year_to_date = 0 + fiscal_year = frappe.get_list('Fiscal Year', + fields = ['year','year_start_date','year_end_date'], + filters= {'year_start_date' : ['<=', self.start_date], + 'year_end_date' : ['>=', self.end_date] + })[0] + salary_slips_from_current_fiscal_year = frappe.get_list('Salary Slip', + fields = ['employee_name', 'start_date', 'end_date', 'net_pay'], + filters = {'employee_name' : self.employee_name, + 'start_date' : ['>=', fiscal_year.year_start_date], + 'end_date' : ['<=', fiscal_year.year_end_date] + }) + + for salary_slip in salary_slips_from_current_fiscal_year: + year_to_date += salary_slip.net_pay + + year_to_date += self.net_pay + self.year_to_date = year_to_date + def unlink_ref_doc_from_salary_slip(ref_no): linked_ss = frappe.db.sql_list("""select name from `tabSalary Slip` where journal_entry=%s and docstatus < 2""", (ref_no)) @@ -1135,4 +1158,4 @@ def unlink_ref_doc_from_salary_slip(ref_no): def generate_password_for_pdf(policy_template, employee): employee = frappe.get_doc("Employee", employee) - return policy_template.format(**employee.as_dict()) + return policy_template.format(**employee.as_dict()) \ No newline at end of file From a81519f5571f25d15c47e20eefce257c18c3f1ff Mon Sep 17 00:00:00 2001 From: Afshan Date: Fri, 18 Dec 2020 11:16:01 +0530 Subject: [PATCH 05/37] fix: error popup for submitted doc --- .../payroll/doctype/salary_slip/salary_slip.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.js b/erpnext/payroll/doctype/salary_slip/salary_slip.js index f7e22c6387..abe873d839 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.js +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.js @@ -214,14 +214,16 @@ frappe.ui.form.on('Salary Slip Timesheet', { }); var calculate_totals = function(frm) { - if (frm.doc.earnings || frm.doc.deductions) { - frappe.call({ - method: "set_totals", - doc: frm.doc, - callback: function() { - frm.refresh_fields(); - } - }); + if (frm.doc.docstatus === 0) { + if (frm.doc.earnings || frm.doc.deductions) { + frappe.call({ + method: "set_totals", + doc: frm.doc, + callback: function() { + frm.refresh_fields(); + } + }); + } } }; From 89a02d7d3f705742bc95e654e2909a821e883e45 Mon Sep 17 00:00:00 2001 From: Ganga Manoj Date: Fri, 18 Dec 2020 14:59:20 +0530 Subject: [PATCH 06/37] feat: Changed Fiscal Year to Payroll Period --- .../doctype/salary_slip/salary_slip.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 27de46acc3..0ea0684a8f 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -35,9 +35,6 @@ class SalarySlip(TransactionBase): def autoname(self): self.name = make_autoname(self.series) - def before_save(self): - self.compute_year_to_date() - def validate(self): self.status = self.get_status() self.validate_dates() @@ -52,6 +49,7 @@ class SalarySlip(TransactionBase): self.get_working_days_details(lwp = self.leave_without_pay) self.calculate_net_pay() + self.compute_year_to_date() if frappe.db.get_single_value("Payroll Settings", "max_working_hours_against_timesheet"): max_working_hours = frappe.db.get_single_value("Payroll Settings", "max_working_hours_against_timesheet") @@ -1130,19 +1128,21 @@ class SalarySlip(TransactionBase): def compute_year_to_date(self): year_to_date = 0 - fiscal_year = frappe.get_list('Fiscal Year', - fields = ['year','year_start_date','year_end_date'], - filters= {'year_start_date' : ['<=', self.start_date], - 'year_end_date' : ['>=', self.end_date] + payroll_period = frappe.get_list('Payroll Period', + fields = ['start_date','end_date','company'], + filters= {'start_date' : ['<=', self.start_date], + 'end_date' : ['>=', self.end_date], + 'company' : self.company })[0] - salary_slips_from_current_fiscal_year = frappe.get_list('Salary Slip', + salary_slips_from_current_payroll_period = frappe.get_list('Salary Slip', fields = ['employee_name', 'start_date', 'end_date', 'net_pay'], filters = {'employee_name' : self.employee_name, - 'start_date' : ['>=', fiscal_year.year_start_date], - 'end_date' : ['<=', fiscal_year.year_end_date] + 'start_date' : ['>=', payroll_period.start_date], + 'end_date' : ['<=', payroll_period.end_date], + 'name' : ['!=', self.name] }) - for salary_slip in salary_slips_from_current_fiscal_year: + for salary_slip in salary_slips_from_current_payroll_period: year_to_date += salary_slip.net_pay year_to_date += self.net_pay From 1b1df6b6bcabedcf27ebc5c1cc4f2c0fac1e73b8 Mon Sep 17 00:00:00 2001 From: Ganga Manoj Date: Fri, 18 Dec 2020 23:51:05 +0530 Subject: [PATCH 07/37] feat: Add month_to_date field --- erpnext/payroll/doctype/salary_slip/salary_slip.json | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.json b/erpnext/payroll/doctype/salary_slip/salary_slip.json index b64e5a08fe..5141868adb 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.json +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.json @@ -73,6 +73,7 @@ "column_break_53", "rounded_total", "base_rounded_total", + "month_to_date", "section_break_55", "total_in_words", "column_break_69", @@ -583,14 +584,21 @@ { "fieldname": "year_to_date", "fieldtype": "Currency", - "label": "Year To Date" + "label": "Year To Date(Company Currency)", + "options": "Company:company:default_currency", + "read_only": 1 + }, + { + "fieldname": "month_to_date", + "fieldtype": "Currency", + "label": "Month To Date" } ], "icon": "fa fa-file-text", "idx": 9, "is_submittable": 1, "links": [], - "modified": "2020-12-17 21:51:19.612940", + "modified": "2020-12-18 23:23:10.484574", "modified_by": "Administrator", "module": "Payroll", "name": "Salary Slip", From 59fbf702dad1c4231d19fe8cfb4970862e4aaad0 Mon Sep 17 00:00:00 2001 From: Ganga Manoj Date: Fri, 18 Dec 2020 23:52:11 +0530 Subject: [PATCH 08/37] feat: Compute month_to_date --- .../doctype/salary_slip/salary_slip.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 0ea0684a8f..e86a7fc315 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -50,6 +50,7 @@ class SalarySlip(TransactionBase): self.calculate_net_pay() self.compute_year_to_date() + self.compute_month_to_date() if frappe.db.get_single_value("Payroll Settings", "max_working_hours_against_timesheet"): max_working_hours = frappe.db.get_single_value("Payroll Settings", "max_working_hours_against_timesheet") @@ -1138,8 +1139,7 @@ class SalarySlip(TransactionBase): fields = ['employee_name', 'start_date', 'end_date', 'net_pay'], filters = {'employee_name' : self.employee_name, 'start_date' : ['>=', payroll_period.start_date], - 'end_date' : ['<=', payroll_period.end_date], - 'name' : ['!=', self.name] + 'end_date' : ['<', self.start_date] }) for salary_slip in salary_slips_from_current_payroll_period: @@ -1148,6 +1148,22 @@ class SalarySlip(TransactionBase): year_to_date += self.net_pay self.year_to_date = year_to_date + def compute_month_to_date(self): + month_to_date = 0 + date = datetime.datetime.strptime(self.start_date,"%Y-%m-%d") + first_day_of_the_month = "1-" + str(date.month) + "-" + str(date.year) + salary_slips_from_this_month = frappe.get_list('Salary Slip', + fields = ['employee_name', 'start_date', 'net_pay'], + filters = {'employee_name' : self.employee_name, + 'start_date' : ['>=', first_day_of_the_month], + 'end_date' : ['<', self.start_date] + }) + for salary_slip in salary_slips_from_this_month: + month_to_date += salary_slip.net_pay + + month_to_date += self.net_pay + self.month_to_date = month_to_date + def unlink_ref_doc_from_salary_slip(ref_no): linked_ss = frappe.db.sql_list("""select name from `tabSalary Slip` where journal_entry=%s and docstatus < 2""", (ref_no)) From ddd9fe49fca4f05f31bc97e462a478aa52477e2d Mon Sep 17 00:00:00 2001 From: Ganga Manoj Date: Fri, 18 Dec 2020 23:58:05 +0530 Subject: [PATCH 09/37] feat: Add month_to_date field --- erpnext/payroll/doctype/salary_slip/salary_slip.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.json b/erpnext/payroll/doctype/salary_slip/salary_slip.json index 5141868adb..d981a39953 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.json +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.json @@ -591,14 +591,16 @@ { "fieldname": "month_to_date", "fieldtype": "Currency", - "label": "Month To Date" + "label": "Month To Date(Company Currency)", + "options": "Company:company:default_currency", + "read_only": 1 } ], "icon": "fa fa-file-text", "idx": 9, "is_submittable": 1, "links": [], - "modified": "2020-12-18 23:23:10.484574", + "modified": "2020-12-18 23:57:41.042954", "modified_by": "Administrator", "module": "Payroll", "name": "Salary Slip", From c36cab81f229376cbdde96cf7cfe4ccbd33b6f36 Mon Sep 17 00:00:00 2001 From: Ganga Manoj Date: Mon, 21 Dec 2020 23:46:02 +0530 Subject: [PATCH 10/37] fix: Update year_to_date and month_to_date field labels to show company currency --- .../doctype/salary_slip/salary_slip.js | 6 +++--- .../doctype/salary_slip/salary_slip.json | 20 +++++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.js b/erpnext/payroll/doctype/salary_slip/salary_slip.js index f7e22c6387..5694871762 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.js +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.js @@ -125,15 +125,15 @@ frappe.ui.form.on("Salary Slip", { change_form_labels: function(frm, company_currency) { frm.set_currency_labels(["base_hour_rate", "base_gross_pay", "base_total_deduction", - "base_net_pay", "base_rounded_total", "base_total_in_words"], + "base_net_pay", "base_rounded_total", "base_total_in_words", "base_year_to_date", "base_month_to_date"], company_currency); - frm.set_currency_labels(["hour_rate", "gross_pay", "total_deduction", "net_pay", "rounded_total", "total_in_words"], + frm.set_currency_labels(["hour_rate", "gross_pay", "total_deduction", "net_pay", "rounded_total", "total_in_words", "year_to_date", "month_to_date"], frm.doc.currency); // toggle fields frm.toggle_display(["exchange_rate", "base_hour_rate", "base_gross_pay", "base_total_deduction", - "base_net_pay", "base_rounded_total", "base_total_in_words"], + "base_net_pay", "base_rounded_total", "base_total_in_words", "base_year_to_date", "base_month_to_date"], frm.doc.currency != company_currency); }, diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.json b/erpnext/payroll/doctype/salary_slip/salary_slip.json index d981a39953..43deee43aa 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.json +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.json @@ -70,10 +70,12 @@ "net_pay", "base_net_pay", "year_to_date", + "base_year_to_date", "column_break_53", "rounded_total", "base_rounded_total", "month_to_date", + "base_month_to_date", "section_break_55", "total_in_words", "column_break_69", @@ -584,12 +586,26 @@ { "fieldname": "year_to_date", "fieldtype": "Currency", + "label": "Year To Date", + "options": "currency", + "read_only": 1 + }, + { + "fieldname": "month_to_date", + "fieldtype": "Currency", + "label": "Month To Date", + "options": "currency", + "read_only": 1 + }, + { + "fieldname": "base_year_to_date", + "fieldtype": "Currency", "label": "Year To Date(Company Currency)", "options": "Company:company:default_currency", "read_only": 1 }, { - "fieldname": "month_to_date", + "fieldname": "base_month_to_date", "fieldtype": "Currency", "label": "Month To Date(Company Currency)", "options": "Company:company:default_currency", @@ -600,7 +616,7 @@ "idx": 9, "is_submittable": 1, "links": [], - "modified": "2020-12-18 23:57:41.042954", + "modified": "2020-12-21 23:43:44.959840", "modified_by": "Administrator", "module": "Payroll", "name": "Salary Slip", From 090783804bdc59f22b8a7afee43cb3ddabcd37b2 Mon Sep 17 00:00:00 2001 From: Ganga Manoj Date: Mon, 21 Dec 2020 23:52:05 +0530 Subject: [PATCH 11/37] fix: Improve month_to_date computation --- erpnext/payroll/doctype/salary_slip/salary_slip.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index e86a7fc315..02e5f2d1d1 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe, erpnext import datetime, math -from frappe.utils import add_days, cint, cstr, flt, getdate, rounded, date_diff, money_in_words, formatdate +from frappe.utils import add_days, cint, cstr, flt, getdate, rounded, date_diff, money_in_words, formatdate, get_first_day from frappe.model.naming import make_autoname from frappe import msgprint, _ @@ -1150,8 +1150,7 @@ class SalarySlip(TransactionBase): def compute_month_to_date(self): month_to_date = 0 - date = datetime.datetime.strptime(self.start_date,"%Y-%m-%d") - first_day_of_the_month = "1-" + str(date.month) + "-" + str(date.year) + first_day_of_the_month = get_first_day(self.start_date) salary_slips_from_this_month = frappe.get_list('Salary Slip', fields = ['employee_name', 'start_date', 'net_pay'], filters = {'employee_name' : self.employee_name, From d556847fca7ac82e7f11fc5d30de30ebb45ad63e Mon Sep 17 00:00:00 2001 From: Anurag Mishra Date: Thu, 17 Dec 2020 15:17:25 +0530 Subject: [PATCH 12/37] fix: allow addition and removal of employee in payroll Entry --- .../payroll_employee_detail.json | 5 +-- .../doctype/payroll_entry/payroll_entry.js | 38 ++++++++++--------- .../doctype/payroll_entry/payroll_entry.json | 5 +-- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/erpnext/payroll/doctype/payroll_employee_detail/payroll_employee_detail.json b/erpnext/payroll/doctype/payroll_employee_detail/payroll_employee_detail.json index 8a55224dca..09c7eb9a45 100644 --- a/erpnext/payroll/doctype/payroll_employee_detail/payroll_employee_detail.json +++ b/erpnext/payroll/doctype/payroll_employee_detail/payroll_employee_detail.json @@ -17,8 +17,7 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Employee", - "options": "Employee", - "read_only": 1 + "options": "Employee" }, { "fetch_from": "employee.employee_name", @@ -52,7 +51,7 @@ ], "istable": 1, "links": [], - "modified": "2020-09-30 12:40:07.999878", + "modified": "2020-12-17 15:43:29.542977", "modified_by": "Administrator", "module": "Payroll", "name": "Payroll Employee Detail", diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js index cb48abbc36..28236c0499 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js @@ -31,7 +31,7 @@ frappe.ui.form.on('Payroll Entry', { refresh: function(frm) { if (frm.doc.docstatus == 0) { - if(!frm.is_new()) { + if (!frm.is_new()) { frm.page.clear_primary_action(); frm.add_custom_button(__("Get Employees"), function() { @@ -61,33 +61,33 @@ frappe.ui.form.on('Payroll Entry', { doc: frm.doc, method: 'fill_employee_details', }).then(r => { - if (r.docs && r.docs[0].employees){ + if (r.docs && r.docs[0].employees) { frm.employees = r.docs[0].employees; frm.dirty(); frm.save(); frm.refresh(); - if(r.docs[0].validate_attendance){ + if (r.docs[0].validate_attendance) { render_employee_attendance(frm, r.message); } } - }) + }); }, create_salary_slips: function(frm) { frm.call({ doc: frm.doc, method: "create_salary_slips", - callback: function(r) { + callback: function() { frm.refresh(); frm.toolbar.refresh(); } - }) + }); }, add_context_buttons: function(frm) { - if(frm.doc.salary_slips_submitted || (frm.doc.__onload && frm.doc.__onload.submitted_ss)) { + if (frm.doc.salary_slips_submitted || (frm.doc.__onload && frm.doc.__onload.submitted_ss)) { frm.events.add_bank_entry_button(frm); - } else if(frm.doc.salary_slips_created) { + } else if (frm.doc.salary_slips_created) { frm.add_custom_button(__("Submit Salary Slip"), function() { submit_salary_slip(frm); }).addClass("btn-primary"); @@ -192,9 +192,9 @@ frappe.ui.form.on('Payroll Entry', { }, start_date: function (frm) { - if(!in_progress && frm.doc.start_date){ + if (!in_progress && frm.doc.start_date) { frm.trigger("set_end_date"); - }else{ + } else { // reset flag in_progress = false; } @@ -228,7 +228,7 @@ frappe.ui.form.on('Payroll Entry', { } }, - set_end_date: function(frm){ + set_end_date: function(frm) { frappe.call({ method: 'erpnext.payroll.doctype.payroll_entry.payroll_entry.get_end_date', args: { @@ -243,9 +243,9 @@ frappe.ui.form.on('Payroll Entry', { }); }, - validate_attendance: function(frm){ - if(frm.doc.validate_attendance && frm.doc.employees){ - frappe.call({ + validate_attendance: function(frm) { + if (frm.doc.validate_attendance && frm.doc.employees) { + frappe.call ({ method: 'validate_employee_attendance', args: {}, callback: function(r) { @@ -255,7 +255,7 @@ frappe.ui.form.on('Payroll Entry', { freeze: true, freeze_message: __('Validating Employee Attendance...') }); - }else{ + } else { frm.fields_dict.attendance_detail_html.html(""); } }, @@ -274,14 +274,16 @@ const submit_salary_slip = function (frm) { frappe.call({ method: 'submit_salary_slips', args: {}, - callback: function() {frm.events.refresh(frm);}, + callback: function() { + frm.events.refresh(frm); + }, doc: frm.doc, freeze: true, freeze_message: __('Submitting Salary Slips and creating Journal Entry...') }); }, function() { - if(frappe.dom.freeze_count) { + if (frappe.dom.freeze_count) { frappe.dom.unfreeze(); frm.events.refresh(frm); } @@ -316,4 +318,4 @@ let render_employee_attendance = function(frm, data) { data: data }) ); -} +}; diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.json b/erpnext/payroll/doctype/payroll_entry/payroll_entry.json index 7a48dd1475..0444134aa4 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.json +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.json @@ -129,8 +129,7 @@ "fieldname": "employees", "fieldtype": "Table", "label": "Employee Details", - "options": "Payroll Employee Detail", - "read_only": 1 + "options": "Payroll Employee Detail" }, { "fieldname": "section_break_13", @@ -290,7 +289,7 @@ "icon": "fa fa-cog", "is_submittable": 1, "links": [], - "modified": "2020-10-23 13:00:33.753228", + "modified": "2020-12-17 15:13:17.766210", "modified_by": "Administrator", "module": "Payroll", "name": "Payroll Entry", From 527a156512f773c092b13465f567e06258e708cf Mon Sep 17 00:00:00 2001 From: Anurag Mishra Date: Wed, 23 Dec 2020 17:22:51 +0530 Subject: [PATCH 13/37] feat: validated employees whose salary has been already precessed --- .../doctype/payroll_entry/payroll_entry.js | 104 +++++++++++++----- .../doctype/payroll_entry/payroll_entry.py | 25 ++++- 2 files changed, 97 insertions(+), 32 deletions(-) diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js index 28236c0499..2288a27791 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.js +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.js @@ -10,15 +10,22 @@ frappe.ui.form.on('Payroll Entry', { } frm.toggle_reqd(['payroll_frequency'], !frm.doc.salary_slip_based_on_timesheet); - frm.set_query("department", function() { + frm.events.department_filters(frm); + frm.events.payroll_payable_account_filters(frm); + }, + + department_filters: function (frm) { + frm.set_query("department", function () { return { "filters": { "company": frm.doc.company, } }; }); + }, - frm.set_query("payroll_payable_account", function() { + payroll_payable_account_filters: function (frm) { + frm.set_query("payroll_payable_account", function () { return { filters: { "company": frm.doc.company, @@ -29,12 +36,12 @@ frappe.ui.form.on('Payroll Entry', { }); }, - refresh: function(frm) { + refresh: function (frm) { if (frm.doc.docstatus == 0) { if (!frm.is_new()) { frm.page.clear_primary_action(); frm.add_custom_button(__("Get Employees"), - function() { + function () { frm.events.get_employee_details(frm); } ).toggleClass('btn-primary', !(frm.doc.employees || []).length); @@ -42,7 +49,7 @@ frappe.ui.form.on('Payroll Entry', { if ((frm.doc.employees || []).length) { frm.page.clear_primary_action(); frm.page.set_primary_action(__('Create Salary Slips'), () => { - frm.save('Submit').then(()=>{ + frm.save('Submit').then(() => { frm.page.clear_primary_action(); frm.refresh(); frm.events.refresh(frm); @@ -73,36 +80,36 @@ frappe.ui.form.on('Payroll Entry', { }); }, - create_salary_slips: function(frm) { + create_salary_slips: function (frm) { frm.call({ doc: frm.doc, method: "create_salary_slips", - callback: function() { + callback: function () { frm.refresh(); frm.toolbar.refresh(); } }); }, - add_context_buttons: function(frm) { + add_context_buttons: function (frm) { if (frm.doc.salary_slips_submitted || (frm.doc.__onload && frm.doc.__onload.submitted_ss)) { frm.events.add_bank_entry_button(frm); } else if (frm.doc.salary_slips_created) { - frm.add_custom_button(__("Submit Salary Slip"), function() { + frm.add_custom_button(__("Submit Salary Slip"), function () { submit_salary_slip(frm); }).addClass("btn-primary"); } }, - add_bank_entry_button: function(frm) { + add_bank_entry_button: function (frm) { frappe.call({ method: 'erpnext.payroll.doctype.payroll_entry.payroll_entry.payroll_entry_has_bank_entries', args: { 'name': frm.doc.name }, - callback: function(r) { + callback: function (r) { if (r.message && !r.message.submitted) { - frm.add_custom_button("Make Bank Entry", function() { + frm.add_custom_button("Make Bank Entry", function () { make_bank_entry(frm); }).addClass("btn-primary"); } @@ -141,8 +148,37 @@ frappe.ui.form.on('Payroll Entry', { }, payroll_frequency: function (frm) { - frm.trigger("set_start_end_dates"); - frm.events.clear_employee_table(frm); + frm.trigger("set_start_end_dates").then( ()=> { + frm.events.clear_employee_table(frm); + frm.events.get_employee_with_salary_slip_and_set_query(frm); + }); + }, + + employee_filters: function (frm, emp_list) { + frm.set_query('employee', 'employees', () => { + return { + filters: { + name: ["not in", emp_list] + } + }; + }); + }, + + get_employee_with_salary_slip_and_set_query: function (frm) { + frappe.db.get_list('Salary Slip', { + filters: { + start_date: frm.doc.start_date, + end_date: frm.doc.end_date, + docstatus: 1, + }, + fields: ['employee'] + }).then((emp) => { + var emp_list = []; + emp.forEach((employee_data) => { + emp_list.push(Object.values(employee_data)[0]); + }); + frm.events.employee_filters(frm, emp_list); + }); }, company: function (frm) { @@ -164,17 +200,17 @@ frappe.ui.form.on('Payroll Entry', { from_currency: frm.doc.currency, to_currency: company_currency, }, - callback: function(r) { + callback: function (r) { frm.set_value("exchange_rate", flt(r.message)); frm.set_df_property('exchange_rate', 'hidden', 0); - frm.set_df_property("exchange_rate", "description", "1 " + frm.doc.currency - + " = [?] " + company_currency); + frm.set_df_property("exchange_rate", "description", "1 " + frm.doc.currency + + " = [?] " + company_currency); } }); } else { frm.set_value("exchange_rate", 1.0); frm.set_df_property('exchange_rate', 'hidden', 1); - frm.set_df_property("exchange_rate", "description", "" ); + frm.set_df_property("exchange_rate", "description", ""); } } }, @@ -228,7 +264,7 @@ frappe.ui.form.on('Payroll Entry', { } }, - set_end_date: function(frm) { + set_end_date: function (frm) { frappe.call({ method: 'erpnext.payroll.doctype.payroll_entry.payroll_entry.get_end_date', args: { @@ -243,12 +279,12 @@ frappe.ui.form.on('Payroll Entry', { }); }, - validate_attendance: function(frm) { + validate_attendance: function (frm) { if (frm.doc.validate_attendance && frm.doc.employees) { - frappe.call ({ + frappe.call({ method: 'validate_employee_attendance', args: {}, - callback: function(r) { + callback: function (r) { render_employee_attendance(frm, r.message); }, doc: frm.doc, @@ -270,11 +306,11 @@ frappe.ui.form.on('Payroll Entry', { const submit_salary_slip = function (frm) { frappe.confirm(__('This will submit Salary Slips and create accrual Journal Entry. Do you want to proceed?'), - function() { + function () { frappe.call({ method: 'submit_salary_slips', args: {}, - callback: function() { + callback: function () { frm.events.refresh(frm); }, doc: frm.doc, @@ -282,7 +318,7 @@ const submit_salary_slip = function (frm) { freeze_message: __('Submitting Salary Slips and creating Journal Entry...') }); }, - function() { + function () { if (frappe.dom.freeze_count) { frappe.dom.unfreeze(); frm.events.refresh(frm); @@ -297,9 +333,11 @@ let make_bank_entry = function (frm) { return frappe.call({ doc: cur_frm.doc, method: "make_payment_entry", - callback: function() { + callback: function () { frappe.set_route( - 'List', 'Journal Entry', {"Journal Entry Account.reference_name": frm.doc.name} + 'List', 'Journal Entry', { + "Journal Entry Account.reference_name": frm.doc.name + } ); }, freeze: true, @@ -311,11 +349,19 @@ let make_bank_entry = function (frm) { } }; - -let render_employee_attendance = function(frm, data) { +let render_employee_attendance = function (frm, data) { frm.fields_dict.attendance_detail_html.html( frappe.render_template('employees_to_mark_attendance', { data: data }) ); }; + +frappe.ui.form.on('Payroll Employee Detail', { + employee: function(frm) { + frm.events.clear_employee_table(frm); + if (!frm.doc.payroll_frequency) { + frappe.throw(__("Please set a Payroll Frequency")); + } + } +}); diff --git a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py index 8c2d9740ec..a25a6e7a32 100644 --- a/erpnext/payroll/doctype/payroll_entry/payroll_entry.py +++ b/erpnext/payroll/doctype/payroll_entry/payroll_entry.py @@ -6,7 +6,7 @@ from __future__ import unicode_literals import frappe, erpnext from frappe.model.document import Document from dateutil.relativedelta import relativedelta -from frappe.utils import cint, flt, nowdate, add_days, getdate, fmt_money, add_to_date, DATE_FORMAT, date_diff +from frappe.utils import cint, flt, add_days, getdate, add_to_date, DATE_FORMAT, date_diff, comma_and from frappe import _ from erpnext.accounts.utils import get_fiscal_year from erpnext.hr.doctype.employee.employee import get_holiday_list_for_employee @@ -19,16 +19,26 @@ class PayrollEntry(Document): # check if salary slips were manually submitted entries = frappe.db.count("Salary Slip", {'payroll_entry': self.name, 'docstatus': 1}, ['name']) if cint(entries) == len(self.employees): - self.set_onload("submitted_ss", True) + self.set_onload("submitted_ss", True) def on_submit(self): self.create_salary_slips() def before_submit(self): + self.validate_employee_details() if self.validate_attendance: if self.validate_employee_attendance(): frappe.throw(_("Cannot Submit, Employees left to mark attendance")) + def validate_employee_details(self): + emp_with_sal_slip = [] + for employee_details in self.employees: + if frappe.db.exists("Salary Slip", {"employee": employee_details.employee, "start_date": self.start_date, "end_date": self.end_date, "docstatus": 1}): + emp_with_sal_slip.append(employee_details.employee) + + if len(emp_with_sal_slip): + frappe.throw(_("Salary Slip already exists for {0} ").format(comma_and(emp_with_sal_slip))) + def on_cancel(self): frappe.delete_doc("Salary Slip", frappe.db.sql_list("""select name from `tabSalary Slip` where payroll_entry=%s """, (self.name))) @@ -71,8 +81,17 @@ class PayrollEntry(Document): and t2.docstatus = 1 %s order by t2.from_date desc """ % cond, {"sal_struct": tuple(sal_struct), "from_date": self.end_date, "payroll_payable_account": self.payroll_payable_account}, as_dict=True) + + emp_list = self.remove_payrolled_employees(emp_list) return emp_list + def remove_payrolled_employees(self, emp_list): + for employee_details in emp_list: + if frappe.db.exists("Salary Slip", {"employee": employee_details.employee, "start_date": self.start_date, "end_date": self.end_date, "docstatus": 1}): + emp_list.remove(employee_details) + + return emp_list + def fill_employee_details(self): self.set('employees', []) employees = self.get_emp_list() @@ -542,7 +561,7 @@ def create_salary_slips_for_employees(employees, args, publish_progress=True): title = _("Creating Salary Slips...")) else: salary_slip_name = frappe.db.sql( - '''SELECT + '''SELECT name FROM `tabSalary Slip` WHERE company=%s From 46d5f4c7f14f9cdbf046f2afc06ce93ff751852d Mon Sep 17 00:00:00 2001 From: "hasnain2808@gmail.com" Date: Fri, 25 Dec 2020 16:34:43 +0530 Subject: [PATCH 14/37] refactor(analytics report): linting --- .../purchase_analytics/purchase_analytics.js | 24 +++++++++++-------- .../report/sales_analytics/sales_analytics.js | 17 ++++++------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/erpnext/buying/report/purchase_analytics/purchase_analytics.js b/erpnext/buying/report/purchase_analytics/purchase_analytics.js index 7ee9f2c372..ba8535a3ae 100644 --- a/erpnext/buying/report/purchase_analytics/purchase_analytics.js +++ b/erpnext/buying/report/purchase_analytics/purchase_analytics.js @@ -87,12 +87,18 @@ frappe.query_reports["Purchase Analytics"] = { row_name = data[2].content; length = data.length; - if (tree_type == "Supplier" || tree_type == "Item") { + if (tree_type == "Supplier") { row_values = data .slice(4, length - 1) .map(function (column) { return column.content; }); + } else if (tree_type == "Item") { + row_values = data + .slice(5, length - 1) + .map(function (column) { + return column.content; + }); } else { row_values = data .slice(3, length - 1) @@ -109,17 +115,15 @@ frappe.query_reports["Purchase Analytics"] = { let raw_data = frappe.query_report.chart.data; let new_datasets = raw_data.datasets; - let found = false; - - for (let i = 0; i < new_datasets.length; i++) { - if (new_datasets[i].name == row_name) { - found = true; - new_datasets.splice(i, 1); - break; + let element_found = new_datasets.some((element, index, array)=>{ + if(element.name == row_name){ + array.splice(index, 1) + return true } - } + return false + }) - if (!found) { + if (!element_found) { new_datasets.push(entry); } let new_data = { diff --git a/erpnext/selling/report/sales_analytics/sales_analytics.js b/erpnext/selling/report/sales_analytics/sales_analytics.js index aad6bfd5ef..9089b53fb0 100644 --- a/erpnext/selling/report/sales_analytics/sales_analytics.js +++ b/erpnext/selling/report/sales_analytics/sales_analytics.js @@ -76,7 +76,6 @@ frappe.query_reports["Sales Analytics"] = { events: { onCheckRow: function (data) { if (!data) return; - const data_doctype = $( data[2].html )[0].attributes.getNamedItem("data-doctype").value; @@ -114,17 +113,15 @@ frappe.query_reports["Sales Analytics"] = { let raw_data = frappe.query_report.chart.data; let new_datasets = raw_data.datasets; - let found = false; - - for (let i = 0; i < new_datasets.length; i++) { - if (new_datasets[i].name == row_name) { - found = true; - new_datasets.splice(i, 1); - break; + let element_found = new_datasets.some((element, index, array)=>{ + if(element.name == row_name){ + array.splice(index, 1) + return true } - } + return false + }) - if (!found) { + if (!element_found) { new_datasets.push(entry); } From 40d2c6a0cccea8b08bf3480bcb563099f1429780 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 28 Dec 2020 14:08:45 +0530 Subject: [PATCH 15/37] fix: finished good produced qty validation --- .../stock/doctype/stock_entry/stock_entry.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 92d268f099..2fc7da8389 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -259,11 +259,16 @@ class StockEntry(StockController): item_code.append(item.item_code) def validate_fg_completed_qty(self): + item_wise_qty = {} if self.purpose == "Manufacture" and self.work_order: for d in self.items: - if d.is_finished_item and d.qty != self.fg_completed_qty: - frappe.throw(_("Finished product quantity {0} and For Quantity {1} cannot be different") - .format(d.qty, self.fg_completed_qty)) + if d.is_finished_item: + item_wise_qty.setdefault(d.item_code, []).append(d.qty) + + for item_code, qty_list in iteritems(item_wise_qty): + if self.fg_completed_qty != sum(qty_list): + frappe.throw(_("The finished product {0} quantity {1} and For Quantity {2} cannot be different") + .format(frappe.bold(item_code), frappe.bold(sum(qty_list)), frappe.bold(self.fg_completed_qty))) def validate_difference_account(self): if not cint(erpnext.is_perpetual_inventory_enabled(self.company)): @@ -319,7 +324,7 @@ class StockEntry(StockController): if self.purpose == "Manufacture": if validate_for_manufacture: - if d.bom_no: + if d.is_finished_item or d.is_scrap_item: d.s_warehouse = None if not d.t_warehouse: frappe.throw(_("Target warehouse is mandatory for row {0}").format(d.idx)) @@ -699,7 +704,7 @@ class StockEntry(StockController): # SLE for target warehouse self.get_sle_for_target_warehouse(sl_entries, finished_item_row) - + # reverse sl entries if cancel if self.docstatus == 2: sl_entries.reverse() @@ -727,9 +732,9 @@ class StockEntry(StockController): sle.dependant_sle_voucher_detail_no = d.name elif finished_item_row and (finished_item_row.item_code != d.item_code or finished_item_row.t_warehouse != d.s_warehouse): sle.dependant_sle_voucher_detail_no = finished_item_row.name - + sl_entries.append(sle) - + def get_sle_for_target_warehouse(self, sl_entries, finished_item_row): for d in self.get('items'): if cstr(d.t_warehouse): From 91e3c07d774fae54d7e0d67e9dd21cd8bc65c182 Mon Sep 17 00:00:00 2001 From: Afshan Date: Mon, 28 Dec 2020 19:42:46 +0530 Subject: [PATCH 16/37] fix: assest depreciation ledger --- .../asset_depreciation_ledger.py | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py b/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py index 16bef56525..2162a02eff 100644 --- a/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py +++ b/erpnext/accounts/report/asset_depreciation_ledger/asset_depreciation_ledger.py @@ -47,21 +47,22 @@ def get_data(filters): for d in gl_entries: asset_data = assets_details.get(d.against_voucher) - if not asset_data.get("accumulated_depreciation_amount"): - asset_data.accumulated_depreciation_amount = d.debit - else: - asset_data.accumulated_depreciation_amount += d.debit + if asset_data: + if not asset_data.get("accumulated_depreciation_amount"): + asset_data.accumulated_depreciation_amount = d.debit + else: + asset_data.accumulated_depreciation_amount += d.debit - row = frappe._dict(asset_data) - row.update({ - "depreciation_amount": d.debit, - "depreciation_date": d.posting_date, - "amount_after_depreciation": (flt(row.gross_purchase_amount) - - flt(row.accumulated_depreciation_amount)), - "depreciation_entry": d.voucher_no - }) + row = frappe._dict(asset_data) + row.update({ + "depreciation_amount": d.debit, + "depreciation_date": d.posting_date, + "amount_after_depreciation": (flt(row.gross_purchase_amount) - + flt(row.accumulated_depreciation_amount)), + "depreciation_entry": d.voucher_no + }) - data.append(row) + data.append(row) return data From 81285204dc5a038a4eafc0525b4956caf821337b Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 29 Dec 2020 16:25:45 +0530 Subject: [PATCH 17/37] fix: option name for the field 'Role Allowed to Create/Edit Back-dated Transactions' --- erpnext/stock/doctype/stock_settings/stock_settings.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.json b/erpnext/stock/doctype/stock_settings/stock_settings.json index 859aea2eb6..3ff396ba77 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.json +++ b/erpnext/stock/doctype/stock_settings/stock_settings.json @@ -217,7 +217,7 @@ "fieldname": "role_allowed_to_create_edit_back_dated_transactions", "fieldtype": "Link", "label": "Role Allowed to Create/Edit Back-dated Transactions", - "options": "User" + "options": "Role" }, { "fieldname": "column_break_26", @@ -234,7 +234,7 @@ "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2020-11-23 22:26:54.225608", + "modified": "2020-12-29 12:53:31.162247", "modified_by": "Administrator", "module": "Stock", "name": "Stock Settings", From 353f8f4d857381baf0bfa8e4b50e698b49f59da9 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 29 Dec 2020 22:13:40 +0530 Subject: [PATCH 18/37] fix: Add test case for YTD --- ...test_employee_tax_exemption_declaration.py | 16 ++-- .../doctype/salary_slip/salary_slip.py | 49 ++++++------ .../doctype/salary_slip/test_salary_slip.py | 76 ++++++++++++++----- .../salary_structure/test_salary_structure.py | 18 +++-- 4 files changed, 106 insertions(+), 53 deletions(-) diff --git a/erpnext/payroll/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py b/erpnext/payroll/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py index 0609d19149..311f3527f6 100644 --- a/erpnext/payroll/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py +++ b/erpnext/payroll/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py @@ -86,19 +86,21 @@ class TestEmployeeTaxExemptionDeclaration(unittest.TestCase): self.assertEqual(declaration.total_exemption_amount, 100000) -def create_payroll_period(): - if not frappe.db.exists("Payroll Period", "_Test Payroll Period"): +def create_payroll_period(**args): + args = frappe._dict(args) + name = args.name or "_Test Payroll Period" + if not frappe.db.exists("Payroll Period", name): from datetime import date payroll_period = frappe.get_doc(dict( doctype = 'Payroll Period', - name = "_Test Payroll Period", - company = erpnext.get_default_company(), - start_date = date(date.today().year, 1, 1), - end_date = date(date.today().year, 12, 31) + name = name, + company = args.company or erpnext.get_default_company(), + start_date = args.start_date or date(date.today().year, 1, 1), + end_date = args.end_date or date(date.today().year, 12, 31) )).insert() return payroll_period else: - return frappe.get_doc("Payroll Period", "_Test Payroll Period") + return frappe.get_doc("Payroll Period", name) def create_exemption_category(): if not frappe.db.exists("Employee Tax Exemption Category", "_Test Category"): diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 02e5f2d1d1..9f46d50e58 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -18,6 +18,7 @@ from erpnext.payroll.doctype.payroll_period.payroll_period import get_period_fac from erpnext.payroll.doctype.employee_benefit_application.employee_benefit_application import get_benefit_component_amount from erpnext.payroll.doctype.employee_benefit_claim.employee_benefit_claim import get_benefit_claim_amount, get_last_payroll_period_benefits from erpnext.loan_management.doctype.loan_repayment.loan_repayment import calculate_amounts, create_repayment_entry +from erpnext.accounts.utils import get_fiscal_year class SalarySlip(TransactionBase): def __init__(self, *args, **kwargs): @@ -1129,21 +1130,25 @@ class SalarySlip(TransactionBase): def compute_year_to_date(self): year_to_date = 0 - payroll_period = frappe.get_list('Payroll Period', - fields = ['start_date','end_date','company'], - filters= {'start_date' : ['<=', self.start_date], - 'end_date' : ['>=', self.end_date], - 'company' : self.company - })[0] - salary_slips_from_current_payroll_period = frappe.get_list('Salary Slip', - fields = ['employee_name', 'start_date', 'end_date', 'net_pay'], - filters = {'employee_name' : self.employee_name, - 'start_date' : ['>=', payroll_period.start_date], - 'end_date' : ['<', self.start_date] - }) + payroll_period = get_payroll_period(self.start_date, self.end_date, self.company) - for salary_slip in salary_slips_from_current_payroll_period: - year_to_date += salary_slip.net_pay + if payroll_period: + period_start_date = payroll_period.start_date + period_end_date = payroll_period.end_date + else: + # get dates based on fiscal year if no payroll period exists + fiscal_year = get_fiscal_year(date=self.start_date, company=self.company, as_dict=1) + period_start_date = fiscal_year.year_start_date + period_end_date = fiscal_year.year_end_date + + salary_slip_sum = frappe.get_list('Salary Slip', + fields = ['sum(net_pay) as sum'], + filters = {'employee_name' : self.employee_name, + 'start_date' : ['>=', period_start_date], + 'end_date' : ['<', period_end_date]}) + + + year_to_date = flt(salary_slip_sum[0].sum) if salary_slip_sum else 0.0 year_to_date += self.net_pay self.year_to_date = year_to_date @@ -1151,14 +1156,14 @@ class SalarySlip(TransactionBase): def compute_month_to_date(self): month_to_date = 0 first_day_of_the_month = get_first_day(self.start_date) - salary_slips_from_this_month = frappe.get_list('Salary Slip', - fields = ['employee_name', 'start_date', 'net_pay'], - filters = {'employee_name' : self.employee_name, - 'start_date' : ['>=', first_day_of_the_month], - 'end_date' : ['<', self.start_date] - }) - for salary_slip in salary_slips_from_this_month: - month_to_date += salary_slip.net_pay + salary_slip_sum = frappe.get_list('Salary Slip', + fields = ['sum(net_pay) as sum'], + filters = {'employee_name' : self.employee_name, + 'start_date' : ['>=', first_day_of_the_month], + 'end_date' : ['<', self.start_date] + }) + + year_to_date = flt(salary_slip_sum[0].sum) if salary_slip_sum else 0.0 month_to_date += self.net_pay self.month_to_date = month_to_date diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index 5daf1d439d..687d3602a9 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -290,6 +290,35 @@ class TestSalarySlip(unittest.TestCase): self.assertEqual(salary_slip.gross_pay, 78000) self.assertEqual(salary_slip.base_gross_pay, 78000*70) + def test_year_to_date_computation(self): + from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure + + applicant = make_employee("test_ytd@salary.com", company="_Test Company") + + payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company", + start_date=getdate("2019-04-01"), end_date=getdate("2020-03-31")) + + create_tax_slab(payroll_period, allow_tax_exemption=True, currency="INR", effective_date=getdate("2019-04-01")) + + salary_structure = make_salary_structure("Monthly Salary Structure Test for Salary Slip YTD", + "Monthly", employee=applicant, company="_Test Company", currency="INR", payroll_period=payroll_period) + + # clear salary slip for this employee + frappe.db.sql("DELETE FROM `tabSalary Slip` where employee_name = 'test_ytd@salary.com'") + + create_salary_slips_for_payroll_period(applicant, salary_structure.name, + payroll_period, deduct_random=False) + + salary_slips = frappe.get_all('Salary Slip', fields=['year_to_date'], filters={'employee_name': + 'test_ytd@salary.com'}, order_by = 'posting_date') + + net_pay = 70026.00 + month = 1 + for slip in salary_slips: + year_to_date = month * net_pay + self.assertEqual(slip.year_to_date, year_to_date) + month += 1 + def test_tax_for_payroll_period(self): data = {} # test the impact of tax exemption declaration, tax exemption proof submission @@ -631,8 +660,13 @@ def create_benefit_claim(employee, payroll_period, amount, component): }).submit() return claim_date -def create_tax_slab(payroll_period, effective_date = None, allow_tax_exemption = False, dont_submit = False, currency=erpnext.get_default_currency()): - frappe.db.sql("""delete from `tabIncome Tax Slab`""") +def create_tax_slab(payroll_period, effective_date = None, allow_tax_exemption = False, dont_submit = False, currency=None): + # frappe.db.sql("""delete from `tabIncome Tax Slab`""") + + print(payroll_period.name, effective_date) + + if not currency: + currency = erpnext.get_default_currency() slabs = [ { @@ -652,26 +686,32 @@ def create_tax_slab(payroll_period, effective_date = None, allow_tax_exemption = } ] - income_tax_slab = frappe.new_doc("Income Tax Slab") - income_tax_slab.name = "Tax Slab: " + payroll_period.name - income_tax_slab.effective_from = effective_date or add_days(payroll_period.start_date, -2) - income_tax_slab.currency = currency + income_tax_slab_name = frappe.db.get_value("Income Tax Slab", "Tax Slab: " + payroll_period.name) + if not income_tax_slab_name: + income_tax_slab = frappe.new_doc("Income Tax Slab") + income_tax_slab.name = "Tax Slab: " + payroll_period.name + income_tax_slab.effective_from = effective_date or add_days(payroll_period.start_date, -2) + income_tax_slab.currency = currency - if allow_tax_exemption: - income_tax_slab.allow_tax_exemption = 1 - income_tax_slab.standard_tax_exemption_amount = 50000 + if allow_tax_exemption: + income_tax_slab.allow_tax_exemption = 1 + income_tax_slab.standard_tax_exemption_amount = 50000 - for item in slabs: - income_tax_slab.append("slabs", item) + for item in slabs: + income_tax_slab.append("slabs", item) - income_tax_slab.append("other_taxes_and_charges", { - "description": "cess", - "percent": 4 - }) + income_tax_slab.append("other_taxes_and_charges", { + "description": "cess", + "percent": 4 + }) - income_tax_slab.save() - if not dont_submit: - income_tax_slab.submit() + income_tax_slab.save() + if not dont_submit: + income_tax_slab.submit() + + return income_tax_slab.name + else: + return income_tax_slab_name def create_salary_slips_for_payroll_period(employee, salary_structure, payroll_period, deduct_random=True): deducted_dates = [] diff --git a/erpnext/payroll/doctype/salary_structure/test_salary_structure.py b/erpnext/payroll/doctype/salary_structure/test_salary_structure.py index abb669740b..e1c6a008aa 100644 --- a/erpnext/payroll/doctype/salary_structure/test_salary_structure.py +++ b/erpnext/payroll/doctype/salary_structure/test_salary_structure.py @@ -114,7 +114,7 @@ class TestSalaryStructure(unittest.TestCase): self.assertEqual(sal_struct.currency, 'USD') def make_salary_structure(salary_structure, payroll_frequency, employee=None, dont_submit=False, other_details=None, - test_tax=False, company=None, currency=erpnext.get_default_currency()): + test_tax=False, company=None, currency=erpnext.get_default_currency(), payroll_period=None): if test_tax: frappe.db.sql("""delete from `tabSalary Structure` where name=%s""",(salary_structure)) @@ -141,16 +141,22 @@ def make_salary_structure(salary_structure, payroll_frequency, employee=None, do if employee and not frappe.db.get_value("Salary Structure Assignment", {'employee':employee, 'docstatus': 1}) and salary_structure_doc.docstatus==1: - create_salary_structure_assignment(employee, salary_structure, company=company, currency=currency) + create_salary_structure_assignment(employee, salary_structure, company=company, currency=currency, + payroll_period=payroll_period) return salary_structure_doc -def create_salary_structure_assignment(employee, salary_structure, from_date=None, company=None, currency=erpnext.get_default_currency()): +def create_salary_structure_assignment(employee, salary_structure, from_date=None, company=None, currency=erpnext.get_default_currency(), + payroll_period=None): + if frappe.db.exists("Salary Structure Assignment", {"employee": employee}): frappe.db.sql("""delete from `tabSalary Structure Assignment` where employee=%s""",(employee)) - payroll_period = create_payroll_period() - create_tax_slab(payroll_period, allow_tax_exemption=True, currency=currency) + if not payroll_period: + payroll_period = create_payroll_period() + income_tax_slab = create_tax_slab(payroll_period, allow_tax_exemption=True, currency=currency) + else: + income_tax_slab = frappe.db.get_value('Income Tax Slab', "Tax Slab: " + payroll_period.name) salary_structure_assignment = frappe.new_doc("Salary Structure Assignment") salary_structure_assignment.employee = employee @@ -162,7 +168,7 @@ def create_salary_structure_assignment(employee, salary_structure, from_date=Non salary_structure_assignment.payroll_payable_account = get_payable_account(company) salary_structure_assignment.company = company or erpnext.get_default_company() salary_structure_assignment.save(ignore_permissions=True) - salary_structure_assignment.income_tax_slab = "Tax Slab: _Test Payroll Period" + salary_structure_assignment.income_tax_slab = income_tax_slab salary_structure_assignment.submit() return salary_structure_assignment From 20133bd1dfc7fa983e78af18ea827bfee7c2e86d Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 29 Dec 2020 22:19:12 +0530 Subject: [PATCH 19/37] fix: Remove comments --- erpnext/payroll/doctype/salary_slip/test_salary_slip.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index 687d3602a9..d1eaae7490 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -661,10 +661,6 @@ def create_benefit_claim(employee, payroll_period, amount, component): return claim_date def create_tax_slab(payroll_period, effective_date = None, allow_tax_exemption = False, dont_submit = False, currency=None): - # frappe.db.sql("""delete from `tabIncome Tax Slab`""") - - print(payroll_period.name, effective_date) - if not currency: currency = erpnext.get_default_currency() From 8b7ebe5044b823ccad309f9cd241bd335af93cba Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 30 Dec 2020 12:45:46 +0530 Subject: [PATCH 20/37] fix: Test Case cleanup and fixes --- .../loan_management/doctype/loan/test_loan.py | 2 +- .../income_tax_slab/income_tax_slab.py | 7 +++-- .../doctype/salary_slip/test_salary_slip.py | 30 +++++++++++-------- .../salary_structure/test_salary_structure.py | 5 ++-- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/erpnext/loan_management/doctype/loan/test_loan.py b/erpnext/loan_management/doctype/loan/test_loan.py index a63d06590f..1d831aeb64 100644 --- a/erpnext/loan_management/doctype/loan/test_loan.py +++ b/erpnext/loan_management/doctype/loan/test_loan.py @@ -45,7 +45,7 @@ class TestLoan(unittest.TestCase): create_loan_security_price("Test Security 2", 250, "Nos", get_datetime() , get_datetime(add_to_date(nowdate(), hours=24))) self.applicant1 = make_employee("robert_loan@loan.com") - make_salary_structure("Test Salary Structure Loan", "Monthly", employee=self.applicant1, currency='INR') + make_salary_structure("Test Salary Structure Loan", "Monthly", employee=self.applicant1, currency='INR', company="_Test Company") if not frappe.db.exists("Customer", "_Test Loan Customer"): frappe.get_doc(get_customer_dict('_Test Loan Customer')).insert(ignore_permissions=True) diff --git a/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.py b/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.py index 253f023f68..e2b22a6ce9 100644 --- a/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.py +++ b/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.py @@ -3,8 +3,11 @@ # For license information, please see license.txt from __future__ import unicode_literals -# import frappe +import frappe +import erpnext from frappe.model.document import Document class IncomeTaxSlab(Document): - pass + def validate(self): + if self.company: + self.currency = erpnext.get_company_currency(self.company) diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index d1eaae7490..9e3e707f39 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -240,7 +240,12 @@ class TestSalarySlip(unittest.TestCase): interest_income_account='Interest Income Account - _TC', penalty_income_account='Penalty Income Account - _TC') - make_salary_structure("Test Loan Repayment Salary Structure", "Monthly", employee=applicant, currency='INR') + payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company", + start_date=getdate("2019-04-01"), end_date=getdate("2020-03-31")) + + make_salary_structure("Test Loan Repayment Salary Structure", "Monthly", employee=applicant, currency='INR', + payroll_period=payroll_period) + frappe.db.sql("""delete from `tabLoan""") loan = create_loan(applicant, "Car Loan", 11000, "Repay Over Number of Periods", 20, posting_date=add_months(nowdate(), -1)) loan.repay_from_salary = 1 @@ -298,7 +303,8 @@ class TestSalarySlip(unittest.TestCase): payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company", start_date=getdate("2019-04-01"), end_date=getdate("2020-03-31")) - create_tax_slab(payroll_period, allow_tax_exemption=True, currency="INR", effective_date=getdate("2019-04-01")) + create_tax_slab(payroll_period, allow_tax_exemption=True, currency="INR", effective_date=getdate("2019-04-01"), + company="_Test Company") salary_structure = make_salary_structure("Monthly Salary Structure Test for Salary Slip YTD", "Monthly", employee=applicant, company="_Test Company", currency="INR", payroll_period=payroll_period) @@ -309,15 +315,13 @@ class TestSalarySlip(unittest.TestCase): create_salary_slips_for_payroll_period(applicant, salary_structure.name, payroll_period, deduct_random=False) - salary_slips = frappe.get_all('Salary Slip', fields=['year_to_date'], filters={'employee_name': + salary_slips = frappe.get_all('Salary Slip', fields=['year_to_date', 'net_pay'], filters={'employee_name': 'test_ytd@salary.com'}, order_by = 'posting_date') - net_pay = 70026.00 - month = 1 + year_to_date = 0 for slip in salary_slips: - year_to_date = month * net_pay + year_to_date += slip.net_pay self.assertEqual(slip.year_to_date, year_to_date) - month += 1 def test_tax_for_payroll_period(self): data = {} @@ -439,10 +443,7 @@ def make_employee_salary_slip(user, payroll_frequency, salary_structure=None): salary_structure = payroll_frequency + " Salary Structure Test for Salary Slip" employee = frappe.db.get_value("Employee", {"user_id": user}) - if not frappe.db.exists('Salary Structure', salary_structure): - salary_structure_doc = make_salary_structure(salary_structure, payroll_frequency, employee) - else: - salary_structure_doc = frappe.get_doc('Salary Structure', salary_structure) + salary_structure_doc = make_salary_structure(salary_structure, payroll_frequency, employee=employee) salary_slip_name = frappe.db.get_value("Salary Slip", {"employee": frappe.db.get_value("Employee", {"user_id": user})}) if not salary_slip_name: @@ -660,7 +661,8 @@ def create_benefit_claim(employee, payroll_period, amount, component): }).submit() return claim_date -def create_tax_slab(payroll_period, effective_date = None, allow_tax_exemption = False, dont_submit = False, currency=None): +def create_tax_slab(payroll_period, effective_date = None, allow_tax_exemption = False, dont_submit = False, currency=None, + company=None): if not currency: currency = erpnext.get_default_currency() @@ -687,6 +689,10 @@ def create_tax_slab(payroll_period, effective_date = None, allow_tax_exemption = income_tax_slab = frappe.new_doc("Income Tax Slab") income_tax_slab.name = "Tax Slab: " + payroll_period.name income_tax_slab.effective_from = effective_date or add_days(payroll_period.start_date, -2) + + if company: + income_tax_slab.company = company + income_tax_slab.currency = currency if allow_tax_exemption: diff --git a/erpnext/payroll/doctype/salary_structure/test_salary_structure.py b/erpnext/payroll/doctype/salary_structure/test_salary_structure.py index e1c6a008aa..2b249c7a19 100644 --- a/erpnext/payroll/doctype/salary_structure/test_salary_structure.py +++ b/erpnext/payroll/doctype/salary_structure/test_salary_structure.py @@ -154,9 +154,8 @@ def create_salary_structure_assignment(employee, salary_structure, from_date=Non if not payroll_period: payroll_period = create_payroll_period() - income_tax_slab = create_tax_slab(payroll_period, allow_tax_exemption=True, currency=currency) - else: - income_tax_slab = frappe.db.get_value('Income Tax Slab', "Tax Slab: " + payroll_period.name) + + income_tax_slab = create_tax_slab(payroll_period, allow_tax_exemption=True, currency=currency) salary_structure_assignment = frappe.new_doc("Salary Structure Assignment") salary_structure_assignment.employee = employee From 97d055dfc34ba987f538a1f794bcc9e6eb97e87e Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 30 Dec 2020 14:06:13 +0530 Subject: [PATCH 21/37] fix: Test Case --- erpnext/payroll/doctype/salary_slip/salary_slip.py | 2 +- .../doctype/salary_structure/test_salary_structure.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 9f46d50e58..99d8a8317c 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -1163,7 +1163,7 @@ class SalarySlip(TransactionBase): 'end_date' : ['<', self.start_date] }) - year_to_date = flt(salary_slip_sum[0].sum) if salary_slip_sum else 0.0 + month_to_date = flt(salary_slip_sum[0].sum) if salary_slip_sum else 0.0 month_to_date += self.net_pay self.month_to_date = month_to_date diff --git a/erpnext/payroll/doctype/salary_structure/test_salary_structure.py b/erpnext/payroll/doctype/salary_structure/test_salary_structure.py index 2b249c7a19..f2fb558a14 100644 --- a/erpnext/payroll/doctype/salary_structure/test_salary_structure.py +++ b/erpnext/payroll/doctype/salary_structure/test_salary_structure.py @@ -155,7 +155,10 @@ def create_salary_structure_assignment(employee, salary_structure, from_date=Non if not payroll_period: payroll_period = create_payroll_period() - income_tax_slab = create_tax_slab(payroll_period, allow_tax_exemption=True, currency=currency) + income_tax_slab = frappe.db.get_value("Income Tax Slab", {"currency": currency}) + + if not income_tax_slab: + income_tax_slab = create_tax_slab(payroll_period, allow_tax_exemption=True, currency=currency) salary_structure_assignment = frappe.new_doc("Salary Structure Assignment") salary_structure_assignment.employee = employee From f946bbd03294d170d8b1093994fe2e174f381c04 Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 30 Dec 2020 14:43:42 +0530 Subject: [PATCH 22/37] fix: minor e-invoicing issues (#24239) * fix: invoice value set to zero if rounded total disabled * fix: unit rate & gross amount calculation * fix: e-invoice-setup patch * chore: no need to re-run the patch * fix: item value & invoice value calculations --- .../sales_invoice/test_sales_invoice.py | 63 +++++++++++++----- erpnext/patches.txt | 1 + .../patches/v12_0/setup_einvoice_fields.py | 1 + .../india/e_invoice/einv_template.json | 2 +- erpnext/regional/india/e_invoice/utils.py | 66 +++++++++---------- 5 files changed, 81 insertions(+), 52 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 3c681eeecf..eb223ee42c 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -1885,8 +1885,8 @@ class TestSalesInvoice(unittest.TestCase): "item_code": "_Test Item", "uom": "Nos", "warehouse": "_Test Warehouse - _TC", - "qty": 2, - "rate": 100, + "qty": 2000, + "rate": 12, "income_account": "Sales - _TC", "expense_account": "Cost of Goods Sold - _TC", "cost_center": "_Test Cost Center - _TC", @@ -1895,31 +1895,52 @@ class TestSalesInvoice(unittest.TestCase): "item_code": "_Test Item 2", "uom": "Nos", "warehouse": "_Test Warehouse - _TC", - "qty": 4, - "rate": 150, + "qty": 420, + "rate": 15, "income_account": "Sales - _TC", "expense_account": "Cost of Goods Sold - _TC", "cost_center": "_Test Cost Center - _TC", }) + si.discount_amount = 100 si.save() einvoice = make_einvoice(si) - total_item_ass_value = sum([d['AssAmt'] for d in einvoice['ItemList']]) - total_item_cgst_value = sum([d['CgstAmt'] for d in einvoice['ItemList']]) - total_item_sgst_value = sum([d['SgstAmt'] for d in einvoice['ItemList']]) - total_item_igst_value = sum([d['IgstAmt'] for d in einvoice['ItemList']]) - total_item_value = sum([d['TotItemVal'] for d in einvoice['ItemList']]) + total_item_ass_value = 0 + total_item_cgst_value = 0 + total_item_sgst_value = 0 + total_item_igst_value = 0 + total_item_value = 0 + + for item in einvoice['ItemList']: + total_item_ass_value += item['AssAmt'] + total_item_cgst_value += item['CgstAmt'] + total_item_sgst_value += item['SgstAmt'] + total_item_igst_value += item['IgstAmt'] + total_item_value += item['TotItemVal'] + + self.assertTrue(item['AssAmt'], item['TotAmt'] - item['Discount']) + self.assertTrue(item['TotItemVal'], item['AssAmt'] + item['CgstAmt'] + item['SgstAmt'] + item['IgstAmt']) + + value_details = einvoice['ValDtls'] self.assertEqual(einvoice['Version'], '1.1') - self.assertEqual(einvoice['ValDtls']['AssVal'], total_item_ass_value) - self.assertEqual(einvoice['ValDtls']['CgstVal'], total_item_cgst_value) - self.assertEqual(einvoice['ValDtls']['SgstVal'], total_item_sgst_value) - self.assertEqual(einvoice['ValDtls']['IgstVal'], total_item_igst_value) - self.assertEqual(einvoice['ValDtls']['TotInvVal'], total_item_value) + self.assertEqual(value_details['AssVal'], total_item_ass_value) + self.assertEqual(value_details['CgstVal'], total_item_cgst_value) + self.assertEqual(value_details['SgstVal'], total_item_sgst_value) + self.assertEqual(value_details['IgstVal'], total_item_igst_value) + + self.assertEqual( + value_details['TotInvVal'], + value_details['AssVal'] + value_details['CgstVal'] + + value_details['SgstVal'] + value_details['IgstVal'] + + value_details['OthChrg'] - value_details['Discount'] + ) + + self.assertEqual(value_details['TotInvVal'], si.base_grand_total) self.assertTrue(einvoice['EwbDtls']) -def make_sales_invoice_for_ewaybill(): +def make_test_address_for_ewaybill(): if not frappe.db.exists('Address', '_Test Address for Eway bill-Billing'): address = frappe.get_doc({ "address_line1": "_Test Address Line 1", @@ -1967,7 +1988,8 @@ def make_sales_invoice_for_ewaybill(): }) address.save() - + +def make_test_transporter_for_ewaybill(): if not frappe.db.exists('Supplier', '_Test Transporter'): frappe.get_doc({ "doctype": "Supplier", @@ -1978,12 +2000,17 @@ def make_sales_invoice_for_ewaybill(): "is_transporter": 1 }).insert() +def make_sales_invoice_for_ewaybill(): + make_test_address_for_ewaybill() + make_test_transporter_for_ewaybill() + gst_settings = frappe.get_doc("GST Settings") gst_account = frappe.get_all( "GST Account", fields=["cgst_account", "sgst_account", "igst_account"], - filters = {"company": "_Test Company"}) + filters = {"company": "_Test Company"} + ) if not gst_account: gst_settings.append("gst_accounts", { @@ -1995,7 +2022,7 @@ def make_sales_invoice_for_ewaybill(): gst_settings.save() - si = create_sales_invoice(do_not_save =1, rate = '60000') + si = create_sales_invoice(do_not_save=1, rate='60000') si.distance = 2000 si.company_address = "_Test Address for Eway bill-Billing" diff --git a/erpnext/patches.txt b/erpnext/patches.txt index d69dabf15c..f2e4f72d67 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -711,6 +711,7 @@ erpnext.patches.v13_0.delete_old_sales_reports execute:frappe.delete_doc_if_exists("DocType", "Bank Reconciliation") erpnext.patches.v13_0.move_doctype_reports_and_notification_from_hr_to_payroll #22-06-2020 erpnext.patches.v13_0.move_payroll_setting_separately_from_hr_settings #22-06-2020 +execute:frappe.reload_doc("regional", "doctype", "e_invoice_settings") erpnext.patches.v13_0.check_is_income_tax_component #22-06-2020 erpnext.patches.v13_0.loyalty_points_entry_for_pos_invoice #22-07-2020 erpnext.patches.v12_0.add_taxjar_integration_field diff --git a/erpnext/patches/v12_0/setup_einvoice_fields.py b/erpnext/patches/v12_0/setup_einvoice_fields.py index d0782765de..2474bc3b82 100644 --- a/erpnext/patches/v12_0/setup_einvoice_fields.py +++ b/erpnext/patches/v12_0/setup_einvoice_fields.py @@ -8,6 +8,7 @@ def execute(): if not company: return + frappe.reload_doc("custom", "doctype", "custom_field") frappe.reload_doc("regional", "doctype", "e_invoice_settings") custom_fields = { 'Sales Invoice': [ diff --git a/erpnext/regional/india/e_invoice/einv_template.json b/erpnext/regional/india/e_invoice/einv_template.json index e5751da561..60f490d616 100644 --- a/erpnext/regional/india/e_invoice/einv_template.json +++ b/erpnext/regional/india/e_invoice/einv_template.json @@ -59,7 +59,7 @@ {item_list} ], "ValDtls": {{ - "AssVal": "{invoice_value_details.base_net_total}", + "AssVal": "{invoice_value_details.base_total}", "CgstVal": "{invoice_value_details.total_cgst_amt}", "SgstVal": "{invoice_value_details.total_sgst_amt}", "IgstVal": "{invoice_value_details.total_igst_amt}", diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index cb92c42464..db96610043 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -146,12 +146,12 @@ def get_item_list(invoice): item.update(d.as_dict()) item.sr_no = d.idx - item.qty = abs(item.qty) - item.description = d.item_name - item.taxable_value = abs(item.base_net_amount) item.discount_amount = abs(item.discount_amount * item.qty) - item.unit_rate = abs(item.base_price_list_rate) if item.discount_amount else abs(item.base_net_rate) - item.gross_amount = abs(item.unit_rate * item.qty) + item.description = d.item_name + item.qty = abs(item.qty) + item.unit_rate = abs(item.base_amount / item.qty) + item.gross_amount = abs(item.base_amount) + item.taxable_value = abs(item.base_amount) item.batch_expiry_date = frappe.db.get_value('Batch', d.batch_no, 'expiry_date') if d.batch_no else None item.batch_expiry_date = format_date(item.batch_expiry_date, 'dd/mm/yyyy') if item.batch_expiry_date else None @@ -180,35 +180,35 @@ def update_item_taxes(invoice, item): item[attr] = 0 for t in invoice.taxes: + # this contains item wise tax rate & tax amount (incl. discount) item_tax_detail = json.loads(t.item_wise_tax_detail).get(item.item_code) if t.account_head in gst_accounts_list: + item_tax_rate = item_tax_detail[0] + # item tax amount excluding discount amount + item_tax_amount = (item_tax_rate / 100) * item.base_amount + if t.account_head in gst_accounts.cess_account: + item_tax_amount_after_discount = item_tax_detail[1] if t.charge_type == 'On Item Quantity': - item.cess_nadv_amount += abs(item_tax_detail[1]) + item.cess_nadv_amount += abs(item_tax_amount_after_discount) else: - item.cess_rate += item_tax_detail[0] - item.cess_amount += abs(item_tax_detail[1]) - elif t.account_head in gst_accounts.igst_account: - item.tax_rate += item_tax_detail[0] - item.igst_amount += abs(item_tax_detail[1]) - elif t.account_head in gst_accounts.sgst_account: - item.tax_rate += item_tax_detail[0] - item.sgst_amount += abs(item_tax_detail[1]) - elif t.account_head in gst_accounts.cgst_account: - item.tax_rate += item_tax_detail[0] - item.cgst_amount += abs(item_tax_detail[1]) - + item.cess_rate += item_tax_rate + item.cess_amount += abs(item_tax_amount_after_discount) + + for tax_type in ['igst', 'cgst', 'sgst']: + if t.account_head in gst_accounts[f'{tax_type}_account']: + item.tax_rate += item_tax_rate + item[f'{tax_type}_amount'] += abs(item_tax_amount) + return item def get_invoice_value_details(invoice): invoice_value_details = frappe._dict(dict()) - invoice_value_details.base_net_total = abs(invoice.base_net_total) - invoice_value_details.invoice_discount_amt = invoice.discount_amount if invoice.discount_amount and invoice.discount_amount > 0 else 0 - # discount amount cannnot be -ve in an e-invoice, so if -ve include discount in round_off - invoice_value_details.round_off = invoice.rounding_adjustment - (invoice.discount_amount if invoice.discount_amount and invoice.discount_amount < 0 else 0) - disable_rounded = frappe.db.get_single_value('Global Defaults', 'disable_rounded_total') - invoice_value_details.base_grand_total = abs(invoice.base_grand_total) if disable_rounded else abs(invoice.base_rounded_total) - invoice_value_details.grand_total = abs(invoice.grand_total) if disable_rounded else abs(invoice.rounded_total) + invoice_value_details.base_total = abs(invoice.base_total) + invoice_value_details.invoice_discount_amt = invoice.discount_amount + invoice_value_details.round_off = invoice.rounding_adjustment + invoice_value_details.base_grand_total = abs(invoice.base_rounded_total) or abs(invoice.base_grand_total) + invoice_value_details.grand_total = abs(invoice.rounded_total) or abs(invoice.grand_total) invoice_value_details = update_invoice_taxes(invoice, invoice_value_details) @@ -226,15 +226,14 @@ def update_invoice_taxes(invoice, invoice_value_details): for t in invoice.taxes: if t.account_head in gst_accounts_list: if t.account_head in gst_accounts.cess_account: + # using after discount amt since item also uses after discount amt for cess calc invoice_value_details.total_cess_amt += abs(t.base_tax_amount_after_discount_amount) - elif t.account_head in gst_accounts.igst_account: - invoice_value_details.total_igst_amt += abs(t.base_tax_amount_after_discount_amount) - elif t.account_head in gst_accounts.sgst_account: - invoice_value_details.total_sgst_amt += abs(t.base_tax_amount_after_discount_amount) - elif t.account_head in gst_accounts.cgst_account: - invoice_value_details.total_cgst_amt += abs(t.base_tax_amount_after_discount_amount) + + for tax_type in ['igst', 'cgst', 'sgst']: + if t.account_head in gst_accounts[f'{tax_type}_account']: + invoice_value_details[f'total_{tax_type}_amt'] += abs(t.base_tax_amount) else: - invoice_value_details.total_other_charges += abs(t.base_tax_amount_after_discount_amount) + invoice_value_details.total_other_charges += abs(t.base_tax_amount) return invoice_value_details @@ -358,7 +357,8 @@ def validate_einvoice(validations, einvoice, errors=[]): einvoice[fieldname] = str(value) elif value_type == 'number': is_integer = '.' not in str(field_validation.get('maximum')) - einvoice[fieldname] = flt(value, 2) if not is_integer else cint(value) + precision = 3 if '.999' in str(field_validation.get('maximum')) else 2 + einvoice[fieldname] = flt(value, precision) if not is_integer else cint(value) value = einvoice[fieldname] max_length = field_validation.get('maxLength') From 66dcaf3ab2cda4663317827e20ca87dc1fa3181b Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 30 Dec 2020 15:47:22 +0530 Subject: [PATCH 23/37] fix: Salary structure assignment in tests --- .../income_tax_slab/income_tax_slab.py | 2 +- .../doctype/salary_slip/test_salary_slip.py | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.py b/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.py index e2b22a6ce9..81e364778c 100644 --- a/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.py +++ b/erpnext/payroll/doctype/income_tax_slab/income_tax_slab.py @@ -3,7 +3,7 @@ # For license information, please see license.txt from __future__ import unicode_literals -import frappe +#import frappe import erpnext from frappe.model.document import Document diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index 9e3e707f39..bb310c4d87 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -9,7 +9,7 @@ import calendar import random from erpnext.accounts.utils import get_fiscal_year from frappe.utils.make_random import get_random -from frappe.utils import getdate, nowdate, add_days, add_months, flt, get_first_day, get_last_day +from frappe.utils import getdate, nowdate, add_days, add_months, flt, get_first_day, get_last_day, cstr from erpnext.payroll.doctype.salary_structure.salary_structure import make_salary_slip from erpnext.payroll.doctype.payroll_entry.payroll_entry import get_month_details from erpnext.hr.doctype.employee.test_employee import make_employee @@ -240,8 +240,7 @@ class TestSalarySlip(unittest.TestCase): interest_income_account='Interest Income Account - _TC', penalty_income_account='Penalty Income Account - _TC') - payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company", - start_date=getdate("2019-04-01"), end_date=getdate("2020-03-31")) + payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company") make_salary_structure("Test Loan Repayment Salary Structure", "Monthly", employee=applicant, currency='INR', payroll_period=payroll_period) @@ -300,8 +299,7 @@ class TestSalarySlip(unittest.TestCase): applicant = make_employee("test_ytd@salary.com", company="_Test Company") - payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company", - start_date=getdate("2019-04-01"), end_date=getdate("2020-03-31")) + payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company") create_tax_slab(payroll_period, allow_tax_exemption=True, currency="INR", effective_date=getdate("2019-04-01"), company="_Test Company") @@ -666,6 +664,9 @@ def create_tax_slab(payroll_period, effective_date = None, allow_tax_exemption = if not currency: currency = erpnext.get_default_currency() + if company: + currency = erpnext.get_company_currency(company) + slabs = [ { "from_amount": 250000, @@ -684,15 +685,12 @@ def create_tax_slab(payroll_period, effective_date = None, allow_tax_exemption = } ] - income_tax_slab_name = frappe.db.get_value("Income Tax Slab", "Tax Slab: " + payroll_period.name) + income_tax_slab_name = frappe.db.get_value("Income Tax Slab", {"currency": currency}) if not income_tax_slab_name: income_tax_slab = frappe.new_doc("Income Tax Slab") - income_tax_slab.name = "Tax Slab: " + payroll_period.name + income_tax_slab.name = "Tax Slab: " + payroll_period.name + " " + cstr(currency) income_tax_slab.effective_from = effective_date or add_days(payroll_period.start_date, -2) - - if company: - income_tax_slab.company = company - + income_tax_slab.company = company or '' income_tax_slab.currency = currency if allow_tax_exemption: From aa44c754de3f740b79e1fb3c686f7ce99fd6ea85 Mon Sep 17 00:00:00 2001 From: Karthikeyan S Date: Wed, 30 Dec 2020 19:22:37 +0530 Subject: [PATCH 24/37] fix(GST E Invoice): update live URLs for adaequare GSP (#24248) --- erpnext/regional/india/e_invoice/utils.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index db96610043..102a2f0f56 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -386,15 +386,15 @@ class GSPConnector(): self.invoice = frappe.get_cached_doc(doctype, docname) if doctype and docname else None self.credentials = self.get_credentials() - self.base_url = 'https://gsp.adaequare.com/' - self.authenticate_url = self.base_url + 'gsp/authenticate?grant_type=token' - self.gstin_details_url = self.base_url + 'test/enriched/ei/api/master/gstin' - self.generate_irn_url = self.base_url + 'test/enriched/ei/api/invoice' - self.irn_details_url = self.base_url + 'test/enriched/ei/api/invoice/irn' - self.cancel_irn_url = self.base_url + 'test/enriched/ei/api/invoice/cancel' - self.cancel_ewaybill_url = self.base_url + '/test/enriched/ei/api/ewayapi' - self.generate_ewaybill_url = self.base_url + 'test/enriched/ei/api/ewaybill' - + self.base_url = 'https://gsp.adaequare.com' + self.authenticate_url = self.base_url + '/gsp/authenticate?grant_type=token' + self.gstin_details_url = self.base_url + '/enriched/ei/api/master/gstin' + self.generate_irn_url = self.base_url + '/enriched/ei/api/invoice' + self.irn_details_url = self.base_url + '/enriched/ei/api/invoice/irn' + self.cancel_irn_url = self.base_url + '/enriched/ei/api/invoice/cancel' + self.cancel_ewaybill_url = self.base_url + '/enriched/ei/api/ewayapi' + self.generate_ewaybill_url = self.base_url + '/enriched/ei/api/ewaybill' + def get_credentials(self): if self.invoice: gstin = self.get_seller_gstin() From a60707873c8c976a99f83cca001d9820a1777418 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 30 Dec 2020 20:24:15 +0530 Subject: [PATCH 25/37] fix: Partial loan security unpledging --- erpnext/loan_management/doctype/loan/loan.py | 6 +-- .../loan_management/doctype/loan/test_loan.py | 37 +++++++++++++++++++ .../loan_security_shortfall.py | 1 - .../loan_security_unpledge.py | 16 +++++--- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/erpnext/loan_management/doctype/loan/loan.py b/erpnext/loan_management/doctype/loan/loan.py index cd40a665d4..578c7f116a 100644 --- a/erpnext/loan_management/doctype/loan/loan.py +++ b/erpnext/loan_management/doctype/loan/loan.py @@ -280,10 +280,10 @@ def make_loan_write_off(loan, company=None, posting_date=None, amount=0, as_dict return write_off @frappe.whitelist() -def unpledge_security(loan=None, loan_security_pledge=None, as_dict=0, save=0, submit=0, approve=0): - # if loan is passed it will be considered as full unpledge +def unpledge_security(loan=None, loan_security_pledge=None, security_map=None, as_dict=0, save=0, submit=0, approve=0): + # if no security_map is passed it will be considered as full unpledge if loan: - pledge_qty_map = get_pledged_security_qty(loan) + pledge_qty_map = security_map or get_pledged_security_qty(loan) loan_doc = frappe.get_doc('Loan', loan) unpledge_request = create_loan_security_unpledge(pledge_qty_map, loan_doc.name, loan_doc.company, loan_doc.applicant_type, loan_doc.applicant) diff --git a/erpnext/loan_management/doctype/loan/test_loan.py b/erpnext/loan_management/doctype/loan/test_loan.py index a63d06590f..2b9c7c9d0a 100644 --- a/erpnext/loan_management/doctype/loan/test_loan.py +++ b/erpnext/loan_management/doctype/loan/test_loan.py @@ -325,6 +325,43 @@ class TestLoan(unittest.TestCase): self.assertEquals(amounts['payable_principal_amount'], 0.0) self.assertEqual(amounts['interest_amount'], 0) + def test_partial_loan_security_unpledge(self): + pledge = [{ + "loan_security": "Test Security 1", + "qty": 2000.00 + }, + { + "loan_security": "Test Security 2", + "qty": 4000.00 + }] + + loan_application = create_loan_application('_Test Company', self.applicant2, 'Demand Loan', pledge) + create_pledge(loan_application) + + loan = create_demand_loan(self.applicant2, "Demand Loan", loan_application, posting_date='2019-10-01') + loan.submit() + + self.assertEquals(loan.loan_amount, 1000000) + + first_date = '2019-10-01' + last_date = '2019-10-30' + + make_loan_disbursement_entry(loan.name, loan.loan_amount, disbursement_date=first_date) + process_loan_interest_accrual_for_demand_loans(posting_date = last_date) + + repayment_entry = create_repayment_entry(loan.name, self.applicant2, add_days(last_date, 5), 600000) + repayment_entry.submit() + + unpledge_map = {'Test Security 2': 2000} + + unpledge_request = unpledge_security(loan=loan.name, security_map = unpledge_map, save=1) + unpledge_request.submit() + unpledge_request.status = 'Approved' + unpledge_request.save() + unpledge_request.submit() + unpledge_request.load_from_db() + self.assertEqual(unpledge_request.docstatus, 1) + def test_disbursal_check_with_shortfall(self): pledges = [{ "loan_security": "Test Security 2", diff --git a/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py b/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py index 8ec0bfb62c..6469806884 100644 --- a/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py +++ b/erpnext/loan_management/doctype/loan_security_shortfall/loan_security_shortfall.py @@ -81,7 +81,6 @@ def check_for_ltv_shortfall(process_loan_security_shortfall): process_loan_security_shortfall) def create_loan_security_shortfall(loan, loan_amount, security_value, shortfall_amount, process_loan_security_shortfall): - existing_shortfall = frappe.db.get_value("Loan Security Shortfall", {"loan": loan, "status": "Pending"}, "name") if existing_shortfall: diff --git a/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py b/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py index c29f325bfc..61c418d3d3 100644 --- a/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py +++ b/erpnext/loan_management/doctype/loan_security_unpledge/loan_security_unpledge.py @@ -30,6 +30,8 @@ class LoanSecurityUnpledge(Document): d.idx, frappe.bold(d.loan_security))) def validate_unpledge_qty(self): + from erpnext.loan_management.doctype.loan_security_shortfall.loan_security_shortfall import get_ltv_ratio + pledge_qty_map = get_pledged_security_qty(self.loan) ltv_ratio_map = frappe._dict(frappe.get_all("Loan Security Type", @@ -47,6 +49,8 @@ class LoanSecurityUnpledge(Document): pending_principal_amount = flt(total_payment) - flt(interest_payable) - flt(principal_paid) - flt(written_off_amount) security_value = 0 + unpledge_qty_map = {} + ltv_ratio = 0 for security in self.securities: pledged_qty = pledge_qty_map.get(security.loan_security, 0) @@ -57,13 +61,15 @@ class LoanSecurityUnpledge(Document): msg += _("You are trying to unpledge more.") frappe.throw(msg, title=_("Loan Security Unpledge Error")) - qty_after_unpledge = pledged_qty - security.qty - ltv_ratio = ltv_ratio_map.get(security.loan_security_type) + unpledge_qty_map.setdefault(security.loan_security, 0) + unpledge_qty_map[security.loan_security] += security.qty - current_price = loan_security_price_map.get(security.loan_security) - if not current_price: - frappe.throw(_("No valid Loan Security Price found for {0}").format(frappe.bold(security.loan_security))) + for security in pledge_qty_map: + if not ltv_ratio: + ltv_ratio = get_ltv_ratio(security) + qty_after_unpledge = pledge_qty_map.get(security, 0) - unpledge_qty_map.get(security, 0) + current_price = loan_security_price_map.get(security) security_value += qty_after_unpledge * current_price if not security_value and flt(pending_principal_amount, 2) > 0: From 97162166325c7cf004b7d4dd5e6d1a0c8ae628e0 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Wed, 30 Dec 2020 20:33:35 +0530 Subject: [PATCH 26/37] fix: check for string types --- erpnext/loan_management/doctype/loan/loan.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erpnext/loan_management/doctype/loan/loan.py b/erpnext/loan_management/doctype/loan/loan.py index 578c7f116a..2e0a4d13ab 100644 --- a/erpnext/loan_management/doctype/loan/loan.py +++ b/erpnext/loan_management/doctype/loan/loan.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals import frappe, math, json import erpnext from frappe import _ +from six import string_types from frappe.utils import flt, rounded, add_months, nowdate, getdate, now_datetime from erpnext.loan_management.doctype.loan_security_unpledge.loan_security_unpledge import get_pledged_security_qty from erpnext.controllers.accounts_controller import AccountsController @@ -282,6 +283,9 @@ def make_loan_write_off(loan, company=None, posting_date=None, amount=0, as_dict @frappe.whitelist() def unpledge_security(loan=None, loan_security_pledge=None, security_map=None, as_dict=0, save=0, submit=0, approve=0): # if no security_map is passed it will be considered as full unpledge + if security_map and isinstance(security_map, string_types): + security_map = json.loads(security_map) + if loan: pledge_qty_map = security_map or get_pledged_security_qty(loan) loan_doc = frappe.get_doc('Loan', loan) From d5d571ab9dca8b2853aaa551b5f82faa42f0f54c Mon Sep 17 00:00:00 2001 From: Saqib Ansari Date: Thu, 31 Dec 2020 12:55:35 +0530 Subject: [PATCH 27/37] fix: update old loan patch --- erpnext/patches/v13_0/update_old_loans.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/erpnext/patches/v13_0/update_old_loans.py b/erpnext/patches/v13_0/update_old_loans.py index 561e967d6d..8cf09aa692 100644 --- a/erpnext/patches/v13_0/update_old_loans.py +++ b/erpnext/patches/v13_0/update_old_loans.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.utils import nowdate +from frappe.utils import nowdate, flt from erpnext.accounts.doctype.account.test_account import create_account from erpnext.loan_management.doctype.process_loan_interest_accrual.process_loan_interest_accrual import process_loan_interest_accrual_for_term_loans from erpnext.loan_management.doctype.loan.loan import make_repayment_entry @@ -113,15 +113,15 @@ def execute(): interest_paid = 0 principal_paid = 0 - if total_interest > entry.interest_amount: - interest_paid = entry.interest_amount + if flt(total_interest) > flt(entry.interest_amount): + interest_paid = flt(entry.interest_amount) else: - interest_paid = total_interest + interest_paid = flt(total_interest) - if total_principal > entry.payable_principal_amount: - principal_paid = entry.payable_principal_amount + if flt(total_principal) > flt(entry.payable_principal_amount): + principal_paid = flt(entry.payable_principal_amount) else: - principal_paid = total_principal + principal_paid = flt(total_principal) frappe.db.sql(""" UPDATE `tabLoan Interest Accrual` SET paid_principal_amount = `paid_principal_amount` + %s, @@ -129,8 +129,8 @@ def execute(): WHERE name = %s""", (principal_paid, interest_paid, entry.name)) - total_principal -= principal_paid - total_interest -= interest_paid + total_principal = flt(total_principal) - principal_paid + total_interest = flt(total_interest) - interest_paid def create_loan_type(loan, loan_type_name, penalty_account): loan_type_doc = frappe.new_doc('Loan Type') From 2b67d57480038a9248dfd76cda736974fc14e64f Mon Sep 17 00:00:00 2001 From: Saqib Date: Thu, 31 Dec 2020 13:26:05 +0530 Subject: [PATCH 28/37] fix: cannot submit e-invoice if legal name not found --- erpnext/regional/india/e_invoice/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 102a2f0f56..02ce6c14c9 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -88,7 +88,7 @@ def get_party_details(address_name): gstin = address.get('gstin') gstin_details = get_gstin_details(gstin) - legal_name = gstin_details.get('LegalName') + legal_name = gstin_details.get('LegalName') or gstin_details.get('TradeName') location = gstin_details.get('AddrLoc') or address.get('city') state_code = gstin_details.get('StateCode') pincode = gstin_details.get('AddrPncd') From 8b60fe6125265fa64cf9f3c29cb63fa61d1ef346 Mon Sep 17 00:00:00 2001 From: Afshan Date: Thu, 31 Dec 2020 16:10:39 +0530 Subject: [PATCH 29/37] fix: setting correct account for sal struct assignment if not specified. --- .../salary_structure_assignment/salary_structure_assignment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.py b/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.py index dccb5df1a1..a0c3013061 100644 --- a/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.py +++ b/erpnext/payroll/doctype/salary_structure_assignment/salary_structure_assignment.py @@ -43,7 +43,7 @@ class SalaryStructureAssignment(Document): def set_payroll_payable_account(self): if not self.payroll_payable_account: - payroll_payable_account = frappe.db.get_value('Company', self.company, 'default_payable_account') + payroll_payable_account = frappe.db.get_value('Company', self.company, 'default_payroll_payable_account') if not payroll_payable_account: payroll_payable_account = frappe.db.get_value( "Account", { From e69148c266ead416c03626ee6442af6aba556723 Mon Sep 17 00:00:00 2001 From: Afshan Date: Thu, 31 Dec 2020 16:45:00 +0530 Subject: [PATCH 30/37] fix: allow leave policy assignment to be cancelled. --- .../leave_policy_assignment/leave_policy_assignment.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json index bbb4222715..a0327bdaa0 100644 --- a/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json +++ b/erpnext/hr/doctype/leave_policy_assignment/leave_policy_assignment.json @@ -111,13 +111,14 @@ ], "is_submittable": 1, "links": [], - "modified": "2020-12-17 16:27:20.311060", + "modified": "2020-12-31 16:43:30.695206", "modified_by": "Administrator", "module": "HR", "name": "Leave Policy Assignment", "owner": "Administrator", "permissions": [ { + "cancel": 1, "create": 1, "delete": 1, "email": 1, @@ -131,6 +132,7 @@ "write": 1 }, { + "cancel": 1, "create": 1, "delete": 1, "email": 1, @@ -144,6 +146,7 @@ "write": 1 }, { + "cancel": 1, "create": 1, "delete": 1, "email": 1, From 8c39ab68df1e8871be0f92e96ad5d42119e3047c Mon Sep 17 00:00:00 2001 From: vorasmit Date: Fri, 1 Jan 2021 10:54:57 +0530 Subject: [PATCH 31/37] Delete update_sales_invoice_remarks.py --- .../v12_0/update_sales_invoice_remarks.py | 32 ------------------- 1 file changed, 32 deletions(-) delete mode 100644 erpnext/patches/v12_0/update_sales_invoice_remarks.py diff --git a/erpnext/patches/v12_0/update_sales_invoice_remarks.py b/erpnext/patches/v12_0/update_sales_invoice_remarks.py deleted file mode 100644 index 7e8feaaca6..0000000000 --- a/erpnext/patches/v12_0/update_sales_invoice_remarks.py +++ /dev/null @@ -1,32 +0,0 @@ -from __future__ import unicode_literals -import frappe - -from frappe import _ -from frappe.utils import formatdate - -def execute(): - si_list = frappe.db.get_all('Sales Invoice', filters = { - 'docstatus': 1, - 'remarks': 'No Remarks', - 'po_no' : ['!=', ''], - 'po_date' : ['!=', ''] - }, - fields = ['name', 'po_no', 'po_date'] - ) - - for doc in si_list: - remarks = _("Against Customer Order {0} dated {1}").format(doc.po_no, - formatdate(doc.po_date)) - - frappe.db.set_value('Sales Invoice', doc.name, 'remarks', remarks) - - gl_entry_list = frappe.db.get_all('GL Entry', filters = { - 'voucher_type': 'Sales Invoice', - 'remarks': 'No Remarks', - 'voucher_no' : doc.name - }, - fields = ['name'] - ) - - for entry in gl_entry_list: - frappe.db.set_value('GL Entry', entry.name, 'remarks', remarks) \ No newline at end of file From 3ef965f2531b6cb89e749a0edb18998085294eb2 Mon Sep 17 00:00:00 2001 From: vorasmit Date: Fri, 1 Jan 2021 10:55:20 +0530 Subject: [PATCH 32/37] Update patches.txt --- erpnext/patches.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 4a38cb3ab8..25be884117 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -735,4 +735,3 @@ erpnext.patches.v13_0.create_healthcare_custom_fields_in_stock_entry_detail erpnext.patches.v13_0.update_reason_for_resignation_in_employee erpnext.patches.v13_0.update_custom_fields_for_shopify execute:frappe.delete_doc("Report", "Quoted Item Comparison") -erpnext.patches.v12_0.update_sales_invoice_remarks \ No newline at end of file From a245f667d068257b15d95648d8698048ce0be661 Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Sat, 2 Jan 2021 10:30:22 +0530 Subject: [PATCH 33/37] fix: pos error pop up (#24237) --- erpnext/accounts/doctype/pos_invoice/pos_invoice.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index d486ff6028..ac98dccdb5 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -267,6 +267,8 @@ class POSInvoice(SalesInvoice): from erpnext.stock.get_item_details import get_pos_profile_item_details, get_pos_profile if not self.pos_profile: pos_profile = get_pos_profile(self.company) or {} + if not pos_profile: + frappe.throw(_("No POS Profile found. Please create a New POS Profile first")) self.pos_profile = pos_profile.get('name') profile = {} From 0da201c6a5d6467d3e7a392ae1bb4c616681d364 Mon Sep 17 00:00:00 2001 From: Afshan Date: Mon, 4 Jan 2021 19:04:05 +0530 Subject: [PATCH 34/37] fix: set company in leave allocation and leave ledger entry --- .../doctype/leave_allocation/leave_allocation.json | 12 +++++++++++- .../leave_ledger_entry/leave_ledger_entry.json | 14 +++++++++++++- erpnext/patches.txt | 1 + .../v13_0/set_company_in_leave_ledger_entry.py | 7 +++++++ 4 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 erpnext/patches/v13_0/set_company_in_leave_ledger_entry.py diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.json b/erpnext/hr/doctype/leave_allocation/leave_allocation.json index 4b315014da..3a300c0d63 100644 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.json +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.json @@ -11,6 +11,7 @@ "employee", "employee_name", "department", + "company", "column_break1", "leave_type", "from_date", @@ -219,6 +220,15 @@ "label": "Leave Policy Assignment", "options": "Leave Policy Assignment", "read_only": 1 + }, + { + "fetch_from": "employee.company", + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company", + "read_only": 1, + "reqd": 1 } ], "icon": "fa fa-ok", @@ -226,7 +236,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2020-08-20 14:25:10.314323", + "modified": "2021-01-04 18:46:13.184104", "modified_by": "Administrator", "module": "HR", "name": "Leave Allocation", diff --git a/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.json b/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.json index 4abba5f2d4..d74760a5cf 100644 --- a/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.json +++ b/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.json @@ -1,4 +1,5 @@ { + "actions": [], "creation": "2019-05-09 15:47:39.760406", "doctype": "DocType", "engine": "InnoDB", @@ -8,6 +9,7 @@ "leave_type", "transaction_type", "transaction_name", + "company", "leaves", "column_break_7", "from_date", @@ -106,12 +108,22 @@ "fieldtype": "Link", "label": "Holiday List", "options": "Holiday List" + }, + { + "fetch_from": "employee.company", + "fieldname": "company", + "fieldtype": "Link", + "label": "Company", + "options": "Company", + "read_only": 1, + "reqd": 1 } ], "in_create": 1, "index_web_pages_for_search": 1, "is_submittable": 1, - "modified": "2020-09-04 12:16:36.569066", + "links": [], + "modified": "2021-01-04 18:47:45.146652", "modified_by": "Administrator", "module": "HR", "name": "Leave Ledger Entry", diff --git a/erpnext/patches.txt b/erpnext/patches.txt index f2e4f72d67..923ed2f339 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -742,3 +742,4 @@ erpnext.patches.v13_0.updates_for_multi_currency_payroll erpnext.patches.v13_0.create_leave_policy_assignment_based_on_employee_current_leave_policy erpnext.patches.v13_0.add_po_to_global_search erpnext.patches.v13_0.update_returned_qty_in_pr_dn +erpnext.patches.v13_0.set_company_in_leave_ledger_entry \ No newline at end of file diff --git a/erpnext/patches/v13_0/set_company_in_leave_ledger_entry.py b/erpnext/patches/v13_0/set_company_in_leave_ledger_entry.py new file mode 100644 index 0000000000..66857c4e65 --- /dev/null +++ b/erpnext/patches/v13_0/set_company_in_leave_ledger_entry.py @@ -0,0 +1,7 @@ +import frappe + +def execute(): + frappe.reload_doc('HR', 'doctype', 'Leave Allocation') + frappe.reload_doc('HR', 'doctype', 'Leave Ledger Entry') + frappe.db.sql("""update `tabLeave Ledger Entry` as lle set company = (select company from `tabEmployee` where employee = lle.employee)""") + frappe.db.sql("""update `tabLeave Allocation` as la set company = (select company from `tabEmployee` where employee = la.employee)""") \ No newline at end of file From 517fd8b9e6a59a1b0945d07950d60904041cc9d9 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 5 Jan 2021 09:23:39 +0530 Subject: [PATCH 35/37] fix: Ignore customer and supplier while deleting company transactions (#24279) * fix: Ignore customer and supplier while deleting company transactions * fix: Test cases fixed based on Travis --- erpnext/accounts/doctype/budget/test_budget.py | 12 ++++++------ .../doctype/payroll_entry/test_payroll_entry.py | 8 ++++---- .../doctype/salary_slip/test_salary_slip.py | 17 +++++++++-------- .../company/delete_company_transactions.py | 2 +- 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/erpnext/accounts/doctype/budget/test_budget.py b/erpnext/accounts/doctype/budget/test_budget.py index 0f115f9cc2..cd88b11761 100644 --- a/erpnext/accounts/doctype/budget/test_budget.py +++ b/erpnext/accounts/doctype/budget/test_budget.py @@ -159,10 +159,10 @@ class TestBudget(unittest.TestCase): budget = make_budget(budget_against="Cost Center") month = now_datetime().month - if month > 10: - month = 10 + if month > 9: + month = 9 - for i in range(month): + for i in range(month+1): jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date=nowdate(), submit=True) @@ -181,10 +181,10 @@ class TestBudget(unittest.TestCase): budget = make_budget(budget_against="Project") month = now_datetime().month - if month > 10: - month = 10 + if month > 9: + month = 9 - for i in range(month): + for i in range(month + 1): jv = make_journal_entry("_Test Account Cost for Goods Sold - _TC", "_Test Bank - _TC", 20000, "_Test Cost Center - _TC", posting_date=nowdate(), submit=True, project="_Test Project") diff --git a/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py b/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py index 54106c8d16..e098ec79b0 100644 --- a/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py +++ b/erpnext/payroll/doctype/payroll_entry/test_payroll_entry.py @@ -22,7 +22,7 @@ class TestPayrollEntry(unittest.TestCase): frappe.db.sql("delete from `tab%s`" % dt) make_earning_salary_component(setup=True, company_list=["_Test Company"]) - make_deduction_salary_component(setup=True, company_list=["_Test Company"]) + make_deduction_salary_component(setup=True, test_tax=False, company_list=["_Test Company"]) frappe.db.set_value("Payroll Settings", None, "email_salary_slip_to_employee", 0) @@ -107,9 +107,9 @@ class TestPayrollEntry(unittest.TestCase): frappe.db.get_value("Company", "_Test Company", "default_payroll_payable_account") != "_Test Payroll Payable - _TC": frappe.db.set_value("Company", "_Test Company", "default_payroll_payable_account", "_Test Payroll Payable - _TC") - - make_salary_structure("_Test Salary Structure 1", "Monthly", employee1, company="_Test Company", currency=frappe.db.get_value("Company", "_Test Company", "default_currency")) - make_salary_structure("_Test Salary Structure 2", "Monthly", employee2, company="_Test Company", currency=frappe.db.get_value("Company", "_Test Company", "default_currency")) + currency=frappe.db.get_value("Company", "_Test Company", "default_currency") + make_salary_structure("_Test Salary Structure 1", "Monthly", employee1, company="_Test Company", currency=currency, test_tax=False) + make_salary_structure("_Test Salary Structure 2", "Monthly", employee2, company="_Test Company", currency=currency, test_tax=False) dates = get_start_end_dates('Monthly', nowdate()) if not frappe.db.get_value("Salary Slip", {"start_date": dates.start_date, "end_date": dates.end_date}): diff --git a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py index bb310c4d87..d6fb419598 100644 --- a/erpnext/payroll/doctype/salary_slip/test_salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/test_salary_slip.py @@ -585,14 +585,6 @@ def make_deduction_salary_component(setup=False, test_tax=False, company_list=No "amount": 200, "exempted_from_income_tax": 1 - }, - { - "salary_component": 'TDS', - "abbr":'T', - "type": "Deduction", - "depends_on_payment_days": 0, - "variable_based_on_taxable_salary": 1, - "round_to_the_nearest_integer": 1 } ] if not test_tax: @@ -603,6 +595,15 @@ def make_deduction_salary_component(setup=False, test_tax=False, company_list=No "type": "Deduction", "round_to_the_nearest_integer": 1 }) + else: + data.append({ + "salary_component": 'TDS', + "abbr":'T', + "type": "Deduction", + "depends_on_payment_days": 0, + "variable_based_on_taxable_salary": 1, + "round_to_the_nearest_integer": 1 + }) if setup or test_tax: make_salary_component(data, test_tax, company_list) diff --git a/erpnext/setup/doctype/company/delete_company_transactions.py b/erpnext/setup/doctype/company/delete_company_transactions.py index 566f20cfa1..7a72fe3102 100644 --- a/erpnext/setup/doctype/company/delete_company_transactions.py +++ b/erpnext/setup/doctype/company/delete_company_transactions.py @@ -28,7 +28,7 @@ def delete_company_transactions(company_name): "Party Account", "Employee", "Sales Taxes and Charges Template", "Purchase Taxes and Charges Template", "POS Profile", "BOM", "Company", "Bank Account", "Item Tax Template", "Mode Of Payment", - "Item Default"): + "Item Default", "Customer", "Supplier"): delete_for_doctype(doctype, company_name) # reset company values From 06a401ffbfa812452c9aafc4fca5b2b5d3702554 Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Tue, 5 Jan 2021 11:54:34 +0530 Subject: [PATCH 36/37] fix: incoming rate attribute error (#24287) Co-authored-by: pateljannat --- erpnext/controllers/selling_controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 85cfb951fc..812021f5c8 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -233,7 +233,7 @@ class SellingController(StockController): 'allow_zero_valuation': d.allow_zero_valuation_rate, 'sales_invoice_item': d.get("sales_invoice_item"), 'dn_detail': d.get("dn_detail"), - 'incoming_rate': p.incoming_rate + 'incoming_rate': p.get("incoming_rate") })) else: il.append(frappe._dict({ @@ -252,7 +252,7 @@ class SellingController(StockController): 'allow_zero_valuation': d.allow_zero_valuation_rate, 'sales_invoice_item': d.get("sales_invoice_item"), 'dn_detail': d.get("dn_detail"), - 'incoming_rate': d.incoming_rate + 'incoming_rate': d.get("incoming_rate") })) return il From 1f591ab02e40ab884899059ae95f7d86315da83b Mon Sep 17 00:00:00 2001 From: Saqib Date: Tue, 5 Jan 2021 13:53:51 +0530 Subject: [PATCH 37/37] fix(e-invoicing): minor calculation fixes (#24285) --- .../controllers/sales_and_purchase_return.py | 2 + erpnext/public/js/controllers/transaction.js | 1 + erpnext/regional/india/e_invoice/utils.py | 41 +++++++++++++------ erpnext/stock/get_item_details.py | 4 +- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index 79792262c0..a048d6e2df 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -328,6 +328,7 @@ def make_return_doc(doctype, source_name, target_doc=None): target_doc.po_detail = source_doc.po_detail target_doc.pr_detail = source_doc.pr_detail target_doc.purchase_invoice_item = source_doc.name + target_doc.price_list_rate = 0 elif doctype == "Delivery Note": returned_qty_map = get_returned_qty_map_for_row(source_doc.name, doctype) @@ -353,6 +354,7 @@ def make_return_doc(doctype, source_name, target_doc=None): target_doc.dn_detail = source_doc.dn_detail target_doc.expense_account = source_doc.expense_account target_doc.sales_invoice_item = source_doc.name + target_doc.price_list_rate = 0 if default_warehouse_for_sales_return: target_doc.warehouse = default_warehouse_for_sales_return diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 3bc20f8733..bed9c14141 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -543,6 +543,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ company: me.frm.doc.company, order_type: me.frm.doc.order_type, is_pos: cint(me.frm.doc.is_pos), + is_return: cint(me.frm.doc.is_return), is_subcontracted: me.frm.doc.is_subcontracted, transaction_date: me.frm.doc.transaction_date || me.frm.doc.posting_date, ignore_pricing_rule: me.frm.doc.ignore_pricing_rule, diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index 02ce6c14c9..e5f7d2d78c 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -92,21 +92,18 @@ def get_party_details(address_name): location = gstin_details.get('AddrLoc') or address.get('city') state_code = gstin_details.get('StateCode') pincode = gstin_details.get('AddrPncd') - address_line1 = '{} {}'.format(gstin_details.get('AddrBno'), gstin_details.get('AddrFlno')) - address_line2 = '{} {}'.format(gstin_details.get('AddrBnm'), gstin_details.get('AddrSt')) - email_id = address.get('email_id') - phone = address.get('phone') - # get last 10 digit - phone = phone.replace(" ", "")[-10:] if phone else '' + address_line1 = '{} {}'.format(gstin_details.get('AddrBno') or "", gstin_details.get('AddrFlno') or "") + address_line2 = '{} {}'.format(gstin_details.get('AddrBnm') or "", gstin_details.get('AddrSt') or "") if state_code == 97: # according to einvoice standard pincode = 999999 return frappe._dict(dict( - gstin=gstin, legal_name=legal_name, location=location, - pincode=pincode, state_code=state_code, address_line1=address_line1, - address_line2=address_line2, email=email_id, phone=phone + gstin=gstin, legal_name=legal_name, + location=location, pincode=pincode, + state_code=state_code, address_line1=address_line1, + address_line2=address_line2 )) def get_gstin_details(gstin): @@ -146,9 +143,10 @@ def get_item_list(invoice): item.update(d.as_dict()) item.sr_no = d.idx - item.discount_amount = abs(item.discount_amount * item.qty) - item.description = d.item_name + item.description = d.item_name.replace('"', '\\"') + item.qty = abs(item.qty) + item.discount_amount = abs(item.discount_amount * item.qty) item.unit_rate = abs(item.base_amount / item.qty) item.gross_amount = abs(item.base_amount) item.taxable_value = abs(item.base_amount) @@ -156,6 +154,7 @@ def get_item_list(invoice): item.batch_expiry_date = frappe.db.get_value('Batch', d.batch_no, 'expiry_date') if d.batch_no else None item.batch_expiry_date = format_date(item.batch_expiry_date, 'dd/mm/yyyy') if item.batch_expiry_date else None item.is_service_item = 'N' if frappe.db.get_value('Item', d.item_code, 'is_stock_item') else 'Y' + item.serial_no = "" item = update_item_taxes(invoice, item) @@ -272,7 +271,25 @@ def get_eway_bill_details(invoice): vehicle_type=vehicle_type[invoice.gst_vehicle_type] )) +def validate_mandatory_fields(invoice): + if not invoice.company_address: + frappe.throw(_('Company Address is mandatory to fetch company GSTIN details.'), title=_('Missing Fields')) + if not invoice.customer_address: + frappe.throw(_('Customer Address is mandatory to fetch customer GSTIN details.'), title=_('Missing Fields')) + if not frappe.db.get_value('Address', invoice.company_address, 'gstin'): + frappe.throw( + _('GSTIN is mandatory to fetch company GSTIN details. Please enter GSTIN in selected company address.'), + title=_('Missing Fields') + ) + if not frappe.db.get_value('Address', invoice.customer_address, 'gstin'): + frappe.throw( + _('GSTIN is mandatory to fetch customer GSTIN details. Please enter GSTIN in selected customer address.'), + title=_('Missing Fields') + ) + def make_einvoice(invoice): + validate_mandatory_fields(invoice) + schema = read_json('einv_template') transaction_details = get_transaction_details(invoice) @@ -351,7 +368,7 @@ def validate_einvoice(validations, einvoice, errors=[]): # remove empty dicts einvoice.pop(fieldname, None) continue - + # convert to int or str if value_type == 'string': einvoice[fieldname] = str(value) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 08f7a83b89..bf45251c9d 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -74,7 +74,9 @@ def get_item_details(args, doc=None, for_validate=False, overwrite_warehouse=Tru update_party_blanket_order(args, out) - get_price_list_rate(args, item, out) + if not doc or cint(doc.get('is_return')) == 0: + # get price list rate only if the invoice is not a credit or debit note + get_price_list_rate(args, item, out) if args.customer and cint(args.is_pos): out.update(get_pos_profile_item_details(args.company, args))