refactor(UAE VAT 201): break functions

This commit is contained in:
Mohammad Hasnain 2020-10-29 09:52:17 +05:30
parent bf261a6c39
commit eb3084b072
2 changed files with 34 additions and 17 deletions

View File

@ -113,6 +113,7 @@ def standard_rated_expenses_emiratewise(data, filters):
"amount": frappe.format(amount, 'Currency'), "amount": frappe.format(amount, 'Currency'),
"vat_amount": frappe.format(vat, 'Currency'), "vat_amount": frappe.format(vat, 'Currency'),
} }
amounts_by_emirate = append_emiratewise_expenses(data, emirates, amounts_by_emirate)
for d, emirate in enumerate(emirates, 97): for d, emirate in enumerate(emirates, 97):
if emirate in amounts_by_emirate: if emirate in amounts_by_emirate:
@ -125,6 +126,18 @@ def standard_rated_expenses_emiratewise(data, filters):
frappe.format(0, 'Currency'), frappe.format(0, 'Currency')) frappe.format(0, 'Currency'), frappe.format(0, 'Currency'))
return emirates, amounts_by_emirate return emirates, amounts_by_emirate
def append_emiratewise_expenses(data, emirates, amounts_by_emirate):
"""Append emiratewise standard rated expenses and vat."""
for d, emirate in enumerate(emirates, 97):
if emirate in amounts_by_emirate:
amounts_by_emirate[emirate]["no"] = _('1{0}').format(chr(d))
amounts_by_emirate[emirate]["legend"] = _('Standard rated supplies in {0}').format(emirate)
data.append(amounts_by_emirate[emirate])
else:
append_data(data, _('1{0}').format(chr(d)),
_('Standard rated supplies in {0}').format(emirate),
frappe.format(0, 'Currency'), frappe.format(0, 'Currency'))
return amounts_by_emirate
def append_vat_on_expenses(data, filters): def append_vat_on_expenses(data, filters):
"""Appends Expenses and All Other Inputs.""" """Appends Expenses and All Other Inputs."""

View File

@ -123,25 +123,29 @@ def make_regional_gl_entries(gl_entries, doc):
for tax in doc.get('taxes'): for tax in doc.get('taxes'):
if tax.category not in ("Total", "Valuation and Total"): if tax.category not in ("Total", "Valuation and Total"):
continue continue
gl_entries = make_gl_entry(tax, gl_entries, doc, tax_accounts)
dr_or_cr = "credit" if tax.add_deduct_tax == "Add" else "debit"
if flt(tax.base_tax_amount_after_discount_amount) and tax.account_head in tax_accounts:
account_currency = get_account_currency(tax.account_head)
gl_entries.append(doc.get_gl_dict(
{
"account": tax.account_head,
"cost_center": tax.cost_center,
"posting_date": doc.posting_date,
"against": doc.supplier,
dr_or_cr: tax.base_tax_amount_after_discount_amount,
dr_or_cr + "_in_account_currency": tax.base_tax_amount_after_discount_amount \
if account_currency==doc.company_currency \
else tax.tax_amount_after_discount_amount
}, account_currency, item=tax)
)
return gl_entries return gl_entries
def make_gl_entry(tax, gl_entries, doc, tax_accounts):
dr_or_cr = "credit" if tax.add_deduct_tax == "Add" else "debit"
if flt(tax.base_tax_amount_after_discount_amount) and tax.account_head in tax_accounts:
account_currency = get_account_currency(tax.account_head)
gl_entries.append(doc.get_gl_dict(
{
"account": tax.account_head,
"cost_center": tax.cost_center,
"posting_date": doc.posting_date,
"against": doc.supplier,
dr_or_cr: tax.base_tax_amount_after_discount_amount,
dr_or_cr + "_in_account_currency": tax.base_tax_amount_after_discount_amount \
if account_currency==doc.company_currency \
else tax.tax_amount_after_discount_amount
}, account_currency, item=tax)
)
return gl_entries
def validate_returns(doc, method): def validate_returns(doc, method):
"""Standard Rated expenses should not be set when Reverse Charge Applicable is set.""" """Standard Rated expenses should not be set when Reverse Charge Applicable is set."""
country = frappe.get_cached_value('Company', doc.company, 'country') country = frappe.get_cached_value('Company', doc.company, 'country')