mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-14 12:38:46 +00:00
fix: validations and account type filter for Tax Withholding Category (#46207)
fix: validations and account type filter for tax withholding category
(cherry picked from commit d371236684)
This commit is contained in:
@@ -10,6 +10,7 @@ frappe.ui.form.on("Tax Withholding Category", {
|
|||||||
filters: {
|
filters: {
|
||||||
company: child.company,
|
company: child.company,
|
||||||
root_type: ["in", ["Asset", "Liability"]],
|
root_type: ["in", ["Asset", "Liability"]],
|
||||||
|
is_group: 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,27 +36,38 @@ class TaxWithholdingCategory(Document):
|
|||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.validate_dates()
|
self.validate_dates()
|
||||||
self.validate_accounts()
|
self.validate_companies_and_accounts()
|
||||||
self.validate_thresholds()
|
self.validate_thresholds()
|
||||||
|
|
||||||
def validate_dates(self):
|
def validate_dates(self):
|
||||||
last_date = None
|
last_to_date = None
|
||||||
for d in self.get("rates"):
|
rates = sorted(self.get("rates"), key=lambda d: getdate(d.from_date))
|
||||||
|
|
||||||
|
for d in rates:
|
||||||
if getdate(d.from_date) >= getdate(d.to_date):
|
if getdate(d.from_date) >= getdate(d.to_date):
|
||||||
frappe.throw(_("Row #{0}: From Date cannot be before To Date").format(d.idx))
|
frappe.throw(_("Row #{0}: From Date cannot be before To Date").format(d.idx))
|
||||||
|
|
||||||
# validate overlapping of dates
|
# validate overlapping of dates
|
||||||
if last_date and getdate(d.to_date) < getdate(last_date):
|
if last_to_date and getdate(d.from_date) < getdate(last_to_date):
|
||||||
frappe.throw(_("Row #{0}: Dates overlapping with other row").format(d.idx))
|
frappe.throw(_("Row #{0}: Dates overlapping with other row").format(d.idx))
|
||||||
|
|
||||||
def validate_accounts(self):
|
last_to_date = d.to_date
|
||||||
existing_accounts = []
|
|
||||||
|
def validate_companies_and_accounts(self):
|
||||||
|
existing_accounts = set()
|
||||||
|
companies = set()
|
||||||
for d in self.get("accounts"):
|
for d in self.get("accounts"):
|
||||||
|
# validate duplicate company
|
||||||
|
if d.get("company") in companies:
|
||||||
|
frappe.throw(_("Company {0} added multiple times").format(frappe.bold(d.get("company"))))
|
||||||
|
companies.add(d.get("company"))
|
||||||
|
|
||||||
|
# validate duplicate account
|
||||||
if d.get("account") in existing_accounts:
|
if d.get("account") in existing_accounts:
|
||||||
frappe.throw(_("Account {0} added multiple times").format(frappe.bold(d.get("account"))))
|
frappe.throw(_("Account {0} added multiple times").format(frappe.bold(d.get("account"))))
|
||||||
|
|
||||||
validate_account_head(d.idx, d.get("account"), d.get("company"))
|
validate_account_head(d.idx, d.get("account"), d.get("company"))
|
||||||
existing_accounts.append(d.get("account"))
|
existing_accounts.add(d.get("account"))
|
||||||
|
|
||||||
def validate_thresholds(self):
|
def validate_thresholds(self):
|
||||||
for d in self.get("rates"):
|
for d in self.get("rates"):
|
||||||
|
|||||||
Reference in New Issue
Block a user