From 0aceee4ae29973f0a2efded519720cdd82e3dad5 Mon Sep 17 00:00:00 2001 From: Afshan Date: Sat, 24 Oct 2020 15:18:12 +0530 Subject: [PATCH] patch: update columns --- erpnext/patches.txt | 1 + .../updates_for_multi_currency_payroll.py | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 erpnext/patches/v13_0/updates_for_multi_currency_payroll.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 8b34eaa0a87..fa8e2f41434 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -732,3 +732,4 @@ erpnext.patches.v13_0.set_youtube_video_id erpnext.patches.v13_0.print_uom_after_quantity_patch erpnext.patches.v13_0.set_payment_channel_in_payment_gateway_account erpnext.patches.v13_0.create_healthcare_custom_fields_in_stock_entry_detail +erpnext.patches.v13_0.updates_for_multi_currency_payroll.py \ No newline at end of file diff --git a/erpnext/patches/v13_0/updates_for_multi_currency_payroll.py b/erpnext/patches/v13_0/updates_for_multi_currency_payroll.py new file mode 100644 index 00000000000..cbc4a6f3583 --- /dev/null +++ b/erpnext/patches/v13_0/updates_for_multi_currency_payroll.py @@ -0,0 +1,82 @@ +# Copyright (c) 2019, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +import frappe, erpnext + +def execute(): + company = erpnext.get_default_company() + company_currency = erpnext.get_company_currency(company) + default_payroll_payable_account = frappe.db.get_value('Company', erpnext.get_company_currency(company), 'default_payroll_payable_account') + frappe.reload_doc('accounts', 'doctype', 'salary_component_account') + frappe.reload_doc('hr', 'doctype', 'employee_advance') + frappe.reload_doc('hr', 'doctype', 'leave_enchashment') + + doctype_list = [ + 'additional_salary' + 'employee_benefit_application' + 'employee_benefit_claim' + 'employee_incentive' + 'employee_tax_exemption_declaration' + 'employee_tax_exemption_proof_submission' + 'income_tax_slab' + 'payroll_entry' + 'retention_bonus' + 'salary_structure' + 'salary_structure_assignment' + 'salary_slip' + ] + + for doctype in doctype_list: + frappe.reload_doc('payroll', 'doctype', doctype) + + currency_change_list = [ + 'tabLeave Encashment', + 'tabEmployee Benefit Application', + 'tabEmployee Benefit Claim', + 'tabEmployee Incentive', + 'tabEmployee Tax Exemption Declaration', + 'tabEmployee Tax Exemption Proof Submission', + 'tabIncome Tax Slab', + 'tabAdditional Salary', + 'tabRetention Bonus', + 'tabSalary Structure' + ] + + for table in currency_change_list: + frappe.db.sql(""" + UPDATE `{0}` + SET currency = '{1}' + """.format(table, company_currency)) + + frappe.db.sql(""" + UPDATE `tabSalary Structure Assignment` + SET currency = %s, payroll_payable_account = %s + """, (company_currency, default_payroll_payable_account)) + + if frappe.db.has_column('Salary Component Account', 'default_account'): + frappe.db.sql(""" + UPDATE `tabSalary Component Account` + SET account = default_account, + """) + + frappe.db.sql(""" + UPDATE `tabPayroll Entry` + SET currency = %s, exchange_rate = 1, payroll_payable_account = %s + """, (company_currency, default_payroll_payable_account)) + + frappe.db.sql(""" + UPDATE `tabEmployee Advance` + SET currency = %s, exchange_rate = 1 + """, (company_currency)) + + frappe.db.sql(""" + UPDATE `tabSalary Slip` + SET currency = %s, + exchange_rate = 1, + base_hour_rate = hour_rate, + base_gross_pay = gross_pay, + base_total_deduction = total_deduction, + base_net_pay = net_pay, + base_rounded_total = rounded_total, + base_total_in_words = total_in_words + """, (company_currency)) \ No newline at end of file