fix: Add separate function to validate payment entry taxes

This commit is contained in:
Deepesh Garg 2021-06-14 14:34:44 +05:30
parent 302855e160
commit 5ef9a62917
2 changed files with 34 additions and 17 deletions

View File

@ -18,8 +18,7 @@ from erpnext.accounts.doctype.invoice_discounting.invoice_discounting import get
from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category import get_party_tax_withholding_details from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category import get_party_tax_withholding_details
from six import string_types, iteritems from six import string_types, iteritems
from erpnext.controllers.accounts_controller import validate_conversion_rate, \ from erpnext.controllers.accounts_controller import validate_taxes_and_charges
validate_taxes_and_charges, validate_inclusive_tax
class InvalidPaymentEntry(ValidationError): class InvalidPaymentEntry(ValidationError):
pass pass
@ -925,6 +924,25 @@ class PaymentEntry(AccountsController):
return current_tax_fraction return current_tax_fraction
def validate_inclusive_tax(tax, doc):
def _on_previous_row_error(row_range):
throw(_("To include tax in row {0} in Item rate, taxes in rows {1} must also be included").format(tax.idx, row_range))
if cint(getattr(tax, "included_in_paid_amount", None)):
if tax.charge_type == "Actual":
# inclusive tax cannot be of type Actual
throw(_("Charge of type 'Actual' in row {0} cannot be included in Item Rate or Paid Amount").format(tax.idx))
elif tax.charge_type == "On Previous Row Amount" and \
not cint(doc.get("taxes")[cint(tax.row_id) - 1].included_in_paid_amount):
# referred row should also be inclusive
_on_previous_row_error(tax.row_id)
elif tax.charge_type == "On Previous Row Total" and \
not all([cint(t.included_in_paid_amount for t in doc.get("taxes")[:cint(tax.row_id) - 1])]):
# all rows about the referred tax should be inclusive
_on_previous_row_error("1 - %d" % (cint(tax.row_id),))
elif tax.get("category") == "Valuation":
frappe.throw(_("Valuation type charges can not be marked as Inclusive"))
@frappe.whitelist() @frappe.whitelist()
def get_outstanding_reference_documents(args): def get_outstanding_reference_documents(args):

View File

@ -1211,21 +1211,20 @@ def validate_inclusive_tax(tax, doc):
def _on_previous_row_error(row_range): def _on_previous_row_error(row_range):
throw(_("To include tax in row {0} in Item rate, taxes in rows {1} must also be included").format(tax.idx, row_range)) throw(_("To include tax in row {0} in Item rate, taxes in rows {1} must also be included").format(tax.idx, row_range))
for fieldname in ['included_in_print_rate', 'included_in_paid_amount']: if cint(getattr(tax, "included_in_print_rate", None)):
if cint(getattr(tax, fieldname, None)): if tax.charge_type == "Actual":
if tax.charge_type == "Actual": # inclusive tax cannot be of type Actual
# inclusive tax cannot be of type Actual throw(_("Charge of type 'Actual' in row {0} cannot be included in Item Rate or Paid Amount").format(tax.idx))
throw(_("Charge of type 'Actual' in row {0} cannot be included in Item Rate or Paid Amount").format(tax.idx)) elif tax.charge_type == "On Previous Row Amount" and \
elif tax.charge_type == "On Previous Row Amount" and \ not cint(doc.get("taxes")[cint(tax.row_id) - 1].included_in_print_rate):
not cint(doc.get("taxes")[cint(tax.row_id) - 1].get(fieldname)): # referred row should also be inclusive
# referred row should also be inclusive _on_previous_row_error(tax.row_id)
_on_previous_row_error(tax.row_id) elif tax.charge_type == "On Previous Row Total" and \
elif tax.charge_type == "On Previous Row Total" and \ not all([cint(t.included_in_print_rate for t in doc.get("taxes")[:cint(tax.row_id) - 1])]):
not all([cint(t.get(fieldname) for t in doc.get("taxes")[:cint(tax.row_id) - 1])]): # all rows about the referred tax should be inclusive
# all rows about the referred tax should be inclusive _on_previous_row_error("1 - %d" % (cint(tax.row_id),))
_on_previous_row_error("1 - %d" % (cint(tax.row_id),)) elif tax.get("category") == "Valuation":
elif tax.get("category") == "Valuation": frappe.throw(_("Valuation type charges can not be marked as Inclusive"))
frappe.throw(_("Valuation type charges can not be marked as Inclusive"))
def set_balance_in_account_currency(gl_dict, account_currency=None, conversion_rate=None, company_currency=None): def set_balance_in_account_currency(gl_dict, account_currency=None, conversion_rate=None, company_currency=None):