Merge pull request #38591 from barredterra/de-morgan
diff --git a/erpnext/accounts/doctype/pricing_rule/utils.py b/erpnext/accounts/doctype/pricing_rule/utils.py
index 57feaa0..18aa682 100644
--- a/erpnext/accounts/doctype/pricing_rule/utils.py
+++ b/erpnext/accounts/doctype/pricing_rule/utils.py
@@ -581,6 +581,8 @@
if d.price_or_product_discount == "Price":
if d.apply_discount_on:
doc.set("apply_discount_on", d.apply_discount_on)
+ # Variable to track whether the condition has been met
+ condition_met = False
for field in ["additional_discount_percentage", "discount_amount"]:
pr_field = "discount_percentage" if field == "additional_discount_percentage" else field
@@ -603,6 +605,11 @@
if coupon_code_pricing_rule == d.name:
# if selected coupon code is linked with pricing rule
doc.set(field, d.get(pr_field))
+
+ # Set the condition_met variable to True and break out of the loop
+ condition_met = True
+ break
+
else:
# reset discount if not linked
doc.set(field, 0)
@@ -611,6 +618,10 @@
doc.set(field, 0)
doc.calculate_taxes_and_totals()
+
+ # Break out of the main loop if the condition is met
+ if condition_met:
+ break
elif d.price_or_product_discount == "Product":
item_details = frappe._dict({"parenttype": doc.doctype, "free_item_data": []})
get_product_discount_rule(d, item_details, doc=doc)
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 17ad155..f6b6802 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -637,6 +637,7 @@
extend_bootinfo = [
"erpnext.support.doctype.service_level_agreement.service_level_agreement.add_sla_doctypes",
+ "erpnext.startup.boot.bootinfo",
]
diff --git a/erpnext/startup/boot.py b/erpnext/startup/boot.py
index bdbf8b4..4b4d14f 100644
--- a/erpnext/startup/boot.py
+++ b/erpnext/startup/boot.py
@@ -75,3 +75,11 @@
"Sales Person Tree": {"title": "Sales Person Tree", "route": "Tree/Sales Person"},
}
)
+
+
+def bootinfo(bootinfo):
+ if bootinfo.get("user") and bootinfo["user"].get("name"):
+ bootinfo["user"]["employee"] = ""
+ employee = frappe.db.get_value("Employee", {"user_id": bootinfo["user"]["name"]}, "name")
+ if employee:
+ bootinfo["user"]["employee"] = employee
diff --git a/erpnext/stock/report/stock_ledger_variance/stock_ledger_variance.py b/erpnext/stock/report/stock_ledger_variance/stock_ledger_variance.py
index acbbe90..189a90a 100644
--- a/erpnext/stock/report/stock_ledger_variance/stock_ledger_variance.py
+++ b/erpnext/stock/report/stock_ledger_variance/stock_ledger_variance.py
@@ -56,6 +56,11 @@
"options": "Warehouse",
},
{
+ "fieldname": "valuation_method",
+ "fieldtype": "Data",
+ "label": _("Valuation Method"),
+ },
+ {
"fieldname": "voucher_type",
"fieldtype": "Link",
"label": _("Voucher Type"),
@@ -194,6 +199,7 @@
def get_data(filters=None):
filters = frappe._dict(filters or {})
item_warehouse_map = get_item_warehouse_combinations(filters)
+ valuation_method = frappe.db.get_single_value("Stock Settings", "valuation_method")
data = []
if item_warehouse_map:
@@ -206,8 +212,17 @@
continue
for row in report_data:
- if has_difference(row, precision, filters.difference_in):
- data.append(add_item_warehouse_details(row, item_warehouse))
+ if has_difference(
+ row, precision, filters.difference_in, item_warehouse.valuation_method or valuation_method
+ ):
+ row.update(
+ {
+ "item_code": item_warehouse.item_code,
+ "warehouse": item_warehouse.warehouse,
+ "valuation_method": item_warehouse.valuation_method or valuation_method,
+ }
+ )
+ data.append(row)
break
return data
@@ -229,6 +244,7 @@
.select(
bin.item_code,
bin.warehouse,
+ item.valuation_method,
)
.where(
(item.is_stock_item == 1)
@@ -248,37 +264,27 @@
return query.run(as_dict=1)
-def has_difference(row, precision, difference_in):
- has_qty_difference = flt(row.difference_in_qty, precision) or flt(row.fifo_qty_diff, precision)
- has_value_difference = (
- flt(row.diff_value_diff, precision)
- or flt(row.fifo_value_diff, precision)
- or flt(row.fifo_difference_diff, precision)
- )
- has_valuation_difference = flt(row.valuation_diff, precision) or flt(
- row.fifo_valuation_diff, precision
- )
+def has_difference(row, precision, difference_in, valuation_method):
+ if valuation_method == "Moving Average":
+ qty_diff = flt(row.difference_in_qty, precision)
+ value_diff = flt(row.diff_value_diff, precision)
+ valuation_diff = flt(row.valuation_diff, precision)
+ else:
+ qty_diff = flt(row.difference_in_qty, precision) or flt(row.fifo_qty_diff, precision)
+ value_diff = (
+ flt(row.diff_value_diff, precision)
+ or flt(row.fifo_value_diff, precision)
+ or flt(row.fifo_difference_diff, precision)
+ )
+ valuation_diff = flt(row.valuation_diff, precision) or flt(row.fifo_valuation_diff, precision)
- if difference_in == "Qty" and has_qty_difference:
+ if difference_in == "Qty" and qty_diff:
return True
- elif difference_in == "Value" and has_value_difference:
+ elif difference_in == "Value" and value_diff:
return True
- elif difference_in == "Valuation" and has_valuation_difference:
+ elif difference_in == "Valuation" and valuation_diff:
return True
elif difference_in not in ["Qty", "Value", "Valuation"] and (
- has_qty_difference or has_value_difference or has_valuation_difference
+ qty_diff or value_diff or valuation_diff
):
return True
-
- return False
-
-
-def add_item_warehouse_details(row, item_warehouse):
- row.update(
- {
- "item_code": item_warehouse.item_code,
- "warehouse": item_warehouse.warehouse,
- }
- )
-
- return row