feat: provision to disable get last purchase rate
fix: set_incoming_rate condition
diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.json b/erpnext/buying/doctype/buying_settings/buying_settings.json
index 28158a3..34417f7 100644
--- a/erpnext/buying/doctype/buying_settings/buying_settings.json
+++ b/erpnext/buying/doctype/buying_settings/buying_settings.json
@@ -9,8 +9,8 @@
"supplier_and_price_defaults_section",
"supp_master_name",
"supplier_group",
- "column_break_4",
"buying_price_list",
+ "column_break_4",
"maintain_same_rate_action",
"role_to_override_stop_action",
"transaction_settings_section",
@@ -20,6 +20,7 @@
"maintain_same_rate",
"allow_multiple_items",
"bill_for_rejected_quantity_in_purchase_invoice",
+ "disable_last_purchase_rate",
"subcontract",
"backflush_raw_materials_of_subcontract_based_on",
"column_break_11",
@@ -71,7 +72,7 @@
},
{
"fieldname": "subcontract",
- "fieldtype": "Section Break",
+ "fieldtype": "Tab Break",
"label": "Subcontracting Settings"
},
{
@@ -118,8 +119,8 @@
},
{
"fieldname": "supplier_and_price_defaults_section",
- "fieldtype": "Section Break",
- "label": "Supplier and Price Defaults"
+ "fieldtype": "Tab Break",
+ "label": "Naming Series and Price Defaults"
},
{
"fieldname": "column_break_4",
@@ -127,12 +128,18 @@
},
{
"fieldname": "transaction_settings_section",
- "fieldtype": "Section Break",
+ "fieldtype": "Tab Break",
"label": "Transaction Settings"
},
{
"fieldname": "column_break_12",
"fieldtype": "Column Break"
+ },
+ {
+ "default": "0",
+ "fieldname": "disable_last_purchase_rate",
+ "fieldtype": "Check",
+ "label": "Disable Last Purchase Rate"
}
],
"icon": "fa fa-cog",
@@ -140,7 +147,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
- "modified": "2022-09-27 10:50:27.050252",
+ "modified": "2023-01-09 17:08:28.828173",
"modified_by": "Administrator",
"module": "Buying",
"name": "Buying Settings",
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index fd30e61..54f0d94 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -274,9 +274,7 @@
if self.doctype not in ("Purchase Receipt", "Purchase Invoice", "Purchase Order"):
return
- if (
- self.doctype == "Purchase Invoice" and not self.update_stock and not self.is_internal_transfer()
- ):
+ if not self.is_internal_transfer():
return
ref_doctype_map = {
@@ -549,7 +547,9 @@
self.process_fixed_asset()
self.update_fixed_asset(field)
- if self.doctype in ["Purchase Order", "Purchase Receipt"]:
+ if self.doctype in ["Purchase Order", "Purchase Receipt"] and not frappe.db.get_single_value(
+ "Buying Settings", "disable_last_purchase_rate"
+ ):
update_last_purchase_rate(self, is_submit=1)
def on_cancel(self):
@@ -558,7 +558,9 @@
if self.get("is_return"):
return
- if self.doctype in ["Purchase Order", "Purchase Receipt"]:
+ if self.doctype in ["Purchase Order", "Purchase Receipt"] and not frappe.db.get_single_value(
+ "Buying Settings", "disable_last_purchase_rate"
+ ):
update_last_purchase_rate(self, is_submit=0)
if self.doctype in ["Purchase Receipt", "Purchase Invoice"]:
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 20bc9d9..8597b12 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -279,7 +279,7 @@
frappe.throw(_("Row #{0}: Maximum Net Rate cannot be greater than Minimum Net Rate"))
def update_template_tables(self):
- template = frappe.get_doc("Item", self.variant_of)
+ template = frappe.get_cached_doc("Item", self.variant_of)
# add item taxes from template
for d in template.get("taxes"):
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 8561dc2..d3fa97f 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -813,6 +813,9 @@
flt(price_list_rate) * flt(args.plc_conversion_rate) / flt(args.conversion_rate)
)
+ if frappe.db.get_single_value("Buying Settings", "disable_last_purchase_rate"):
+ return out
+
if not out.price_list_rate and args.transaction_type == "buying":
from erpnext.stock.doctype.item.item import get_last_purchase_details