Merge pull request #38284 from vorasmit/fetch-item-tax-values
fix: fetch item_tax_template values if fields with fetch_from exisit
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.json b/erpnext/accounts/doctype/journal_entry/journal_entry.json
index 2eb54a5..906760e 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.json
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.json
@@ -548,8 +548,16 @@
"icon": "fa fa-file-text",
"idx": 176,
"is_submittable": 1,
- "links": [],
- "modified": "2023-08-10 14:32:22.366895",
+ "links": [
+ {
+ "is_child_table": 1,
+ "link_doctype": "Bank Transaction Payments",
+ "link_fieldname": "payment_entry",
+ "parent_doctype": "Bank Transaction",
+ "table_fieldname": "payment_entries"
+ }
+ ],
+ "modified": "2023-11-23 12:11:04.128015",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Journal Entry",
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 85ef6f7..1cff4c7 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -868,7 +868,7 @@
party_account_currency = d.account_currency
elif frappe.get_cached_value("Account", d.account, "account_type") in ["Bank", "Cash"]:
- bank_amount += d.debit_in_account_currency or d.credit_in_account_currency
+ bank_amount += flt(d.debit_in_account_currency) or flt(d.credit_in_account_currency)
bank_account_currency = d.account_currency
if party_type and pay_to_recd_from:
diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
index 3ba8cea..3132fe9 100644
--- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
+++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json
@@ -203,7 +203,8 @@
"fieldtype": "Select",
"label": "Reference Type",
"no_copy": 1,
- "options": "\nSales Invoice\nPurchase Invoice\nJournal Entry\nSales Order\nPurchase Order\nExpense Claim\nAsset\nLoan\nPayroll Entry\nEmployee Advance\nExchange Rate Revaluation\nInvoice Discounting\nFees\nFull and Final Statement\nPayment Entry"
+ "options": "\nSales Invoice\nPurchase Invoice\nJournal Entry\nSales Order\nPurchase Order\nExpense Claim\nAsset\nLoan\nPayroll Entry\nEmployee Advance\nExchange Rate Revaluation\nInvoice Discounting\nFees\nFull and Final Statement\nPayment Entry",
+ "search_index": 1
},
{
"fieldname": "reference_name",
@@ -211,7 +212,8 @@
"in_list_view": 1,
"label": "Reference Name",
"no_copy": 1,
- "options": "reference_type"
+ "options": "reference_type",
+ "search_index": 1
},
{
"depends_on": "eval:doc.reference_type&&!in_list(doc.reference_type, ['Expense Claim', 'Asset', 'Employee Loan', 'Employee Advance'])",
@@ -278,13 +280,14 @@
"fieldtype": "Data",
"hidden": 1,
"label": "Reference Detail No",
- "no_copy": 1
+ "no_copy": 1,
+ "search_index": 1
}
],
"idx": 1,
"istable": 1,
"links": [],
- "modified": "2023-06-16 14:11:13.507807",
+ "modified": "2023-11-23 11:44:25.841187",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Journal Entry Account",
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.json b/erpnext/accounts/doctype/payment_entry/payment_entry.json
index 4d50a35..aa18156 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.json
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.json
@@ -750,8 +750,16 @@
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
- "links": [],
- "modified": "2023-11-08 21:51:03.482709",
+ "links": [
+ {
+ "is_child_table": 1,
+ "link_doctype": "Bank Transaction Payments",
+ "link_fieldname": "payment_entry",
+ "parent_doctype": "Bank Transaction",
+ "table_fieldname": "payment_entries"
+ }
+ ],
+ "modified": "2023-11-23 12:07:20.887885",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Payment Entry",
diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
index e36e97b..9091a77 100644
--- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
+++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py
@@ -556,7 +556,7 @@
return bin_qty - pos_sales_qty, is_stock_item
else:
is_stock_item = True
- if frappe.db.exists("Product Bundle", item_code):
+ if frappe.db.exists("Product Bundle", {"name": item_code, "disabled": 0}):
return get_bundle_availability(item_code, warehouse), is_stock_item
else:
is_stock_item = False
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index d7c2361..c6ae937 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -527,7 +527,11 @@
if self.update_stock == 1:
self.repost_future_sle_and_gle()
- self.update_project()
+ if (
+ frappe.db.get_single_value("Buying Settings", "project_update_frequency") == "Each Transaction"
+ ):
+ self.update_project()
+
update_linked_doc(self.doctype, self.name, self.inter_company_invoice_reference)
self.update_advance_tax_references()
@@ -1262,7 +1266,10 @@
if self.update_stock == 1:
self.repost_future_sle_and_gle()
- self.update_project()
+ if (
+ frappe.db.get_single_value("Buying Settings", "project_update_frequency") == "Each Transaction"
+ ):
+ self.update_project()
self.db_set("status", "Cancelled")
unlink_inter_company_doc(self.doctype, self.name, self.inter_company_invoice_reference)
@@ -1281,13 +1288,21 @@
self.update_advance_tax_references(cancel=1)
def update_project(self):
- project_list = []
+ projects = frappe._dict()
for d in self.items:
- if d.project and d.project not in project_list:
- project = frappe.get_doc("Project", d.project)
- project.update_purchase_costing()
- project.db_update()
- project_list.append(d.project)
+ if d.project:
+ if self.docstatus == 1:
+ projects[d.project] = projects.get(d.project, 0) + d.base_net_amount
+ elif self.docstatus == 2:
+ projects[d.project] = projects.get(d.project, 0) - d.base_net_amount
+
+ pj = frappe.qb.DocType("Project")
+ for proj, value in projects.items():
+ res = (
+ frappe.qb.from_(pj).select(pj.total_purchase_cost).where(pj.name == proj).for_update().run()
+ )
+ current_purchase_cost = res and res[0][0] or 0
+ frappe.db.set_value("Project", proj, "total_purchase_cost", current_purchase_cost + value)
def validate_supplier_invoice(self):
if self.bill_date:
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index d167783..f209487 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -1615,7 +1615,8 @@
"hide_seconds": 1,
"label": "Inter Company Invoice Reference",
"options": "Purchase Invoice",
- "read_only": 1
+ "read_only": 1,
+ "search_index": 1
},
{
"fieldname": "customer_group",
@@ -2173,7 +2174,7 @@
"link_fieldname": "consolidated_invoice"
}
],
- "modified": "2023-11-20 11:51:43.555197",
+ "modified": "2023-11-23 16:56:29.679499",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 6d2a47f..9d32a03 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -183,6 +183,7 @@
cost_center=None,
ignore_account_permission=False,
account_type=None,
+ start_date=None,
):
if not account and frappe.form_dict.get("account"):
account = frappe.form_dict.get("account")
@@ -196,6 +197,8 @@
cost_center = frappe.form_dict.get("cost_center")
cond = ["is_cancelled=0"]
+ if start_date:
+ cond.append("posting_date >= %s" % frappe.db.escape(cstr(start_date)))
if date:
cond.append("posting_date <= %s" % frappe.db.escape(cstr(date)))
else:
diff --git a/erpnext/assets/doctype/asset/depreciation.py b/erpnext/assets/doctype/asset/depreciation.py
index 84a428c..66930c0 100644
--- a/erpnext/assets/doctype/asset/depreciation.py
+++ b/erpnext/assets/doctype/asset/depreciation.py
@@ -509,6 +509,9 @@
def depreciate_asset(asset_doc, date, notes):
+ if not asset_doc.calculate_depreciation:
+ return
+
asset_doc.flags.ignore_validate_update_after_submit = True
make_new_active_asset_depr_schedules_and_cancel_current_ones(
@@ -521,6 +524,9 @@
def reset_depreciation_schedule(asset_doc, date, notes):
+ if not asset_doc.calculate_depreciation:
+ return
+
asset_doc.flags.ignore_validate_update_after_submit = True
make_new_active_asset_depr_schedules_and_cancel_current_ones(
diff --git a/erpnext/buying/doctype/buying_settings/buying_settings.json b/erpnext/buying/doctype/buying_settings/buying_settings.json
index 0599992..0af93bf 100644
--- a/erpnext/buying/doctype/buying_settings/buying_settings.json
+++ b/erpnext/buying/doctype/buying_settings/buying_settings.json
@@ -17,6 +17,7 @@
"po_required",
"pr_required",
"blanket_order_allowance",
+ "project_update_frequency",
"column_break_12",
"maintain_same_rate",
"set_landed_cost_based_on_purchase_invoice_rate",
@@ -172,6 +173,14 @@
"fieldname": "blanket_order_allowance",
"fieldtype": "Float",
"label": "Blanket Order Allowance (%)"
+ },
+ {
+ "default": "Each Transaction",
+ "description": "How often should Project be updated of Total Purchase Cost ?",
+ "fieldname": "project_update_frequency",
+ "fieldtype": "Select",
+ "label": "Update frequency of Project",
+ "options": "Each Transaction\nManual"
}
],
"icon": "fa fa-cog",
@@ -179,7 +188,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
- "modified": "2023-10-25 14:03:32.520418",
+ "modified": "2023-11-24 10:55:51.287327",
"modified_by": "Administrator",
"module": "Buying",
"name": "Buying Settings",
diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py
index 31bf439..b052f56 100644
--- a/erpnext/buying/doctype/supplier/supplier.py
+++ b/erpnext/buying/doctype/supplier/supplier.py
@@ -165,16 +165,17 @@
@frappe.validate_and_sanitize_search_inputs
def get_supplier_primary_contact(doctype, txt, searchfield, start, page_len, filters):
supplier = filters.get("supplier")
- return frappe.db.sql(
- """
- SELECT
- `tabContact`.name from `tabContact`,
- `tabDynamic Link`
- WHERE
- `tabContact`.name = `tabDynamic Link`.parent
- and `tabDynamic Link`.link_name = %(supplier)s
- and `tabDynamic Link`.link_doctype = 'Supplier'
- and `tabContact`.name like %(txt)s
- """,
- {"supplier": supplier, "txt": "%%%s%%" % txt},
- )
+ contact = frappe.qb.DocType("Contact")
+ dynamic_link = frappe.qb.DocType("Dynamic Link")
+
+ return (
+ frappe.qb.from_(contact)
+ .join(dynamic_link)
+ .on(contact.name == dynamic_link.parent)
+ .select(contact.name, contact.email_id)
+ .where(
+ (dynamic_link.link_name == supplier)
+ & (dynamic_link.link_doctype == "Supplier")
+ & (contact.name.like("%{0}%".format(txt)))
+ )
+ ).run(as_dict=False)
diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py
index d34fbeb..5575a24 100644
--- a/erpnext/controllers/selling_controller.py
+++ b/erpnext/controllers/selling_controller.py
@@ -350,11 +350,12 @@
return il
def has_product_bundle(self, item_code):
- return frappe.db.sql(
- """select name from `tabProduct Bundle`
- where new_item_code=%s and docstatus != 2""",
- item_code,
- )
+ product_bundle = frappe.qb.DocType("Product Bundle")
+ return (
+ frappe.qb.from_(product_bundle)
+ .select(product_bundle.name)
+ .where((product_bundle.new_item_code == item_code) & (product_bundle.disabled == 0))
+ ).run()
def get_already_delivered_qty(self, current_docname, so, so_detail):
delivered_via_dn = frappe.db.sql(
diff --git a/erpnext/crm/doctype/competitor/competitor.json b/erpnext/crm/doctype/competitor/competitor.json
index 280441f..fd6da23 100644
--- a/erpnext/crm/doctype/competitor/competitor.json
+++ b/erpnext/crm/doctype/competitor/competitor.json
@@ -29,8 +29,16 @@
}
],
"index_web_pages_for_search": 1,
- "links": [],
- "modified": "2021-10-21 12:43:59.106807",
+ "links": [
+ {
+ "is_child_table": 1,
+ "link_doctype": "Competitor Detail",
+ "link_fieldname": "competitor",
+ "parent_doctype": "Quotation",
+ "table_fieldname": "competitors"
+ }
+ ],
+ "modified": "2023-11-23 19:33:54.284279",
"modified_by": "Administrator",
"module": "CRM",
"name": "Competitor",
@@ -64,5 +72,6 @@
"quick_entry": 1,
"sort_field": "modified",
"sort_order": "DESC",
+ "states": [],
"track_changes": 1
}
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/job_card/job_card.py b/erpnext/manufacturing/doctype/job_card/job_card.py
index db6bc80..f303531 100644
--- a/erpnext/manufacturing/doctype/job_card/job_card.py
+++ b/erpnext/manufacturing/doctype/job_card/job_card.py
@@ -185,7 +185,8 @@
# override capacity for employee
production_capacity = 1
- if time_logs and production_capacity > len(time_logs):
+ overlap_count = self.get_overlap_count(time_logs)
+ if time_logs and production_capacity > overlap_count:
return {}
if self.workstation_type and time_logs:
@@ -195,6 +196,37 @@
return time_logs[-1]
+ @staticmethod
+ def get_overlap_count(time_logs):
+ count = 1
+
+ # Check overlap exists or not between the overlapping time logs with the current Job Card
+ for idx, row in enumerate(time_logs):
+ next_idx = idx
+ if idx + 1 < len(time_logs):
+ next_idx = idx + 1
+ next_row = time_logs[next_idx]
+ if row.name == next_row.name:
+ continue
+
+ if (
+ (
+ get_datetime(next_row.from_time) >= get_datetime(row.from_time)
+ and get_datetime(next_row.from_time) <= get_datetime(row.to_time)
+ )
+ or (
+ get_datetime(next_row.to_time) >= get_datetime(row.from_time)
+ and get_datetime(next_row.to_time) <= get_datetime(row.to_time)
+ )
+ or (
+ get_datetime(next_row.from_time) <= get_datetime(row.from_time)
+ and get_datetime(next_row.to_time) >= get_datetime(row.to_time)
+ )
+ ):
+ count += 1
+
+ return count
+
def get_time_logs(self, args, doctype, check_next_available_slot=False):
jc = frappe.qb.DocType("Job Card")
jctl = frappe.qb.DocType(doctype)
@@ -211,7 +243,14 @@
query = (
frappe.qb.from_(jctl)
.from_(jc)
- .select(jc.name.as_("name"), jctl.from_time, jctl.to_time, jc.workstation, jc.workstation_type)
+ .select(
+ jc.name.as_("name"),
+ jctl.name.as_("row_name"),
+ jctl.from_time,
+ jctl.to_time,
+ jc.workstation,
+ jc.workstation_type,
+ )
.where(
(jctl.parent == jc.name)
& (Criterion.any(time_conditions))
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index a71d71b..a73502d 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -259,6 +259,7 @@
erpnext.patches.v15_0.saudi_depreciation_warning
erpnext.patches.v15_0.delete_saudi_doctypes
erpnext.patches.v14_0.show_loan_management_deprecation_warning
+erpnext.patches.v14_0.clear_reconciliation_values_from_singles
execute:frappe.rename_doc("Report", "TDS Payable Monthly", "Tax Withholding Details", force=True)
[post_model_sync]
@@ -345,11 +346,11 @@
erpnext.patches.v14_0.rename_over_order_allowance_field
erpnext.patches.v14_0.migrate_delivery_stop_lock_field
erpnext.patches.v14_0.add_default_for_repost_settings
-erpnext.patches.v14_0.clear_reconciliation_values_from_singles
erpnext.patches.v15_0.rename_daily_depreciation_to_depreciation_amount_based_on_num_days_in_month
erpnext.patches.v15_0.rename_depreciation_amount_based_on_num_days_in_month_to_daily_prorata_based
erpnext.patches.v15_0.set_reserved_stock_in_bin
erpnext.patches.v14_0.create_accounting_dimensions_in_supplier_quotation
erpnext.patches.v14_0.update_zero_asset_quantity_field
+execute:frappe.db.set_single_value("Buying Settings", "project_update_frequency", "Each Transaction")
# below migration patch should always run last
erpnext.patches.v14_0.migrate_gl_to_payment_ledger
diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js
index f366f77..2dac399 100644
--- a/erpnext/projects/doctype/project/project.js
+++ b/erpnext/projects/doctype/project/project.js
@@ -68,6 +68,10 @@
frm.events.create_duplicate(frm);
}, __("Actions"));
+ frm.add_custom_button(__('Update Total Purchase Cost'), () => {
+ frm.events.update_total_purchase_cost(frm);
+ }, __("Actions"));
+
frm.trigger("set_project_status_button");
@@ -92,6 +96,22 @@
},
+ update_total_purchase_cost: function(frm) {
+ frappe.call({
+ method: "erpnext.projects.doctype.project.project.recalculate_project_total_purchase_cost",
+ args: {project: frm.doc.name},
+ freeze: true,
+ freeze_message: __('Recalculating Purchase Cost against this Project...'),
+ callback: function(r) {
+ if (r && !r.exc) {
+ frappe.msgprint(__('Total Purchase Cost has been updated'));
+ frm.refresh();
+ }
+ }
+
+ });
+ },
+
set_project_status_button: function(frm) {
frm.add_custom_button(__('Set Project Status'), () => {
let d = new frappe.ui.Dialog({
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index e9aed1a..4f2e395 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -4,11 +4,11 @@
import frappe
from email_reply_parser import EmailReplyParser
-from frappe import _
+from frappe import _, qb
from frappe.desk.reportview import get_match_cond
from frappe.model.document import Document
from frappe.query_builder import Interval
-from frappe.query_builder.functions import Count, CurDate, Date, UnixTimestamp
+from frappe.query_builder.functions import Count, CurDate, Date, Sum, UnixTimestamp
from frappe.utils import add_days, flt, get_datetime, get_time, get_url, nowtime, today
from frappe.utils.user import is_website_user
@@ -249,12 +249,7 @@
self.per_gross_margin = (self.gross_margin / flt(self.total_billed_amount)) * 100
def update_purchase_costing(self):
- total_purchase_cost = frappe.db.sql(
- """select sum(base_net_amount)
- from `tabPurchase Invoice Item` where project = %s and docstatus=1""",
- self.name,
- )
-
+ total_purchase_cost = calculate_total_purchase_cost(self.name)
self.total_purchase_cost = total_purchase_cost and total_purchase_cost[0][0] or 0
def update_sales_amount(self):
@@ -695,3 +690,29 @@
def get_users_email(doc):
return [d.email for d in doc.users if frappe.db.get_value("User", d.user, "enabled")]
+
+
+def calculate_total_purchase_cost(project: str | None = None):
+ if project:
+ pitem = qb.DocType("Purchase Invoice Item")
+ frappe.qb.DocType("Purchase Invoice Item")
+ total_purchase_cost = (
+ qb.from_(pitem)
+ .select(Sum(pitem.base_net_amount))
+ .where((pitem.project == project) & (pitem.docstatus == 1))
+ .run(as_list=True)
+ )
+ return total_purchase_cost
+ return None
+
+
+@frappe.whitelist()
+def recalculate_project_total_purchase_cost(project: str | None = None):
+ if project:
+ total_purchase_cost = calculate_total_purchase_cost(project)
+ frappe.db.set_value(
+ "Project",
+ project,
+ "total_purchase_cost",
+ (total_purchase_cost and total_purchase_cost[0][0] or 0),
+ )
diff --git a/erpnext/selling/doctype/product_bundle/product_bundle.json b/erpnext/selling/doctype/product_bundle/product_bundle.json
index 56155fb..c4f21b6 100644
--- a/erpnext/selling/doctype/product_bundle/product_bundle.json
+++ b/erpnext/selling/doctype/product_bundle/product_bundle.json
@@ -1,315 +1,119 @@
{
- "allow_copy": 0,
- "allow_guest_to_view": 0,
- "allow_import": 1,
- "allow_rename": 0,
- "beta": 0,
- "creation": "2013-06-20 11:53:21",
- "custom": 0,
- "description": "Aggregate group of **Items** into another **Item**. This is useful if you are bundling a certain **Items** into a package and you maintain stock of the packed **Items** and not the aggregate **Item**. \n\nThe package **Item** will have \"Is Stock Item\" as \"No\" and \"Is Sales Item\" as \"Yes\".\n\nFor Example: If you are selling Laptops and Backpacks separately and have a special price if the customer buys both, then the Laptop + Backpack will be a new Product Bundle Item.\n\nNote: BOM = Bill of Materials",
- "docstatus": 0,
- "doctype": "DocType",
- "document_type": "",
- "editable_grid": 0,
+ "actions": [],
+ "allow_import": 1,
+ "creation": "2013-06-20 11:53:21",
+ "description": "Aggregate group of **Items** into another **Item**. This is useful if you are bundling a certain **Items** into a package and you maintain stock of the packed **Items** and not the aggregate **Item**. \n\nThe package **Item** will have \"Is Stock Item\" as \"No\" and \"Is Sales Item\" as \"Yes\".\n\nFor Example: If you are selling Laptops and Backpacks separately and have a special price if the customer buys both, then the Laptop + Backpack will be a new Product Bundle Item.\n\nNote: BOM = Bill of Materials",
+ "doctype": "DocType",
+ "engine": "InnoDB",
+ "field_order": [
+ "basic_section",
+ "new_item_code",
+ "description",
+ "column_break_eonk",
+ "disabled",
+ "item_section",
+ "items",
+ "section_break_4",
+ "about"
+ ],
"fields": [
{
- "allow_bulk_edit": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "basic_section",
- "fieldtype": "Section Break",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
- },
+ "fieldname": "basic_section",
+ "fieldtype": "Section Break"
+ },
{
- "allow_bulk_edit": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "description": "",
- "fieldname": "new_item_code",
- "fieldtype": "Link",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 1,
- "in_list_view": 1,
- "in_standard_filter": 0,
- "label": "Parent Item",
- "length": 0,
- "no_copy": 1,
- "oldfieldname": "new_item_code",
- "oldfieldtype": "Data",
- "options": "Item",
- "permlevel": 0,
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 1,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
- },
+ "fieldname": "new_item_code",
+ "fieldtype": "Link",
+ "in_global_search": 1,
+ "in_list_view": 1,
+ "label": "Parent Item",
+ "no_copy": 1,
+ "oldfieldname": "new_item_code",
+ "oldfieldtype": "Data",
+ "options": "Item",
+ "reqd": 1
+ },
{
- "allow_bulk_edit": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "description",
- "fieldtype": "Data",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 1,
- "in_standard_filter": 0,
- "label": "Description",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
- },
+ "fieldname": "description",
+ "fieldtype": "Data",
+ "in_list_view": 1,
+ "label": "Description"
+ },
{
- "allow_bulk_edit": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "description": "List items that form the package.",
- "fieldname": "item_section",
- "fieldtype": "Section Break",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Items",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
- },
+ "description": "List items that form the package.",
+ "fieldname": "item_section",
+ "fieldtype": "Section Break",
+ "label": "Items"
+ },
{
- "allow_bulk_edit": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "items",
- "fieldtype": "Table",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Items",
- "length": 0,
- "no_copy": 0,
- "oldfieldname": "sales_bom_items",
- "oldfieldtype": "Table",
- "options": "Product Bundle Item",
- "permlevel": 0,
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 1,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
- },
+ "fieldname": "items",
+ "fieldtype": "Table",
+ "label": "Items",
+ "oldfieldname": "sales_bom_items",
+ "oldfieldtype": "Table",
+ "options": "Product Bundle Item",
+ "reqd": 1
+ },
{
- "allow_bulk_edit": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "section_break_4",
- "fieldtype": "Section Break",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
- },
+ "fieldname": "section_break_4",
+ "fieldtype": "Section Break"
+ },
{
- "allow_bulk_edit": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "about",
- "fieldtype": "HTML",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "",
- "length": 0,
- "no_copy": 0,
- "options": "<h3>About Product Bundle</h3>\n\n<p>Aggregate group of <b>Items</b> into another <b>Item</b>. This is useful if you are bundling a certain <b>Items</b> into a package and you maintain stock of the packed <b>Items</b> and not the aggregate <b>Item</b>.</p>\n<p>The package <b>Item</b> will have <code>Is Stock Item</code> as <b>No</b> and <code>Is Sales Item</code> as <b>Yes</b>.</p>\n<h4>Example:</h4>\n<p>If you are selling Laptops and Backpacks separately and have a special price if the customer buys both, then the Laptop + Backpack will be a new Product Bundle Item.</p>",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
+ "fieldname": "about",
+ "fieldtype": "HTML",
+ "options": "<h3>About Product Bundle</h3>\n\n<p>Aggregate group of <b>Items</b> into another <b>Item</b>. This is useful if you are bundling a certain <b>Items</b> into a package and you maintain stock of the packed <b>Items</b> and not the aggregate <b>Item</b>.</p>\n<p>The package <b>Item</b> will have <code>Is Stock Item</code> as <b>No</b> and <code>Is Sales Item</code> as <b>Yes</b>.</p>\n<h4>Example:</h4>\n<p>If you are selling Laptops and Backpacks separately and have a special price if the customer buys both, then the Laptop + Backpack will be a new Product Bundle Item.</p>"
+ },
+ {
+ "default": "0",
+ "fieldname": "disabled",
+ "fieldtype": "Check",
+ "label": "Disabled"
+ },
+ {
+ "fieldname": "column_break_eonk",
+ "fieldtype": "Column Break"
}
- ],
- "has_web_view": 0,
- "hide_heading": 0,
- "hide_toolbar": 0,
- "icon": "fa fa-sitemap",
- "idx": 1,
- "image_view": 0,
- "in_create": 0,
- "is_submittable": 0,
- "issingle": 0,
- "istable": 0,
- "max_attachments": 0,
- "modified": "2020-09-18 17:26:09.703215",
- "modified_by": "Administrator",
- "module": "Selling",
- "name": "Product Bundle",
- "owner": "Administrator",
+ ],
+ "icon": "fa fa-sitemap",
+ "idx": 1,
+ "links": [],
+ "modified": "2023-11-22 15:20:46.805114",
+ "modified_by": "Administrator",
+ "module": "Selling",
+ "name": "Product Bundle",
+ "owner": "Administrator",
"permissions": [
{
- "amend": 0,
- "apply_user_permissions": 0,
- "cancel": 0,
- "create": 1,
- "delete": 1,
- "email": 1,
- "export": 0,
- "if_owner": 0,
- "import": 0,
- "permlevel": 0,
- "print": 1,
- "read": 1,
- "report": 1,
- "role": "Stock Manager",
- "set_user_permissions": 0,
- "share": 1,
- "submit": 0,
+ "create": 1,
+ "delete": 1,
+ "email": 1,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "Stock Manager",
+ "share": 1,
"write": 1
- },
+ },
{
- "amend": 0,
- "apply_user_permissions": 0,
- "cancel": 0,
- "create": 0,
- "delete": 0,
- "email": 1,
- "export": 0,
- "if_owner": 0,
- "import": 0,
- "permlevel": 0,
- "print": 1,
- "read": 1,
- "report": 1,
- "role": "Stock User",
- "set_user_permissions": 0,
- "share": 0,
- "submit": 0,
- "write": 0
- },
+ "email": 1,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "Stock User"
+ },
{
- "amend": 0,
- "apply_user_permissions": 0,
- "cancel": 0,
- "create": 1,
- "delete": 1,
- "email": 1,
- "export": 0,
- "if_owner": 0,
- "import": 0,
- "permlevel": 0,
- "print": 1,
- "read": 1,
- "report": 1,
- "role": "Sales User",
- "set_user_permissions": 0,
- "share": 1,
- "submit": 0,
+ "create": 1,
+ "delete": 1,
+ "email": 1,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "Sales User",
+ "share": 1,
"write": 1
}
- ],
- "quick_entry": 0,
- "read_only": 0,
- "read_only_onload": 0,
- "show_name_in_global_search": 0,
- "sort_order": "ASC",
- "track_changes": 0,
- "track_seen": 0
+ ],
+ "sort_field": "modified",
+ "sort_order": "ASC",
+ "states": []
}
\ No newline at end of file
diff --git a/erpnext/selling/doctype/product_bundle/product_bundle.py b/erpnext/selling/doctype/product_bundle/product_bundle.py
index ac83c0f..2fd9cc1 100644
--- a/erpnext/selling/doctype/product_bundle/product_bundle.py
+++ b/erpnext/selling/doctype/product_bundle/product_bundle.py
@@ -59,10 +59,12 @@
"""Validates, main Item is not a stock item"""
if frappe.db.get_value("Item", self.new_item_code, "is_stock_item"):
frappe.throw(_("Parent Item {0} must not be a Stock Item").format(self.new_item_code))
+ if frappe.db.get_value("Item", self.new_item_code, "is_fixed_asset"):
+ frappe.throw(_("Parent Item {0} must not be a Fixed Asset").format(self.new_item_code))
def validate_child_items(self):
for item in self.items:
- if frappe.db.exists("Product Bundle", item.item_code):
+ if frappe.db.exists("Product Bundle", {"name": item.item_code, "disabled": 0}):
frappe.throw(
_(
"Row #{0}: Child Item should not be a Product Bundle. Please remove Item {1} and Save"
@@ -73,12 +75,17 @@
@frappe.whitelist()
@frappe.validate_and_sanitize_search_inputs
def get_new_item_code(doctype, txt, searchfield, start, page_len, filters):
- from erpnext.controllers.queries import get_match_cond
-
- return frappe.db.sql(
- """select name, item_name, description from tabItem
- where is_stock_item=0 and name not in (select name from `tabProduct Bundle`)
- and %s like %s %s limit %s offset %s"""
- % (searchfield, "%s", get_match_cond(doctype), "%s", "%s"),
- ("%%%s%%" % txt, page_len, start),
- )
+ product_bundles = frappe.db.get_list("Product Bundle", {"disabled": 0}, pluck="name")
+ item = frappe.qb.DocType("Item")
+ return (
+ frappe.qb.from_(item)
+ .select("*")
+ .where(
+ (item.is_stock_item == 0)
+ & (item.is_fixed_asset == 0)
+ & (item.name.notin(product_bundles))
+ & (item[searchfield].like(f"%{txt}%"))
+ )
+ .limit(page_len)
+ .offset(start)
+ ).run()
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index 3ad18da..97b214e 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -214,13 +214,12 @@
label: __("Items to Reserve"),
allow_bulk_edit: false,
cannot_add_rows: true,
- cannot_delete_rows: true,
data: [],
fields: [
{
- fieldname: "name",
+ fieldname: "sales_order_item",
fieldtype: "Data",
- label: __("Name"),
+ label: __("Sales Order Item"),
reqd: 1,
read_only: 1,
},
@@ -260,7 +259,7 @@
],
primary_action_label: __("Reserve Stock"),
primary_action: () => {
- var data = {items: dialog.fields_dict.items.grid.get_selected_children()};
+ var data = {items: dialog.fields_dict.items.grid.data};
if (data.items && data.items.length > 0) {
frappe.call({
@@ -278,9 +277,6 @@
}
});
}
- else {
- frappe.msgprint(__("Please select items to reserve."));
- }
dialog.hide();
},
@@ -292,7 +288,7 @@
if (unreserved_qty > 0) {
dialog.fields_dict.items.df.data.push({
- 'name': item.name,
+ 'sales_order_item': item.name,
'item_code': item.item_code,
'warehouse': item.warehouse,
'qty_to_reserve': (unreserved_qty / flt(item.conversion_factor))
@@ -308,7 +304,7 @@
cancel_stock_reservation_entries(frm) {
const dialog = new frappe.ui.Dialog({
title: __("Stock Unreservation"),
- size: "large",
+ size: "extra-large",
fields: [
{
fieldname: "sr_entries",
@@ -316,14 +312,13 @@
label: __("Reserved Stock"),
allow_bulk_edit: false,
cannot_add_rows: true,
- cannot_delete_rows: true,
in_place_edit: true,
data: [],
fields: [
{
- fieldname: "name",
+ fieldname: "sre",
fieldtype: "Link",
- label: __("SRE"),
+ label: __("Stock Reservation Entry"),
options: "Stock Reservation Entry",
reqd: 1,
read_only: 1,
@@ -360,14 +355,14 @@
],
primary_action_label: __("Unreserve Stock"),
primary_action: () => {
- var data = {sr_entries: dialog.fields_dict.sr_entries.grid.get_selected_children()};
+ var data = {sr_entries: dialog.fields_dict.sr_entries.grid.data};
if (data.sr_entries && data.sr_entries.length > 0) {
frappe.call({
doc: frm.doc,
method: "cancel_stock_reservation_entries",
args: {
- sre_list: data.sr_entries,
+ sre_list: data.sr_entries.map(item => item.sre),
},
freeze: true,
freeze_message: __('Unreserving Stock...'),
@@ -377,9 +372,6 @@
}
});
}
- else {
- frappe.msgprint(__("Please select items to unreserve."));
- }
dialog.hide();
},
@@ -396,7 +388,7 @@
r.message.forEach(sre => {
if (flt(sre.reserved_qty) > flt(sre.delivered_qty)) {
dialog.fields_dict.sr_entries.df.data.push({
- 'name': sre.name,
+ 'sre': sre.name,
'item_code': sre.item_code,
'warehouse': sre.warehouse,
'qty': (flt(sre.reserved_qty) - flt(sre.delivered_qty))
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index a97198a..a23599b 100755
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -688,7 +688,9 @@
"Sales Order Item": {
"doctype": "Material Request Item",
"field_map": {"name": "sales_order_item", "parent": "sales_order"},
- "condition": lambda item: not frappe.db.exists("Product Bundle", item.item_code)
+ "condition": lambda item: not frappe.db.exists(
+ "Product Bundle", {"name": item.item_code, "disabled": 0}
+ )
and get_remaining_qty(item) > 0,
"postprocess": update_item,
},
@@ -1309,7 +1311,7 @@
def is_product_bundle(item_code):
- return frappe.db.exists("Product Bundle", item_code)
+ return frappe.db.exists("Product Bundle", {"name": item_code, "disabled": 0})
@frappe.whitelist()
@@ -1521,7 +1523,7 @@
product_bundle_parents = [
pb.new_item_code
for pb in frappe.get_all(
- "Product Bundle", {"new_item_code": ["in", item_codes]}, ["new_item_code"]
+ "Product Bundle", {"new_item_code": ["in", item_codes], "disabled": 0}, ["new_item_code"]
)
]
diff --git a/erpnext/selling/report/lost_quotations/__init__.py b/erpnext/selling/report/lost_quotations/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/selling/report/lost_quotations/__init__.py
diff --git a/erpnext/selling/report/lost_quotations/lost_quotations.js b/erpnext/selling/report/lost_quotations/lost_quotations.js
new file mode 100644
index 0000000..78e76cb
--- /dev/null
+++ b/erpnext/selling/report/lost_quotations/lost_quotations.js
@@ -0,0 +1,40 @@
+// Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.query_reports["Lost Quotations"] = {
+ filters: [
+ {
+ fieldname: "company",
+ label: __("Company"),
+ fieldtype: "Link",
+ options: "Company",
+ default: frappe.defaults.get_user_default("Company"),
+ },
+ {
+ label: "Timespan",
+ fieldtype: "Select",
+ fieldname: "timespan",
+ options: [
+ "Last Week",
+ "Last Month",
+ "Last Quarter",
+ "Last 6 months",
+ "Last Year",
+ "This Week",
+ "This Month",
+ "This Quarter",
+ "This Year",
+ ],
+ default: "This Year",
+ reqd: 1,
+ },
+ {
+ fieldname: "group_by",
+ label: __("Group By"),
+ fieldtype: "Select",
+ options: ["Lost Reason", "Competitor"],
+ default: "Lost Reason",
+ reqd: 1,
+ },
+ ],
+};
diff --git a/erpnext/selling/report/lost_quotations/lost_quotations.json b/erpnext/selling/report/lost_quotations/lost_quotations.json
new file mode 100644
index 0000000..8915bab
--- /dev/null
+++ b/erpnext/selling/report/lost_quotations/lost_quotations.json
@@ -0,0 +1,30 @@
+{
+ "add_total_row": 0,
+ "columns": [],
+ "creation": "2023-11-23 18:00:19.141922",
+ "disabled": 0,
+ "docstatus": 0,
+ "doctype": "Report",
+ "filters": [],
+ "idx": 0,
+ "is_standard": "Yes",
+ "letter_head": null,
+ "letterhead": null,
+ "modified": "2023-11-23 19:27:28.854108",
+ "modified_by": "Administrator",
+ "module": "Selling",
+ "name": "Lost Quotations",
+ "owner": "Administrator",
+ "prepared_report": 0,
+ "ref_doctype": "Quotation",
+ "report_name": "Lost Quotations",
+ "report_type": "Script Report",
+ "roles": [
+ {
+ "role": "Sales User"
+ },
+ {
+ "role": "Sales Manager"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/selling/report/lost_quotations/lost_quotations.py b/erpnext/selling/report/lost_quotations/lost_quotations.py
new file mode 100644
index 0000000..7c0bfbd
--- /dev/null
+++ b/erpnext/selling/report/lost_quotations/lost_quotations.py
@@ -0,0 +1,98 @@
+# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from typing import Literal
+
+import frappe
+from frappe import _
+from frappe.model.docstatus import DocStatus
+from frappe.query_builder.functions import Coalesce, Count, Round, Sum
+from frappe.utils.data import get_timespan_date_range
+
+
+def execute(filters=None):
+ columns = get_columns(filters.get("group_by"))
+ from_date, to_date = get_timespan_date_range(filters.get("timespan").lower())
+ data = get_data(filters.get("company"), from_date, to_date, filters.get("group_by"))
+ return columns, data
+
+
+def get_columns(group_by: Literal["Lost Reason", "Competitor"]):
+ return [
+ {
+ "fieldname": "lost_reason" if group_by == "Lost Reason" else "competitor",
+ "label": _("Lost Reason") if group_by == "Lost Reason" else _("Competitor"),
+ "fieldtype": "Link",
+ "options": "Quotation Lost Reason" if group_by == "Lost Reason" else "Competitor",
+ "width": 200,
+ },
+ {
+ "filedname": "lost_quotations",
+ "label": _("Lost Quotations"),
+ "fieldtype": "Int",
+ "width": 150,
+ },
+ {
+ "filedname": "lost_quotations_pct",
+ "label": _("Lost Quotations %"),
+ "fieldtype": "Percent",
+ "width": 200,
+ },
+ {
+ "fieldname": "lost_value",
+ "label": _("Lost Value"),
+ "fieldtype": "Currency",
+ "width": 150,
+ },
+ {
+ "filedname": "lost_value_pct",
+ "label": _("Lost Value %"),
+ "fieldtype": "Percent",
+ "width": 200,
+ },
+ ]
+
+
+def get_data(
+ company: str, from_date: str, to_date: str, group_by: Literal["Lost Reason", "Competitor"]
+):
+ """Return quotation value grouped by lost reason or competitor"""
+ if group_by == "Lost Reason":
+ fieldname = "lost_reason"
+ dimension = frappe.qb.DocType("Quotation Lost Reason Detail")
+ elif group_by == "Competitor":
+ fieldname = "competitor"
+ dimension = frappe.qb.DocType("Competitor Detail")
+ else:
+ frappe.throw(_("Invalid Group By"))
+
+ q = frappe.qb.DocType("Quotation")
+
+ lost_quotation_condition = (
+ (q.status == "Lost")
+ & (q.docstatus == DocStatus.submitted())
+ & (q.transaction_date >= from_date)
+ & (q.transaction_date <= to_date)
+ & (q.company == company)
+ )
+
+ from_lost_quotations = frappe.qb.from_(q).where(lost_quotation_condition)
+ total_quotations = from_lost_quotations.select(Count(q.name))
+ total_value = from_lost_quotations.select(Sum(q.base_net_total))
+
+ query = (
+ frappe.qb.from_(q)
+ .select(
+ Coalesce(dimension[fieldname], _("Not Specified")),
+ Count(q.name).distinct(),
+ Round((Count(q.name).distinct() / total_quotations * 100), 2),
+ Sum(q.base_net_total),
+ Round((Sum(q.base_net_total) / total_value * 100), 2),
+ )
+ .left_join(dimension)
+ .on(dimension.parent == q.name)
+ .where(lost_quotation_condition)
+ .groupby(dimension[fieldname])
+ )
+
+ return query.run()
diff --git a/erpnext/setup/doctype/email_digest/email_digest.py b/erpnext/setup/doctype/email_digest/email_digest.py
index 4fc20e6..6ed44ff 100644
--- a/erpnext/setup/doctype/email_digest/email_digest.py
+++ b/erpnext/setup/doctype/email_digest/email_digest.py
@@ -382,9 +382,10 @@
"""Get income to date"""
balance = 0.0
count = 0
+ fy_start_date = get_fiscal_year(self.future_to_date)[1]
for account in self.get_root_type_accounts(root_type):
- balance += get_balance_on(account, date=self.future_to_date)
+ balance += get_balance_on(account, date=self.future_to_date, start_date=fy_start_date)
count += get_count_on(account, fieldname, date=self.future_to_date)
if fieldname == "income":
diff --git a/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.json b/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.json
index 5d778ee..0eae08e 100644
--- a/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.json
+++ b/erpnext/setup/doctype/quotation_lost_reason/quotation_lost_reason.json
@@ -1,83 +1,58 @@
{
- "allow_copy": 0,
- "allow_import": 1,
- "allow_rename": 0,
- "autoname": "field:order_lost_reason",
- "beta": 0,
- "creation": "2013-01-10 16:34:24",
- "custom": 0,
- "docstatus": 0,
- "doctype": "DocType",
- "document_type": "Setup",
- "editable_grid": 0,
+ "actions": [],
+ "allow_import": 1,
+ "autoname": "field:order_lost_reason",
+ "creation": "2013-01-10 16:34:24",
+ "doctype": "DocType",
+ "document_type": "Setup",
+ "engine": "InnoDB",
+ "field_order": [
+ "order_lost_reason"
+ ],
"fields": [
{
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "fieldname": "order_lost_reason",
- "fieldtype": "Data",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_list_view": 1,
- "label": "Quotation Lost Reason",
- "length": 0,
- "no_copy": 0,
- "oldfieldname": "order_lost_reason",
- "oldfieldtype": "Data",
- "permlevel": 0,
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "report_hide": 0,
- "reqd": 1,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
+ "fieldname": "order_lost_reason",
+ "fieldtype": "Data",
+ "in_list_view": 1,
+ "label": "Quotation Lost Reason",
+ "oldfieldname": "order_lost_reason",
+ "oldfieldtype": "Data",
+ "reqd": 1,
+ "unique": 1
}
- ],
- "hide_heading": 0,
- "hide_toolbar": 0,
- "icon": "fa fa-flag",
- "idx": 1,
- "image_view": 0,
- "in_create": 0,
-
- "is_submittable": 0,
- "issingle": 0,
- "istable": 0,
- "max_attachments": 0,
- "modified": "2016-07-25 05:24:25.533953",
- "modified_by": "Administrator",
- "module": "Setup",
- "name": "Quotation Lost Reason",
- "owner": "Administrator",
+ ],
+ "icon": "fa fa-flag",
+ "idx": 1,
+ "links": [
+ {
+ "is_child_table": 1,
+ "link_doctype": "Quotation Lost Reason Detail",
+ "link_fieldname": "lost_reason",
+ "parent_doctype": "Quotation",
+ "table_fieldname": "lost_reasons"
+ }
+ ],
+ "modified": "2023-11-23 19:31:02.743353",
+ "modified_by": "Administrator",
+ "module": "Setup",
+ "name": "Quotation Lost Reason",
+ "naming_rule": "By fieldname",
+ "owner": "Administrator",
"permissions": [
{
- "amend": 0,
- "apply_user_permissions": 0,
- "cancel": 0,
- "create": 1,
- "delete": 1,
- "email": 1,
- "export": 0,
- "if_owner": 0,
- "import": 0,
- "permlevel": 0,
- "print": 1,
- "read": 1,
- "report": 1,
- "role": "Sales Master Manager",
- "set_user_permissions": 0,
- "share": 1,
- "submit": 0,
+ "create": 1,
+ "delete": 1,
+ "email": 1,
+ "print": 1,
+ "read": 1,
+ "report": 1,
+ "role": "Sales Master Manager",
+ "share": 1,
"write": 1
}
- ],
- "quick_entry": 1,
- "read_only": 0,
- "read_only_onload": 0,
- "track_seen": 0
+ ],
+ "quick_entry": 1,
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "states": []
}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py
index 66dd33a..f240136 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.py
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.py
@@ -615,7 +615,7 @@
items_list = [item.item_code for item in self.items]
return frappe.db.get_all(
"Product Bundle",
- filters={"new_item_code": ["in", items_list]},
+ filters={"new_item_code": ["in", items_list], "disabled": 0},
pluck="name",
)
@@ -938,7 +938,7 @@
},
"postprocess": update_item,
"condition": lambda item: (
- not frappe.db.exists("Product Bundle", {"new_item_code": item.item_code})
+ not frappe.db.exists("Product Bundle", {"new_item_code": item.item_code, "disabled": 0})
and flt(item.packed_qty) < flt(item.qty)
),
},
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index d8935fe..cb34497 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -512,8 +512,12 @@
def validate_duplicate_product_bundles_before_merge(self, old_name, new_name):
"Block merge if both old and new items have product bundles."
- old_bundle = frappe.get_value("Product Bundle", filters={"new_item_code": old_name})
- new_bundle = frappe.get_value("Product Bundle", filters={"new_item_code": new_name})
+ old_bundle = frappe.get_value(
+ "Product Bundle", filters={"new_item_code": old_name, "disabled": 0}
+ )
+ new_bundle = frappe.get_value(
+ "Product Bundle", filters={"new_item_code": new_name, "disabled": 0}
+ )
if old_bundle and new_bundle:
bundle_link = get_link_to_form("Product Bundle", old_bundle)
diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py
index a9e9ad1..35701c9 100644
--- a/erpnext/stock/doctype/packed_item/packed_item.py
+++ b/erpnext/stock/doctype/packed_item/packed_item.py
@@ -55,7 +55,7 @@
def is_product_bundle(item_code: str) -> bool:
- return bool(frappe.db.exists("Product Bundle", {"new_item_code": item_code}))
+ return bool(frappe.db.exists("Product Bundle", {"new_item_code": item_code, "disabled": 0}))
def get_indexed_packed_items_table(doc):
@@ -111,7 +111,7 @@
product_bundle_item.uom,
product_bundle_item.description,
)
- .where(product_bundle.new_item_code == item_code)
+ .where((product_bundle.new_item_code == item_code) & (product_bundle.disabled == 0))
.orderby(product_bundle_item.idx)
)
return query.run(as_dict=True)
diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py
index ed20209..e7f6204 100644
--- a/erpnext/stock/doctype/pick_list/pick_list.py
+++ b/erpnext/stock/doctype/pick_list/pick_list.py
@@ -233,7 +233,7 @@
for location in self.locations:
if location.warehouse and location.sales_order and location.sales_order_item:
item_details = {
- "name": location.sales_order_item,
+ "sales_order_item": location.sales_order_item,
"item_code": location.item_code,
"warehouse": location.warehouse,
"qty_to_reserve": (flt(location.picked_qty) - flt(location.stock_reserved_qty)),
@@ -368,7 +368,9 @@
frappe.throw("Row #{0}: Item Code is Mandatory".format(item.idx))
if not cint(
frappe.get_cached_value("Item", item.item_code, "is_stock_item")
- ) and not frappe.db.exists("Product Bundle", {"new_item_code": item.item_code}):
+ ) and not frappe.db.exists(
+ "Product Bundle", {"new_item_code": item.item_code, "disabled": 0}
+ ):
continue
item_code = item.item_code
reference = item.sales_order_item or item.material_request_item
@@ -507,7 +509,9 @@
# bundle_item_code: Dict[component, qty]
product_bundle_qty_map = {}
for bundle_item_code in bundles:
- bundle = frappe.get_last_doc("Product Bundle", {"new_item_code": bundle_item_code})
+ bundle = frappe.get_last_doc(
+ "Product Bundle", {"new_item_code": bundle_item_code, "disabled": 0}
+ )
product_bundle_qty_map[bundle_item_code] = {item.item_code: item.qty for item in bundle.items}
return product_bundle_qty_map
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index a5940f0..a7aa7e2 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -781,7 +781,7 @@
for item in self.items:
if item.sales_order and item.sales_order_item:
item_details = {
- "name": item.sales_order_item,
+ "sales_order_item": item.sales_order_item,
"item_code": item.item_code,
"warehouse": item.warehouse,
"qty_to_reserve": item.stock_qty,
diff --git a/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py b/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py
index 0954282..cbfa4e0 100644
--- a/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py
+++ b/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py
@@ -869,7 +869,7 @@
items = []
if items_details:
for item in items_details:
- so_item = frappe.get_doc("Sales Order Item", item.get("name"))
+ so_item = frappe.get_doc("Sales Order Item", item.get("sales_order_item"))
so_item.warehouse = item.get("warehouse")
so_item.qty_to_reserve = (
flt(item.get("qty_to_reserve"))
@@ -1053,12 +1053,14 @@
from_voucher_type: Literal["Pick List", "Purchase Receipt"] = None,
from_voucher_no: str = None,
from_voucher_detail_no: str = None,
- sre_list: list[dict] = None,
+ sre_list: list = None,
notify: bool = True,
) -> None:
"""Cancel Stock Reservation Entries."""
if not sre_list:
+ sre_list = {}
+
if voucher_type and voucher_no:
sre_list = get_stock_reservation_entries_for_voucher(
voucher_type, voucher_no, voucher_detail_no, fields=["name"]
@@ -1082,9 +1084,11 @@
sre_list = query.run(as_dict=True)
+ sre_list = [d.name for d in sre_list]
+
if sre_list:
for sre in sre_list:
- frappe.get_doc("Stock Reservation Entry", sre["name"]).cancel()
+ frappe.get_doc("Stock Reservation Entry", sre).cancel()
if notify:
msg = _("Stock Reservation Entries Cancelled")
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 5143067..dfeb1ee 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -150,7 +150,7 @@
def set_valuation_rate(out, args):
- if frappe.db.exists("Product Bundle", args.item_code, cache=True):
+ if frappe.db.exists("Product Bundle", {"name": args.item_code, "disabled": 0}, cache=True):
valuation_rate = 0.0
bundled_items = frappe.get_doc("Product Bundle", args.item_code)
diff --git a/erpnext/utilities/transaction_base.py b/erpnext/utilities/transaction_base.py
index 7eba35d..b083614 100644
--- a/erpnext/utilities/transaction_base.py
+++ b/erpnext/utilities/transaction_base.py
@@ -98,6 +98,7 @@
"Selling Settings", "None", ["maintain_same_rate_action", "role_to_override_stop_action"]
)
+ stop_actions = []
for ref_dt, ref_dn_field, ref_link_field in ref_details:
reference_names = [d.get(ref_link_field) for d in self.get("items") if d.get(ref_link_field)]
reference_details = self.get_reference_details(reference_names, ref_dt + " Item")
@@ -108,7 +109,7 @@
if abs(flt(d.rate - ref_rate, d.precision("rate"))) >= 0.01:
if action == "Stop":
if role_allowed_to_override not in frappe.get_roles():
- frappe.throw(
+ stop_actions.append(
_("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
)
@@ -121,6 +122,8 @@
title=_("Warning"),
indicator="orange",
)
+ if stop_actions:
+ frappe.throw(stop_actions, as_list=True)
def get_reference_details(self, reference_names, reference_doctype):
return frappe._dict(