def execute(): frappe.reload_doc("accounts", "doctype", "journal_entry") frappe.db.sql( """ update `tabJournal Entry` set total_amount_currency = %s where ifnull(multi_currency, 0) = 0 and (pay_to_recd_from is not null or pay_to_recd_from != "") """, get_default_currency()) for je in frappe.db.sql( """ select name from `tabJournal Entry` where multi_currency = 1 and (pay_to_recd_from is not null or pay_to_recd_from != "")""", as_dict=1): doc = frappe.get_doc("Journal Entry", je.name) for d in doc.get('accounts'): if d.party_type and d.party: total_amount_currency = d.account_currency elif frappe.db.get_value("Account", d.account, "account_type") in ["Bank", "Cash"]: total_amount_currency = d.account_currency frappe.db.set_value("Journal Entry", je.name, "total_amount_currency", total_amount_currency, update_modified=False)
def get_columns(): currency = get_default_currency() return [{ "label": _("Territory"), "fieldname": "territory", "fieldtype": "Link", "options": "Territory", "width": 150 }, { "label": _("Opportunity Amount"), "fieldname": "opportunity_amount", "fieldtype": "Currency", "options": currency, "width": 150 }, { "label": _("Quotation Amount"), "fieldname": "quotation_amount", "fieldtype": "Currency", "options": currency, "width": 150 }, { "label": _("Order Amount"), "fieldname": "order_amount", "fieldtype": "Currency", "options": currency, "width": 150 }, { "label": _("Billing Amount"), "fieldname": "billing_amount", "fieldtype": "Currency", "options": currency, "width": 150 }]
def test_duplicate_entry_for_payroll_period(self): declaration = frappe.get_doc({ "doctype": "Employee Tax Exemption Declaration", "employee": frappe.get_value("Employee", {"user_id": "*****@*****.**"}, "name"), "company": erpbee.get_default_company(), "payroll_period": "_Test Payroll Period", "currency": erpbee.get_default_currency(), "declarations": [ dict(exemption_sub_category="_Test Sub Category", exemption_category="_Test Category", amount=100000), dict(exemption_sub_category="_Test1 Sub Category", exemption_category="_Test Category", amount=50000), ] }).insert() duplicate_declaration = frappe.get_doc({ "doctype": "Employee Tax Exemption Declaration", "employee": frappe.get_value("Employee", {"user_id": "*****@*****.**"}, "name"), "company": erpbee.get_default_company(), "payroll_period": "_Test Payroll Period", "currency": erpbee.get_default_currency(), "declarations": [ dict(exemption_sub_category="_Test Sub Category", exemption_category="_Test Category", amount=100000) ] }) self.assertRaises(DuplicateDeclarationError, duplicate_declaration.insert) duplicate_declaration.employee = frappe.get_value( "Employee", {"user_id": "*****@*****.**"}, "name") self.assertTrue(duplicate_declaration.insert)
def make_salary_structure(salary_structure, payroll_frequency, employee=None, dont_submit=False, other_details=None, test_tax=False, company=None, currency=erpbee.get_default_currency(), payroll_period=None): if test_tax: frappe.db.sql("""delete from `tabSalary Structure` where name=%s""", (salary_structure)) if not frappe.db.exists('Salary Structure', salary_structure): details = { "doctype": "Salary Structure", "name": salary_structure, "company": company or erpbee.get_default_company(), "earnings": make_earning_salary_component(test_tax=test_tax, company_list=["_Test Company"]), "deductions": make_deduction_salary_component(test_tax=test_tax, company_list=["_Test Company"]), "payroll_frequency": payroll_frequency, "payment_account": get_random("Account", filters={'account_currency': currency}), "currency": currency } if other_details and isinstance(other_details, dict): details.update(other_details) salary_structure_doc = frappe.get_doc(details) salary_structure_doc.insert() if not dont_submit: salary_structure_doc.submit() else: salary_structure_doc = frappe.get_doc("Salary Structure", salary_structure) 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, payroll_period=payroll_period) return salary_structure_doc
def create_tax_slab(payroll_period, effective_date=None, allow_tax_exemption=False, dont_submit=False, currency=None, company=None): if not currency: currency = erpbee.get_default_currency() if company: currency = erpbee.get_company_currency(company) slabs = [{ "from_amount": 250000, "to_amount": 500000, "percent_deduction": 5, "condition": "annual_taxable_earning > 500000" }, { "from_amount": 500001, "to_amount": 1000000, "percent_deduction": 20 }, { "from_amount": 1000001, "percent_deduction": 30 }] 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 + " " + cstr( currency) income_tax_slab.effective_from = effective_date or add_days( payroll_period.start_date, -2) income_tax_slab.company = company or '' income_tax_slab.currency = currency 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) income_tax_slab.append("other_taxes_and_charges", { "description": "cess", "percent": 4 }) 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_benefit_claim(employee, payroll_period, amount, component): claim_date = add_months(payroll_period.start_date, random.randint(0, 11)) frappe.get_doc({ "doctype": "Employee Benefit Claim", "employee": employee, "claimed_amount": amount, "claim_date": claim_date, "earning_component": component, "currency": erpbee.get_default_currency() }).submit() return claim_date
def create_additional_salary(employee, payroll_period, amount): salary_date = add_months(payroll_period.start_date, random.randint(0, 11)) frappe.get_doc({ "doctype": "Additional Salary", "employee": employee, "company": erpbee.get_default_company(), "salary_component": "Performance Bonus", "payroll_date": salary_date, "amount": amount, "type": "Earning", "currency": erpbee.get_default_currency() }).submit() return salary_date
def get_additional_salary(emp_id): create_salary_component("Recurring Salary Component") add_sal = frappe.new_doc("Additional Salary") add_sal.employee = emp_id add_sal.salary_component = "Recurring Salary Component" add_sal.is_recurring = 1 add_sal.from_date = add_days(nowdate(), -50) add_sal.to_date = add_days(nowdate(), 180) add_sal.amount = 5000 add_sal.currency = erpbee.get_default_currency() add_sal.save() add_sal.submit() return add_sal
def set_missing_customer_details(self): if not self.customer_group: self.customer_group = frappe.db.get_single_value('Selling Settings', 'customer_group') or get_root_of('Customer Group') if not self.territory: self.territory = frappe.db.get_single_value('Selling Settings', 'territory') or get_root_of('Territory') if not self.default_price_list: self.default_price_list = frappe.db.get_single_value('Selling Settings', 'selling_price_list') if not self.customer_group or not self.territory or not self.default_price_list: frappe.msgprint(_('Please set defaults for Customer Group, Territory and Selling Price List in Selling Settings'), alert=True) if not self.default_currency: self.default_currency = get_default_currency() if not self.language: self.language = frappe.db.get_single_value('System Settings', 'language')
def load_dashboard_info(self): company_default_currency = get_default_currency() allocated_amount = frappe.db.sql( """ select sum(allocated_amount) from `tabSales Team` where sales_person = %s and docstatus=1 and parenttype = 'Sales Order' """, (self.sales_person_name)) info = {} info["allocated_amount"] = flt( allocated_amount[0][0]) if allocated_amount else 0 info["currency"] = company_default_currency self.set_onload('dashboard_info', info)
def create_exemption_declaration(employee, payroll_period): create_exemption_category() declaration = frappe.get_doc({ "doctype": "Employee Tax Exemption Declaration", "employee": employee, "payroll_period": payroll_period, "company": erpbee.get_default_company(), "currency": erpbee.get_default_currency() }) declaration.append( "declarations", { "exemption_sub_category": "_Test Sub Category", "exemption_category": "_Test Category", "amount": 100000 }) declaration.submit()
def create_proof_submission(employee, payroll_period, amount): submission_date = add_months(payroll_period.start_date, random.randint(0, 11)) proof_submission = frappe.get_doc({ "doctype": "Employee Tax Exemption Proof Submission", "employee": employee, "payroll_period": payroll_period.name, "submission_date": submission_date, "currency": erpbee.get_default_currency() }) proof_submission.append( "tax_exemption_proofs", { "exemption_sub_category": "_Test Sub Category", "exemption_category": "_Test Category", "type_of_proof": "Test", "amount": amount }) proof_submission.submit() return submission_date
def get_ordered_to_be_billed_data(args): doctype, party = args.get('doctype'), args.get('party') child_tab = doctype + " Item" precision = get_field_precision( frappe.get_meta(child_tab).get_field("billed_amt"), currency=get_default_currency()) or 2 project_field = get_project_field(doctype, party) return frappe.db.sql(""" Select `{parent_tab}`.name, `{parent_tab}`.{date_field}, `{parent_tab}`.{party}, `{parent_tab}`.{party}_name, `{child_tab}`.item_code, `{child_tab}`.base_amount, (`{child_tab}`.billed_amt * ifnull(`{parent_tab}`.conversion_rate, 1)), (`{child_tab}`.base_rate * ifnull(`{child_tab}`.returned_qty, 0)), (`{child_tab}`.base_amount - (`{child_tab}`.billed_amt * ifnull(`{parent_tab}`.conversion_rate, 1)) - (`{child_tab}`.base_rate * ifnull(`{child_tab}`.returned_qty, 0))), `{child_tab}`.item_name, `{child_tab}`.description, {project_field}, `{parent_tab}`.company from `{parent_tab}`, `{child_tab}` where `{parent_tab}`.name = `{child_tab}`.parent and `{parent_tab}`.docstatus = 1 and `{parent_tab}`.status not in ('Closed', 'Completed') and `{child_tab}`.amount > 0 and (`{child_tab}`.base_amount - round(`{child_tab}`.billed_amt * ifnull(`{parent_tab}`.conversion_rate, 1), {precision}) - (`{child_tab}`.base_rate * ifnull(`{child_tab}`.returned_qty, 0))) > 0 order by `{parent_tab}`.{order} {order_by} """.format(parent_tab='tab' + doctype, child_tab='tab' + child_tab, precision=precision, party=party, date_field=args.get('date'), project_field=project_field, order=args.get('order'), order_by=args.get('order_by')))
def create_salary_structure_assignment(employee, salary_structure, from_date=None, company=None, currency=erpbee.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)) if not payroll_period: payroll_period = create_payroll_period() 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 salary_structure_assignment.base = 50000 salary_structure_assignment.variable = 5000 salary_structure_assignment.from_date = from_date or add_days( nowdate(), -1) salary_structure_assignment.salary_structure = salary_structure salary_structure_assignment.currency = currency salary_structure_assignment.payroll_payable_account = get_payable_account( company) salary_structure_assignment.company = company or erpbee.get_default_company( ) salary_structure_assignment.save(ignore_permissions=True) salary_structure_assignment.income_tax_slab = income_tax_slab salary_structure_assignment.submit() return salary_structure_assignment
def test_duplicate_category_in_declaration(self): declaration = frappe.get_doc({ "doctype": "Employee Tax Exemption Declaration", "employee": frappe.get_value("Employee", {"user_id": "*****@*****.**"}, "name"), "company": erpbee.get_default_company(), "payroll_period": "_Test Payroll Period", "currency": erpbee.get_default_currency(), "declarations": [ dict(exemption_sub_category="_Test Sub Category", exemption_category="_Test Category", amount=100000), dict(exemption_sub_category="_Test Sub Category", exemption_category="_Test Category", amount=50000) ] }) self.assertRaises(frappe.ValidationError, declaration.save)
def test_salary_structures_assignment(self): company_currency = erpbee.get_default_currency() salary_structure = make_salary_structure("Salary Structure Sample", "Monthly", currency=company_currency) employee = "*****@*****.**" employee_doc_name = make_employee(employee) # clear the already assigned stuctures frappe.db.sql( '''delete from `tabSalary Structure Assignment` where employee=%s and salary_structure=%s ''', ("*****@*****.**", salary_structure.name)) #test structure_assignment salary_structure.assign_salary_structure(employee=employee_doc_name, from_date='2013-01-01', base=5000, variable=200) salary_structure_assignment = frappe.get_doc( "Salary Structure Assignment", { 'employee': employee_doc_name, 'from_date': '2013-01-01' }) self.assertEqual(salary_structure_assignment.docstatus, 1) self.assertEqual(salary_structure_assignment.base, 5000) self.assertEqual(salary_structure_assignment.variable, 200)
def test_exemption_amount(self): declaration = frappe.get_doc({ "doctype": "Employee Tax Exemption Declaration", "employee": frappe.get_value("Employee", {"user_id": "*****@*****.**"}, "name"), "company": erpbee.get_default_company(), "payroll_period": "_Test Payroll Period", "currency": erpbee.get_default_currency(), "declarations": [ dict(exemption_sub_category="_Test Sub Category", exemption_category="_Test Category", amount=80000), dict(exemption_sub_category="_Test1 Sub Category", exemption_category="_Test Category", amount=60000), ] }).insert() self.assertEqual(declaration.total_exemption_amount, 100000)