Aditya Hase | f3c22f3 | 2019-01-22 18:22:20 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 2 | import frappe, re |
| 3 | from frappe import _ |
Nabin Hait | 49446ba | 2019-04-25 19:54:20 +0530 | [diff] [blame] | 4 | from frappe.utils import cstr, flt, date_diff, nowdate |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 5 | from erpnext.regional.india import states, state_numbers |
Nabin Hait | b962fc1 | 2017-07-17 18:02:31 +0530 | [diff] [blame] | 6 | from erpnext.controllers.taxes_and_totals import get_itemised_tax, get_itemised_taxable_amount |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 7 | from erpnext.controllers.accounts_controller import get_taxes_and_charges |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 8 | from erpnext.hr.utils import get_salary_assignment |
| 9 | from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 10 | |
| 11 | def validate_gstin_for_india(doc, method): |
rushin29 | 08a209b | 2019-03-15 15:28:50 +0530 | [diff] [blame] | 12 | if hasattr(doc, 'gst_state') and doc.gst_state: |
| 13 | doc.gst_state_number = state_numbers[doc.gst_state] |
FinByz Tech Pvt. Ltd | 237a871 | 2019-01-22 20:49:06 +0530 | [diff] [blame] | 14 | if not hasattr(doc, 'gstin') or not doc.gstin: |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 15 | return |
| 16 | |
Deepesh Garg | 459155f | 2019-06-14 12:01:34 +0530 | [diff] [blame] | 17 | gst_category = [] |
| 18 | |
| 19 | if len(doc.links): |
| 20 | link_doctype = doc.links[0].get("link_doctype") |
| 21 | link_name = doc.links[0].get("link_name") |
| 22 | |
| 23 | if link_doctype in ["Customer", "Supplier"]: |
| 24 | gst_category = frappe.db.get_value(link_doctype, {'name': link_name}, ['gst_category']) |
| 25 | |
Sagar Vora | d75095b | 2019-01-23 14:40:01 +0530 | [diff] [blame] | 26 | doc.gstin = doc.gstin.upper().strip() |
Sagar Vora | 07cf4e8 | 2019-01-10 11:07:51 +0530 | [diff] [blame] | 27 | if not doc.gstin or doc.gstin == 'NA': |
| 28 | return |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 29 | |
Sagar Vora | 07cf4e8 | 2019-01-10 11:07:51 +0530 | [diff] [blame] | 30 | if len(doc.gstin) != 15: |
| 31 | frappe.throw(_("Invalid GSTIN! A GSTIN must have 15 characters.")) |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 32 | |
Deepesh Garg | 459155f | 2019-06-14 12:01:34 +0530 | [diff] [blame] | 33 | if gst_category and gst_category == 'UIN Holders': |
| 34 | p = re.compile("^[0-9]{4}[A-Z]{3}[0-9]{5}[0-9A-Z]{3}") |
| 35 | if not p.match(doc.gstin): |
| 36 | frappe.throw(_("Invalid GSTIN! The input you've entered doesn't match the GSTIN format for UIN Holders or Non-Resident OIDAR Service Providers")) |
| 37 | else: |
| 38 | p = re.compile("^[0-9]{2}[A-Z]{4}[0-9A-Z]{1}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}[1-9A-Z]{1}[0-9A-Z]{1}$") |
| 39 | if not p.match(doc.gstin): |
| 40 | frappe.throw(_("Invalid GSTIN! The input you've entered doesn't match the format of GSTIN.")) |
Rushabh Mehta | 7231f29 | 2017-07-13 15:00:56 +0530 | [diff] [blame] | 41 | |
Deepesh Garg | 459155f | 2019-06-14 12:01:34 +0530 | [diff] [blame] | 42 | validate_gstin_check_digit(doc.gstin) |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 43 | |
Deepesh Garg | 459155f | 2019-06-14 12:01:34 +0530 | [diff] [blame] | 44 | if not doc.gst_state: |
| 45 | if not doc.state: |
| 46 | return |
| 47 | state = doc.state.lower() |
| 48 | states_lowercase = {s.lower():s for s in states} |
| 49 | if state in states_lowercase: |
| 50 | doc.gst_state = states_lowercase[state] |
| 51 | else: |
| 52 | return |
Rushabh Mehta | b3c8f44 | 2017-06-21 17:22:38 +0530 | [diff] [blame] | 53 | |
Deepesh Garg | 459155f | 2019-06-14 12:01:34 +0530 | [diff] [blame] | 54 | doc.gst_state_number = state_numbers[doc.gst_state] |
| 55 | if doc.gst_state_number != doc.gstin[:2]: |
| 56 | frappe.throw(_("Invalid GSTIN! First 2 digits of GSTIN should match with State number {0}.") |
| 57 | .format(doc.gst_state_number)) |
Sagar Vora | 07cf4e8 | 2019-01-10 11:07:51 +0530 | [diff] [blame] | 58 | |
| 59 | def validate_gstin_check_digit(gstin): |
| 60 | ''' Function to validate the check digit of the GSTIN.''' |
karthikeyan5 | 2825b92 | 2019-01-09 19:15:10 +0530 | [diff] [blame] | 61 | factor = 1 |
| 62 | total = 0 |
| 63 | code_point_chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
karthikeyan5 | 2825b92 | 2019-01-09 19:15:10 +0530 | [diff] [blame] | 64 | mod = len(code_point_chars) |
Sagar Vora | 07cf4e8 | 2019-01-10 11:07:51 +0530 | [diff] [blame] | 65 | input_chars = gstin[:-1] |
karthikeyan5 | 2825b92 | 2019-01-09 19:15:10 +0530 | [diff] [blame] | 66 | for char in input_chars: |
| 67 | digit = factor * code_point_chars.find(char) |
Sagar Vora | 07cf4e8 | 2019-01-10 11:07:51 +0530 | [diff] [blame] | 68 | digit = (digit // mod) + (digit % mod) |
karthikeyan5 | 2825b92 | 2019-01-09 19:15:10 +0530 | [diff] [blame] | 69 | total += digit |
| 70 | factor = 2 if factor == 1 else 1 |
Sagar Vora | 07cf4e8 | 2019-01-10 11:07:51 +0530 | [diff] [blame] | 71 | if gstin[-1] != code_point_chars[((mod - (total % mod)) % mod)]: |
| 72 | frappe.throw(_("Invalid GSTIN! The check digit validation has failed. " + |
| 73 | "Please ensure you've typed the GSTIN correctly.")) |
Rushabh Mehta | 7231f29 | 2017-07-13 15:00:56 +0530 | [diff] [blame] | 74 | |
Nabin Hait | b962fc1 | 2017-07-17 18:02:31 +0530 | [diff] [blame] | 75 | def get_itemised_tax_breakup_header(item_doctype, tax_accounts): |
| 76 | if frappe.get_meta(item_doctype).has_field('gst_hsn_code'): |
| 77 | return [_("HSN/SAC"), _("Taxable Amount")] + tax_accounts |
| 78 | else: |
| 79 | return [_("Item"), _("Taxable Amount")] + tax_accounts |
Nabin Hait | b95ecd7 | 2018-02-16 13:19:04 +0530 | [diff] [blame] | 80 | |
Nabin Hait | b962fc1 | 2017-07-17 18:02:31 +0530 | [diff] [blame] | 81 | def get_itemised_tax_breakup_data(doc): |
| 82 | itemised_tax = get_itemised_tax(doc.taxes) |
| 83 | |
| 84 | itemised_taxable_amount = get_itemised_taxable_amount(doc.items) |
Nabin Hait | b95ecd7 | 2018-02-16 13:19:04 +0530 | [diff] [blame] | 85 | |
Nabin Hait | b962fc1 | 2017-07-17 18:02:31 +0530 | [diff] [blame] | 86 | if not frappe.get_meta(doc.doctype + " Item").has_field('gst_hsn_code'): |
| 87 | return itemised_tax, itemised_taxable_amount |
| 88 | |
| 89 | item_hsn_map = frappe._dict() |
| 90 | for d in doc.items: |
| 91 | item_hsn_map.setdefault(d.item_code or d.item_name, d.get("gst_hsn_code")) |
| 92 | |
| 93 | hsn_tax = {} |
| 94 | for item, taxes in itemised_tax.items(): |
| 95 | hsn_code = item_hsn_map.get(item) |
| 96 | hsn_tax.setdefault(hsn_code, frappe._dict()) |
| 97 | for tax_account, tax_detail in taxes.items(): |
| 98 | hsn_tax[hsn_code].setdefault(tax_account, {"tax_rate": 0, "tax_amount": 0}) |
| 99 | hsn_tax[hsn_code][tax_account]["tax_rate"] = tax_detail.get("tax_rate") |
| 100 | hsn_tax[hsn_code][tax_account]["tax_amount"] += tax_detail.get("tax_amount") |
| 101 | |
| 102 | # set taxable amount |
| 103 | hsn_taxable_amount = frappe._dict() |
| 104 | for item, taxable_amount in itemised_taxable_amount.items(): |
| 105 | hsn_code = item_hsn_map.get(item) |
| 106 | hsn_taxable_amount.setdefault(hsn_code, 0) |
| 107 | hsn_taxable_amount[hsn_code] += itemised_taxable_amount.get(item) |
| 108 | |
| 109 | return hsn_tax, hsn_taxable_amount |
| 110 | |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 111 | def set_place_of_supply(doc, method=None): |
| 112 | doc.place_of_supply = get_place_of_supply(doc, doc.doctype) |
Nabin Hait | b95ecd7 | 2018-02-16 13:19:04 +0530 | [diff] [blame] | 113 | |
Rushabh Mehta | 7231f29 | 2017-07-13 15:00:56 +0530 | [diff] [blame] | 114 | # don't remove this function it is used in tests |
| 115 | def test_method(): |
| 116 | '''test function''' |
Nabin Hait | b95ecd7 | 2018-02-16 13:19:04 +0530 | [diff] [blame] | 117 | return 'overridden' |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 118 | |
| 119 | def get_place_of_supply(out, doctype): |
| 120 | if not frappe.get_meta('Address').has_field('gst_state'): return |
| 121 | |
| 122 | if doctype in ("Sales Invoice", "Delivery Note"): |
| 123 | address_name = out.shipping_address_name or out.customer_address |
| 124 | elif doctype == "Purchase Invoice": |
| 125 | address_name = out.shipping_address or out.supplier_address |
| 126 | |
| 127 | if address_name: |
| 128 | address = frappe.db.get_value("Address", address_name, ["gst_state", "gst_state_number"], as_dict=1) |
Rohit Waghchaure | b6a735e | 2018-10-11 10:40:34 +0530 | [diff] [blame] | 129 | if address and address.gst_state and address.gst_state_number: |
Nabin Hait | 2390da6 | 2018-08-30 16:16:35 +0530 | [diff] [blame] | 130 | return cstr(address.gst_state_number) + "-" + cstr(address.gst_state) |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 131 | |
| 132 | def get_regional_address_details(out, doctype, company): |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 133 | out.place_of_supply = get_place_of_supply(out, doctype) |
| 134 | |
| 135 | if not out.place_of_supply: return |
| 136 | |
| 137 | if doctype in ("Sales Invoice", "Delivery Note"): |
| 138 | master_doctype = "Sales Taxes and Charges Template" |
Shreya | 2ad8172 | 2018-06-05 16:49:29 +0530 | [diff] [blame] | 139 | if not out.company_gstin: |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 140 | return |
Shreya | 2ad8172 | 2018-06-05 16:49:29 +0530 | [diff] [blame] | 141 | elif doctype == "Purchase Invoice": |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 142 | master_doctype = "Purchase Taxes and Charges Template" |
Shreya | 2ad8172 | 2018-06-05 16:49:29 +0530 | [diff] [blame] | 143 | if not out.supplier_gstin: |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 144 | return |
| 145 | |
Rohit Waghchaure | de82ad1 | 2018-06-07 13:20:57 +0530 | [diff] [blame] | 146 | if ((doctype in ("Sales Invoice", "Delivery Note") and out.company_gstin |
| 147 | and out.company_gstin[:2] != out.place_of_supply[:2]) or (doctype == "Purchase Invoice" |
| 148 | and out.supplier_gstin and out.supplier_gstin[:2] != out.place_of_supply[:2])): |
Shreya Shah | 4fa600a | 2018-06-05 11:27:53 +0530 | [diff] [blame] | 149 | default_tax = frappe.db.get_value(master_doctype, {"company": company, "is_inter_state":1, "disabled":0}) |
| 150 | else: |
| 151 | default_tax = frappe.db.get_value(master_doctype, {"company": company, "disabled":0, "is_default": 1}) |
| 152 | |
| 153 | if not default_tax: |
| 154 | return |
| 155 | out["taxes_and_charges"] = default_tax |
| 156 | out.taxes = get_taxes_and_charges(master_doctype, default_tax) |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 157 | |
| 158 | def calculate_annual_eligible_hra_exemption(doc): |
Rushabh Mehta | 708e47a | 2018-08-08 16:37:31 +0530 | [diff] [blame] | 159 | basic_component = frappe.get_cached_value('Company', doc.company, "basic_component") |
| 160 | hra_component = frappe.get_cached_value('Company', doc.company, "hra_component") |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 161 | if not (basic_component and hra_component): |
| 162 | frappe.throw(_("Please mention Basic and HRA component in Company")) |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 163 | annual_exemption, monthly_exemption, hra_amount = 0, 0, 0 |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 164 | if hra_component and basic_component: |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 165 | assignment = get_salary_assignment(doc.employee, nowdate()) |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 166 | if assignment: |
| 167 | hra_component_exists = frappe.db.exists("Salary Detail", { |
| 168 | "parent": assignment.salary_structure, |
| 169 | "salary_component": hra_component, |
| 170 | "parentfield": "earnings", |
| 171 | "parenttype": "Salary Structure" |
| 172 | }) |
Nabin Hait | 6b9d64c | 2019-05-16 11:23:04 +0530 | [diff] [blame] | 173 | |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 174 | if hra_component_exists: |
| 175 | basic_amount, hra_amount = get_component_amt_from_salary_slip(doc.employee, |
| 176 | assignment.salary_structure, basic_component, hra_component) |
| 177 | if hra_amount: |
| 178 | if doc.monthly_house_rent: |
| 179 | annual_exemption = calculate_hra_exemption(assignment.salary_structure, |
Nabin Hait | 6b9d64c | 2019-05-16 11:23:04 +0530 | [diff] [blame] | 180 | basic_amount, hra_amount, doc.monthly_house_rent, doc.rented_in_metro_city) |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 181 | if annual_exemption > 0: |
| 182 | monthly_exemption = annual_exemption / 12 |
| 183 | else: |
| 184 | annual_exemption = 0 |
Nabin Hait | 6b9d64c | 2019-05-16 11:23:04 +0530 | [diff] [blame] | 185 | |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 186 | elif doc.docstatus == 1: |
| 187 | frappe.throw(_("Salary Structure must be submitted before submission of Tax Ememption Declaration")) |
| 188 | |
| 189 | return frappe._dict({ |
| 190 | "hra_amount": hra_amount, |
| 191 | "annual_exemption": annual_exemption, |
| 192 | "monthly_exemption": monthly_exemption |
| 193 | }) |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 194 | |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 195 | def get_component_amt_from_salary_slip(employee, salary_structure, basic_component, hra_component): |
Nabin Hait | 6b9d64c | 2019-05-16 11:23:04 +0530 | [diff] [blame] | 196 | salary_slip = make_salary_slip(salary_structure, employee=employee, for_preview=1) |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 197 | basic_amt, hra_amt = 0, 0 |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 198 | for earning in salary_slip.earnings: |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 199 | if earning.salary_component == basic_component: |
| 200 | basic_amt = earning.amount |
| 201 | elif earning.salary_component == hra_component: |
| 202 | hra_amt = earning.amount |
| 203 | if basic_amt and hra_amt: |
| 204 | return basic_amt, hra_amt |
Ranjith Kurungadam | 14e94f8 | 2018-07-16 16:12:46 +0530 | [diff] [blame] | 205 | return basic_amt, hra_amt |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 206 | |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 207 | def calculate_hra_exemption(salary_structure, basic, monthly_hra, monthly_house_rent, rented_in_metro_city): |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 208 | # TODO make this configurable |
| 209 | exemptions = [] |
| 210 | frequency = frappe.get_value("Salary Structure", salary_structure, "payroll_frequency") |
| 211 | # case 1: The actual amount allotted by the employer as the HRA. |
| 212 | exemptions.append(get_annual_component_pay(frequency, monthly_hra)) |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 213 | |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 214 | actual_annual_rent = monthly_house_rent * 12 |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 215 | annual_basic = get_annual_component_pay(frequency, basic) |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 216 | |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 217 | # case 2: Actual rent paid less 10% of the basic salary. |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 218 | exemptions.append(flt(actual_annual_rent) - flt(annual_basic * 0.1)) |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 219 | # case 3: 50% of the basic salary, if the employee is staying in a metro city (40% for a non-metro city). |
Ranjith Kurungadam | b1a756c | 2018-07-01 16:42:38 +0530 | [diff] [blame] | 220 | exemptions.append(annual_basic * 0.5 if rented_in_metro_city else annual_basic * 0.4) |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 221 | # return minimum of 3 cases |
| 222 | return min(exemptions) |
| 223 | |
| 224 | def get_annual_component_pay(frequency, amount): |
| 225 | if frequency == "Daily": |
| 226 | return amount * 365 |
| 227 | elif frequency == "Weekly": |
| 228 | return amount * 52 |
| 229 | elif frequency == "Fortnightly": |
| 230 | return amount * 26 |
| 231 | elif frequency == "Monthly": |
| 232 | return amount * 12 |
| 233 | elif frequency == "Bimonthly": |
| 234 | return amount * 6 |
| 235 | |
| 236 | def validate_house_rent_dates(doc): |
| 237 | if not doc.rented_to_date or not doc.rented_from_date: |
| 238 | frappe.throw(_("House rented dates required for exemption calculation")) |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 239 | |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 240 | if date_diff(doc.rented_to_date, doc.rented_from_date) < 14: |
| 241 | frappe.throw(_("House rented dates should be atleast 15 days apart")) |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 242 | |
| 243 | proofs = frappe.db.sql(""" |
| 244 | select name |
| 245 | from `tabEmployee Tax Exemption Proof Submission` |
| 246 | where |
Nabin Hait | 49446ba | 2019-04-25 19:54:20 +0530 | [diff] [blame] | 247 | docstatus=1 and employee=%(employee)s and payroll_period=%(payroll_period)s |
| 248 | and (rented_from_date between %(from_date)s and %(to_date)s or rented_to_date between %(from_date)s and %(to_date)s) |
| 249 | """, { |
| 250 | "employee": doc.employee, |
| 251 | "payroll_period": doc.payroll_period, |
| 252 | "from_date": doc.rented_from_date, |
| 253 | "to_date": doc.rented_to_date |
| 254 | }) |
Nabin Hait | 04e7bf4 | 2019-04-25 18:44:10 +0530 | [diff] [blame] | 255 | |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 256 | if proofs: |
Nabin Hait | 49446ba | 2019-04-25 19:54:20 +0530 | [diff] [blame] | 257 | frappe.throw(_("House rent paid days overlapping with {0}").format(proofs[0][0])) |
Ranjith Kurungadam | a8e047a | 2018-06-14 17:56:16 +0530 | [diff] [blame] | 258 | |
| 259 | def calculate_hra_exemption_for_period(doc): |
| 260 | monthly_rent, eligible_hra = 0, 0 |
| 261 | if doc.house_rent_payment_amount: |
| 262 | validate_house_rent_dates(doc) |
| 263 | # TODO receive rented months or validate dates are start and end of months? |
| 264 | # Calc monthly rent, round to nearest .5 |
| 265 | factor = flt(date_diff(doc.rented_to_date, doc.rented_from_date) + 1)/30 |
| 266 | factor = round(factor * 2)/2 |
| 267 | monthly_rent = doc.house_rent_payment_amount / factor |
| 268 | # update field used by calculate_annual_eligible_hra_exemption |
| 269 | doc.monthly_house_rent = monthly_rent |
| 270 | exemptions = calculate_annual_eligible_hra_exemption(doc) |
| 271 | |
| 272 | if exemptions["monthly_exemption"]: |
| 273 | # calc total exemption amount |
| 274 | eligible_hra = exemptions["monthly_exemption"] * factor |
Ranjith Kurungadam | 4f9744a | 2018-06-20 11:10:56 +0530 | [diff] [blame] | 275 | exemptions["monthly_house_rent"] = monthly_rent |
| 276 | exemptions["total_eligible_hra_exemption"] = eligible_hra |
| 277 | return exemptions |
Prasann Shah | 829172c | 2019-06-06 12:08:09 +0530 | [diff] [blame] | 278 | |
| 279 | @frappe.whitelist() |
| 280 | def get_gstins_for_company(company): |
| 281 | company_gstins =[] |
| 282 | if company: |
| 283 | company_gstins = frappe.db.sql("""select |
| 284 | distinct `tabAddress`.gstin |
| 285 | from |
| 286 | `tabAddress`, `tabDynamic Link` |
| 287 | where |
| 288 | `tabDynamic Link`.parent = `tabAddress`.name and |
| 289 | `tabDynamic Link`.parenttype = 'Address' and |
| 290 | `tabDynamic Link`.link_doctype = 'Company' and |
| 291 | `tabDynamic Link`.link_name = '{0}'""".format(company)) |
| 292 | return company_gstins |
| 293 | |