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,42 +980,55 @@ 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):
|
||||||
ref_amt = flt(frappe.db.get_value(ref_dt + " Item",
|
continue
|
||||||
item.get(item_ref_dn), based_on), self.precision(based_on, item))
|
|
||||||
if not ref_amt:
|
|
||||||
frappe.msgprint(
|
|
||||||
_("Warning: System will not check overbilling since amount for Item {0} in {1} is zero")
|
|
||||||
.format(item.item_code, ref_dt))
|
|
||||||
else:
|
|
||||||
already_billed = frappe.db.sql("""
|
|
||||||
select sum(%s)
|
|
||||||
from `tab%s`
|
|
||||||
where %s=%s and docstatus=1 and parent != %s
|
|
||||||
""" % (based_on, self.doctype + " Item", item_ref_dn, '%s', '%s'),
|
|
||||||
(item.get(item_ref_dn), self.name))[0][0]
|
|
||||||
|
|
||||||
total_billed_amt = flt(flt(already_billed) + flt(item.get(based_on)),
|
ref_amt = flt(frappe.db.get_value(ref_dt + " Item",
|
||||||
self.precision(based_on, item))
|
item.get(item_ref_dn), based_on), self.precision(based_on, item))
|
||||||
|
if not ref_amt:
|
||||||
|
frappe.msgprint(
|
||||||
|
_("System will not check overbilling since amount for Item {0} in {1} is zero")
|
||||||
|
.format(item.item_code, ref_dt), title=_("Warning"), indicator="orange")
|
||||||
|
continue
|
||||||
|
|
||||||
allowance, item_allowance, global_qty_allowance, global_amount_allowance = \
|
already_billed = frappe.db.sql("""
|
||||||
get_allowance_for(item.item_code, item_allowance, global_qty_allowance, global_amount_allowance, "amount")
|
select sum(%s)
|
||||||
|
from `tab%s`
|
||||||
|
where %s=%s and docstatus=1 and parent != %s
|
||||||
|
""" % (based_on, self.doctype + " Item", item_ref_dn, '%s', '%s'),
|
||||||
|
(item.get(item_ref_dn), self.name))[0][0]
|
||||||
|
|
||||||
max_allowed_amt = flt(ref_amt * (100 + allowance) / 100)
|
total_billed_amt = flt(flt(already_billed) + flt(item.get(based_on)),
|
||||||
|
self.precision(based_on, item))
|
||||||
|
|
||||||
if total_billed_amt < 0 and max_allowed_amt < 0:
|
allowance, item_allowance, global_qty_allowance, global_amount_allowance = \
|
||||||
# while making debit note against purchase return entry(purchase receipt) getting overbill error
|
get_allowance_for(item.item_code, item_allowance, global_qty_allowance, global_amount_allowance, "amount")
|
||||||
total_billed_amt = abs(total_billed_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')
|
max_allowed_amt = flt(ref_amt * (100 + allowance) / 100)
|
||||||
|
|
||||||
if total_billed_amt - max_allowed_amt > 0.01 and role_allowed_to_over_bill not in frappe.get_roles():
|
if total_billed_amt < 0 and max_allowed_amt < 0:
|
||||||
if self.doctype != "Purchase Invoice":
|
# while making debit note against purchase return entry(purchase receipt) getting overbill error
|
||||||
self.throw_overbill_exception(item, max_allowed_amt)
|
total_billed_amt = abs(total_billed_amt)
|
||||||
elif not cint(frappe.db.get_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice")):
|
max_allowed_amt = abs(max_allowed_amt)
|
||||||
self.throw_overbill_exception(item, max_allowed_amt)
|
|
||||||
|
overbill_amt = total_billed_amt - max_allowed_amt
|
||||||
|
total_overbilled_amt += overbill_amt
|
||||||
|
|
||||||
|
if overbill_amt > 0.01 and role_allowed_to_over_bill not in user_roles:
|
||||||
|
if self.doctype != "Purchase Invoice":
|
||||||
|
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")):
|
||||||
|
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")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user