Merge pull request #27601 from ankush/overbill_warn
fix(ux): warn when overbilling allowance was bypassed due to role
This commit is contained in:
commit
4f01115f2f
@ -980,15 +980,23 @@ class AccountsController(TransactionBase):
|
|||||||
item_allowance = {}
|
item_allowance = {}
|
||||||
global_qty_allowance, global_amount_allowance = None, None
|
global_qty_allowance, global_amount_allowance = None, None
|
||||||
|
|
||||||
|
role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill')
|
||||||
|
user_roles = frappe.get_roles()
|
||||||
|
|
||||||
|
total_overbilled_amt = 0.0
|
||||||
|
|
||||||
for item in self.get("items"):
|
for item in self.get("items"):
|
||||||
if item.get(item_ref_dn):
|
if not item.get(item_ref_dn):
|
||||||
|
continue
|
||||||
|
|
||||||
ref_amt = flt(frappe.db.get_value(ref_dt + " Item",
|
ref_amt = flt(frappe.db.get_value(ref_dt + " Item",
|
||||||
item.get(item_ref_dn), based_on), self.precision(based_on, item))
|
item.get(item_ref_dn), based_on), self.precision(based_on, item))
|
||||||
if not ref_amt:
|
if not ref_amt:
|
||||||
frappe.msgprint(
|
frappe.msgprint(
|
||||||
_("Warning: System will not check overbilling since amount for Item {0} in {1} is zero")
|
_("System will not check overbilling since amount for Item {0} in {1} is zero")
|
||||||
.format(item.item_code, ref_dt))
|
.format(item.item_code, ref_dt), title=_("Warning"), indicator="orange")
|
||||||
else:
|
continue
|
||||||
|
|
||||||
already_billed = frappe.db.sql("""
|
already_billed = frappe.db.sql("""
|
||||||
select sum(%s)
|
select sum(%s)
|
||||||
from `tab%s`
|
from `tab%s`
|
||||||
@ -1009,14 +1017,19 @@ class AccountsController(TransactionBase):
|
|||||||
total_billed_amt = abs(total_billed_amt)
|
total_billed_amt = abs(total_billed_amt)
|
||||||
max_allowed_amt = abs(max_allowed_amt)
|
max_allowed_amt = abs(max_allowed_amt)
|
||||||
|
|
||||||
role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill')
|
overbill_amt = total_billed_amt - max_allowed_amt
|
||||||
|
total_overbilled_amt += overbill_amt
|
||||||
|
|
||||||
if total_billed_amt - max_allowed_amt > 0.01 and role_allowed_to_over_bill not in frappe.get_roles():
|
if overbill_amt > 0.01 and role_allowed_to_over_bill not in user_roles:
|
||||||
if self.doctype != "Purchase Invoice":
|
if self.doctype != "Purchase Invoice":
|
||||||
self.throw_overbill_exception(item, max_allowed_amt)
|
self.throw_overbill_exception(item, max_allowed_amt)
|
||||||
elif not cint(frappe.db.get_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice")):
|
elif not cint(frappe.db.get_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice")):
|
||||||
self.throw_overbill_exception(item, max_allowed_amt)
|
self.throw_overbill_exception(item, max_allowed_amt)
|
||||||
|
|
||||||
|
if role_allowed_to_over_bill in user_roles and total_overbilled_amt > 0.1:
|
||||||
|
frappe.msgprint(_("Overbilling of {} ignored because you have {} role.")
|
||||||
|
.format(total_overbilled_amt, role_allowed_to_over_bill), title=_("Warning"), indicator="orange")
|
||||||
|
|
||||||
def throw_overbill_exception(self, item, max_allowed_amt):
|
def throw_overbill_exception(self, item, max_allowed_amt):
|
||||||
frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings")
|
frappe.throw(_("Cannot overbill for Item {0} in row {1} more than {2}. To allow over-billing, please set allowance in Accounts Settings")
|
||||||
.format(item.item_code, item.idx, max_allowed_amt))
|
.format(item.item_code, item.idx, max_allowed_amt))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user