fix: Role to override maintain same rate check in transactions

This commit is contained in:
Deepesh Garg
2021-04-04 21:14:44 +05:30
parent 192002e156
commit ed369c105f
3 changed files with 25 additions and 4 deletions

View File

@@ -14,6 +14,7 @@
"pr_required",
"maintain_same_rate",
"maintain_same_rate_action",
"role_to_override_stop_action",
"allow_multiple_items",
"subcontract",
"backflush_raw_materials_of_subcontract_based_on",
@@ -100,6 +101,13 @@
"label": "Action If Same Rate is Not Maintained",
"mandatory_depends_on": "maintain_same_rate",
"options": "Stop\nWarn"
},
{
"depends_on": "eval:doc.maintain_same_rate_action == 'Stop'",
"fieldname": "role_to_override_stop_action",
"fieldtype": "Link",
"label": "Role Allowed to Override Stop Action",
"options": "Role"
}
],
"icon": "fa fa-cog",
@@ -107,7 +115,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2021-03-11 17:31:21.293142",
"modified": "2021-04-04 20:01:44.087066",
"modified_by": "Administrator",
"module": "Buying",
"name": "Buying Settings",

View File

@@ -19,6 +19,7 @@
"sales_update_frequency",
"maintain_same_sales_rate",
"maintain_same_rate_action",
"role_to_override_stop_action",
"editable_price_list_rate",
"allow_multiple_items",
"allow_against_multiple_purchase_orders",
@@ -144,6 +145,13 @@
"label": "Action If Same Rate is Not Maintained",
"mandatory_depends_on": "maintain_same_sales_rate",
"options": "Stop\nWarn"
},
{
"depends_on": "eval: doc.maintain_same_rate_action == 'Stop'",
"fieldname": "role_to_override_stop_action",
"fieldtype": "Link",
"label": "Role Allowed to Override Stop Action",
"options": "Role"
}
],
"icon": "fa fa-cog",
@@ -151,7 +159,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2021-03-11 17:43:55.584040",
"modified": "2021-04-04 20:18:12.814624",
"modified_by": "Administrator",
"module": "Selling",
"name": "Selling Settings",

View File

@@ -121,8 +121,10 @@ class TransactionBase(StatusUpdater):
if self.doctype in buying_doctypes:
action = frappe.db.get_single_value("Buying Settings", "maintain_same_rate_action")
settings_doc = "Buying Settings"
else:
action = frappe.db.get_single_value("Selling Settings", "maintain_same_rate_action")
settings_doc = "Selling Settings"
for ref_dt, ref_dn_field, ref_link_field in ref_details:
for d in self.get("items"):
@@ -131,8 +133,11 @@ class TransactionBase(StatusUpdater):
if abs(flt(d.rate - ref_rate, d.precision("rate"))) >= .01:
if action == "Stop":
frappe.throw(_("Row #{0}: Rate must be same as {1}: {2} ({3} / {4})").format(
d.idx, ref_dt, d.get(ref_dn_field), d.rate, ref_rate))
role_allowed_to_override = frappe.db.get_single_value(settings_doc, 'role_to_override_stop_action')
if role_allowed_to_override not in frappe.get_roles():
frappe.throw(_("Row #{0}: Rate must be same as {1}: {2} ({3} / {4})").format(
d.idx, ref_dt, d.get(ref_dn_field), d.rate, ref_rate))
else:
frappe.msgprint(_("Row #{0}: Rate must be same as {1}: {2} ({3} / {4})").format(
d.idx, ref_dt, d.get(ref_dn_field), d.rate, ref_rate), title=_("Warning"), indicator="orange")