Merge branch 'frappe:develop' into Custom_Abbr_On_Setup
diff --git a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
index 0b583a1..7c2ebe1 100644
--- a/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
+++ b/erpnext/accounts/report/consolidated_financial_statement/consolidated_financial_statement.py
@@ -6,6 +6,7 @@
import frappe
from frappe import _
+from frappe.query_builder import Criterion
from frappe.utils import flt, getdate
import erpnext
@@ -359,6 +360,7 @@
accounts_by_name,
accounts,
ignore_closing_entries=False,
+ root_type=root_type,
)
calculate_values(accounts_by_name, gl_entries_by_account, companies, filters, fiscal_year)
@@ -603,6 +605,7 @@
accounts_by_name,
accounts,
ignore_closing_entries=False,
+ root_type=None,
):
"""Returns a dict like { "account": [gl entries], ... }"""
@@ -610,7 +613,6 @@
"Company", filters.get("company"), ["lft", "rgt"]
)
- additional_conditions = get_additional_conditions(from_date, ignore_closing_entries, filters)
companies = frappe.db.sql(
""" select name, default_currency from `tabCompany`
where lft >= %(company_lft)s and rgt <= %(company_rgt)s""",
@@ -626,27 +628,42 @@
)
for d in companies:
- gl_entries = frappe.db.sql(
- """select gl.posting_date, gl.account, gl.debit, gl.credit, gl.is_opening, gl.company,
- gl.fiscal_year, gl.debit_in_account_currency, gl.credit_in_account_currency, gl.account_currency,
- acc.account_name, acc.account_number
- from `tabGL Entry` gl, `tabAccount` acc where acc.name = gl.account and gl.company = %(company)s and gl.is_cancelled = 0
- {additional_conditions} and gl.posting_date <= %(to_date)s and acc.lft >= %(lft)s and acc.rgt <= %(rgt)s
- order by gl.account, gl.posting_date""".format(
- additional_conditions=additional_conditions
- ),
- {
- "from_date": from_date,
- "to_date": to_date,
- "lft": root_lft,
- "rgt": root_rgt,
- "company": d.name,
- "finance_book": filters.get("finance_book"),
- "company_fb": frappe.get_cached_value("Company", d.name, "default_finance_book"),
- },
- as_dict=True,
+ gle = frappe.qb.DocType("GL Entry")
+ account = frappe.qb.DocType("Account")
+ query = (
+ frappe.qb.from_(gle)
+ .inner_join(account)
+ .on(account.name == gle.account)
+ .select(
+ gle.posting_date,
+ gle.account,
+ gle.debit,
+ gle.credit,
+ gle.is_opening,
+ gle.company,
+ gle.fiscal_year,
+ gle.debit_in_account_currency,
+ gle.credit_in_account_currency,
+ gle.account_currency,
+ account.account_name,
+ account.account_number,
+ )
+ .where(
+ (gle.company == d.name)
+ & (gle.is_cancelled == 0)
+ & (gle.posting_date <= to_date)
+ & (account.lft >= root_lft)
+ & (account.rgt <= root_rgt)
+ & (account.root_type <= root_type)
+ )
+ .orderby(gle.account, gle.posting_date)
)
+ additional_conditions = get_additional_conditions(from_date, ignore_closing_entries, filters, d)
+ if additional_conditions:
+ query = query.where(Criterion.all(additional_conditions))
+ gl_entries = query.run(as_dict=True)
+
if filters and filters.get("presentation_currency") != d.default_currency:
currency_info["company"] = d.name
currency_info["company_currency"] = d.default_currency
@@ -716,23 +733,25 @@
accounts.insert(idx + 1, args)
-def get_additional_conditions(from_date, ignore_closing_entries, filters):
+def get_additional_conditions(from_date, ignore_closing_entries, filters, d):
+ gle = frappe.qb.DocType("GL Entry")
additional_conditions = []
if ignore_closing_entries:
- additional_conditions.append("gl.voucher_type != 'Period Closing Voucher'")
+ additional_conditions.append((gle.voucher_type != "Period Closing Voucher"))
if from_date:
- additional_conditions.append("gl.posting_date >= %(from_date)s")
+ additional_conditions.append(gle.posting_date >= from_date)
+
+ finance_book = filters.get("finance_book")
+ company_fb = frappe.get_cached_value("Company", d.name, "default_finance_book")
if filters.get("include_default_book_entries"):
- additional_conditions.append(
- "(finance_book in (%(finance_book)s, %(company_fb)s, '') OR finance_book IS NULL)"
- )
+ additional_conditions.append((gle.finance_book.isin([finance_book, company_fb, "", None])))
else:
- additional_conditions.append("(finance_book in (%(finance_book)s, '') OR finance_book IS NULL)")
+ additional_conditions.append((gle.finance_book.isin([finance_book, "", None])))
- return " and {}".format(" and ".join(additional_conditions)) if additional_conditions else ""
+ return additional_conditions
def add_total_row(out, root_type, balance_must_be, companies, company_currency):
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index 26bf315..a76dea6 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -188,6 +188,7 @@
filters,
gl_entries_by_account,
ignore_closing_entries=ignore_closing_entries,
+ root_type=root_type,
)
calculate_values(
@@ -417,13 +418,28 @@
gl_entries_by_account,
ignore_closing_entries=False,
ignore_opening_entries=False,
+ root_type=None,
):
"""Returns a dict like { "account": [gl entries], ... }"""
gl_entries = []
+ account_filters = {
+ "company": company,
+ "is_group": 0,
+ "lft": (">=", root_lft),
+ "rgt": ("<=", root_rgt),
+ }
+
+ if root_type:
+ account_filters.update(
+ {
+ "root_type": root_type,
+ }
+ )
+
accounts_list = frappe.db.get_all(
"Account",
- filters={"company": company, "is_group": 0, "lft": (">=", root_lft), "rgt": ("<=", root_rgt)},
+ filters=account_filters,
pluck="name",
)
diff --git a/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.py b/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.py
index 5ab3611..bd9e9fc 100644
--- a/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.py
+++ b/erpnext/accounts/report/voucher_wise_balance/voucher_wise_balance.py
@@ -46,6 +46,7 @@
.select(
gle.voucher_type, gle.voucher_no, Sum(gle.debit).as_("debit"), Sum(gle.credit).as_("credit")
)
+ .where(gle.is_cancelled == 0)
.groupby(gle.voucher_no)
)
query = apply_filters(query, filters, gle)
diff --git a/erpnext/manufacturing/doctype/workstation/workstation.py b/erpnext/manufacturing/doctype/workstation/workstation.py
index d5b6d37..ac271b7 100644
--- a/erpnext/manufacturing/doctype/workstation/workstation.py
+++ b/erpnext/manufacturing/doctype/workstation/workstation.py
@@ -114,7 +114,7 @@
if schedule_date in tuple(get_holidays(self.holiday_list)):
schedule_date = add_days(schedule_date, 1)
- self.validate_workstation_holiday(schedule_date, skip_holiday_list_check=True)
+ return self.validate_workstation_holiday(schedule_date, skip_holiday_list_check=True)
return schedule_date
diff --git a/erpnext/quality_management/doctype/non_conformance/non_conformance.json b/erpnext/quality_management/doctype/non_conformance/non_conformance.json
index 8dfe2d6..e6b8744 100644
--- a/erpnext/quality_management/doctype/non_conformance/non_conformance.json
+++ b/erpnext/quality_management/doctype/non_conformance/non_conformance.json
@@ -62,10 +62,10 @@
"fieldtype": "Column Break"
},
{
- "fetch_from": "process_owner.full_name",
+ "fetch_from": "procedure.process_owner_full_name",
"fieldname": "full_name",
"fieldtype": "Data",
- "hidden": 1,
+ "read_only": 1,
"label": "Full Name"
},
{
@@ -81,7 +81,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
- "modified": "2021-02-26 15:27:47.247814",
+ "modified": "2023-07-31 08:10:47.247814",
"modified_by": "Administrator",
"module": "Quality Management",
"name": "Non Conformance",
diff --git a/erpnext/quality_management/doctype/quality_review_objective/quality_review_objective.json b/erpnext/quality_management/doctype/quality_review_objective/quality_review_objective.json
index 3a750c2..5ddf0f2 100644
--- a/erpnext/quality_management/doctype/quality_review_objective/quality_review_objective.json
+++ b/erpnext/quality_management/doctype/quality_review_objective/quality_review_objective.json
@@ -56,6 +56,7 @@
"fieldtype": "Column Break"
},
{
+ "default": "Open",
"columns": 2,
"fieldname": "status",
"fieldtype": "Select",
@@ -67,7 +68,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
- "modified": "2020-10-27 16:28:20.908637",
+ "modified": "2023-07-31 09:20:20.908637",
"modified_by": "Administrator",
"module": "Quality Management",
"name": "Quality Review Objective",
@@ -76,4 +77,4 @@
"sort_field": "modified",
"sort_order": "DESC",
"track_changes": 1
-}
\ No newline at end of file
+}
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index 624dadb..45b3f1d 100755
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -733,7 +733,7 @@
# qty is for packed items, because packed items don't have stock_qty field
qty = source.get("qty")
target.project = source_parent.project
- target.qty = qty - requested_item_qty.get(source.name, 0) - source.delivered_qty
+ target.qty = qty - requested_item_qty.get(source.name, 0) - flt(source.get("delivered_qty"))
target.stock_qty = flt(target.qty) * flt(target.conversion_factor)
args = target.as_dict().copy()
@@ -767,7 +767,7 @@
"doctype": "Material Request Item",
"field_map": {"name": "sales_order_item", "parent": "sales_order"},
"condition": lambda doc: not frappe.db.exists("Product Bundle", doc.item_code)
- and (doc.stock_qty - doc.delivered_qty) > requested_item_qty.get(doc.name, 0),
+ and (doc.stock_qty - flt(doc.get("delivered_qty"))) > requested_item_qty.get(doc.name, 0),
"postprocess": update_item,
},
},
diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py
index 796e258..c85a4fb 100644
--- a/erpnext/selling/doctype/sales_order/test_sales_order.py
+++ b/erpnext/selling/doctype/sales_order/test_sales_order.py
@@ -549,6 +549,26 @@
workflow.is_active = 0
workflow.save()
+ def test_material_request_for_product_bundle(self):
+ # Create the Material Request from the sales order for the Packing Items
+ # Check whether the material request has the correct packing item or not.
+ if not frappe.db.exists("Item", "_Test Product Bundle Item New 1"):
+ bundle_item = make_item("_Test Product Bundle Item New 1", {"is_stock_item": 0})
+ bundle_item.append(
+ "item_defaults", {"company": "_Test Company", "default_warehouse": "_Test Warehouse - _TC"}
+ )
+ bundle_item.save(ignore_permissions=True)
+
+ make_item("_Packed Item New 2", {"is_stock_item": 1})
+ make_product_bundle("_Test Product Bundle Item New 1", ["_Packed Item New 2"], 2)
+
+ so = make_sales_order(
+ item_code="_Test Product Bundle Item New 1",
+ )
+
+ mr = make_material_request(so.name)
+ self.assertEqual(mr.items[0].item_code, "_Packed Item New 2")
+
def test_bin_details_of_packed_item(self):
# test Update Items with product bundle
if not frappe.db.exists("Item", "_Test Product Bundle Item New"):
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index ef4155e..aff9587 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -395,16 +395,16 @@
def validate_warehouse_for_reorder(self):
"""Validate Reorder level table for duplicate and conditional mandatory"""
- warehouse = []
+ warehouse_material_request_type: list[tuple[str, str]] = []
for d in self.get("reorder_levels"):
if not d.warehouse_group:
d.warehouse_group = d.warehouse
- if d.get("warehouse") and d.get("warehouse") not in warehouse:
- warehouse += [d.get("warehouse")]
+ if (d.get("warehouse"), d.get("material_request_type")) not in warehouse_material_request_type:
+ warehouse_material_request_type += [(d.get("warehouse"), d.get("material_request_type"))]
else:
frappe.throw(
- _("Row {0}: An Reorder entry already exists for this warehouse {1}").format(
- d.idx, d.warehouse
+ _("Row #{0}: A reorder entry already exists for warehouse {1} with reorder type {2}.").format(
+ d.idx, d.warehouse, d.material_request_type
),
DuplicateReorderRows,
)
diff --git a/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py b/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py
index bdc9d74..176a215 100644
--- a/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py
+++ b/erpnext/stock/report/batch_wise_balance_history/batch_wise_balance_history.py
@@ -17,7 +17,7 @@
if not filters:
filters = {}
- sle_count = frappe.db.count("Stock Ledger Entry", {"is_cancelled": 0})
+ sle_count = frappe.db.count("Stock Ledger Entry")
if sle_count > SLE_COUNT_LIMIT and not filters.get("item_code") and not filters.get("warehouse"):
frappe.throw(_("Please select either the Item or Warehouse filter to generate the report."))