From 00898be8e4638ed88e30ace37b752d2a3b5887c2 Mon Sep 17 00:00:00 2001 From: Nicolas Pereira <41456803+hqnicolas@users.noreply.github.com> Date: Fri, 13 Dec 2024 01:51:30 -0300 Subject: [PATCH 01/12] fix: Stock Entry uses incorrect company when generated from Pick List (#44679) --- erpnext/stock/doctype/pick_list/pick_list.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index 948437a82879..2176d75ee97f 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -982,6 +982,7 @@ def create_stock_entry(pick_list): stock_entry = frappe.new_doc("Stock Entry") stock_entry.pick_list = pick_list.get("name") stock_entry.purpose = pick_list.get("purpose") + stock_entry.company = pick_list.get("company") stock_entry.set_stock_entry_type() if pick_list.get("work_order"): From d83cc57e582885097d0b251cd9e9361c0cc280d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Di=C3=B3genes=20Souza?= <103958767+devdiogenes@users.noreply.github.com> Date: Fri, 13 Dec 2024 03:26:55 -0300 Subject: [PATCH 02/12] fix: Wrong allocated_amount for sales_team in gross_profit report (#42989) * fix: Wrong allocated_amount for sales_team in gross_profit report * style: Removes whitespaces --------- Co-authored-by: ruthra kumar --- erpnext/accounts/report/gross_profit/gross_profit.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index 833bb78a329f..15617a53cdff 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -768,7 +768,10 @@ def load_invoice_items(self): """ if self.filters.group_by == "Sales Person": - sales_person_cols = ", sales.sales_person, sales.allocated_amount, sales.incentives" + sales_person_cols = """, sales.sales_person, + sales.allocated_percentage * `tabSales Invoice Item`.base_net_amount / 100 as allocated_amount, + sales.incentives + """ sales_team_table = "left join `tabSales Team` sales on sales.parent = `tabSales Invoice`.name" else: sales_person_cols = "" From 4b4d5dfa63593dcbfb3ad35c2735e209c20d0436 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Fri, 13 Dec 2024 12:44:03 +0530 Subject: [PATCH 03/12] fix: incorrect status of the purchase receipt (#44689) --- erpnext/controllers/status_updater.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index e04618c857fa..db3bb16bc02e 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -94,7 +94,10 @@ def validate_status(status, options): ["To Bill", "eval:self.per_billed == 0 and self.docstatus == 1"], ["Partly Billed", "eval:self.per_billed > 0 and self.per_billed < 100 and self.docstatus == 1"], ["Return Issued", "eval:self.per_returned == 100 and self.docstatus == 1"], - ["Completed", "eval:self.per_billed == 100 and self.docstatus == 1"], + [ + "Completed", + "eval:(self.per_billed == 100 and self.docstatus == 1) or (self.docstatus == 1 and self.grand_total == 0 and self.per_returned != 100 and self.is_return == 0)", + ], ["Cancelled", "eval:self.docstatus==2"], ["Closed", "eval:self.status=='Closed' and self.docstatus != 2"], ], From b571c7af8743651809301a934ba86a222963c1ce Mon Sep 17 00:00:00 2001 From: ljain112 Date: Thu, 12 Dec 2024 15:15:07 +0530 Subject: [PATCH 04/12] fix: remove invalid filter in Account Receivable report --- .../report/accounts_receivable/accounts_receivable.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py index 7868b06fe331..f488b1a5832f 100644 --- a/erpnext/accounts/report/accounts_receivable/accounts_receivable.py +++ b/erpnext/accounts/report/accounts_receivable/accounts_receivable.py @@ -529,9 +529,7 @@ def get_payment_terms(self, row): self.append_payment_term(row, d, term) def append_payment_term(self, row, d, term): - if ( - self.filters.get("customer") or self.filters.get("supplier") - ) and d.currency == d.party_account_currency: + if d.currency == d.party_account_currency: invoiced = d.payment_amount else: invoiced = d.base_payment_amount From 4a261b5cef5062f3472634f1e6c92202cd6a0083 Mon Sep 17 00:00:00 2001 From: Smit Vora Date: Wed, 11 Dec 2024 17:57:47 +0530 Subject: [PATCH 05/12] fix: better indicator base amount for Tax Witholding in Journal Entry (cherry picked from commit 56a0a0db18fb16ce4a30a92a0fc271351def3894) --- .../report/tds_payable_monthly/tds_payable_monthly.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py b/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py index 465c300a8efe..03a5259b96f4 100644 --- a/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py +++ b/erpnext/accounts/report/tds_payable_monthly/tds_payable_monthly.py @@ -72,8 +72,8 @@ def get_result(filters, tds_docs, tds_accounts, tax_category_map, journal_entry_ if net_total_map.get((voucher_type, name)): if voucher_type == "Journal Entry" and tax_amount and rate: # back calcalute total amount from rate and tax_amount - if rate: - total_amount = grand_total = base_total = tax_amount / (rate / 100) + base_total = min(tax_amount / (rate / 100), net_total_map.get((voucher_type, name))[0]) + total_amount = grand_total = base_total elif voucher_type == "Purchase Invoice": total_amount, grand_total, base_total, bill_no, bill_date = net_total_map.get( (voucher_type, name) @@ -405,7 +405,7 @@ def get_doc_info(vouchers, doctype, tax_category_map, net_total_map=None): "paid_amount_after_tax", "base_paid_amount", ], - "Journal Entry": ["total_amount"], + "Journal Entry": ["total_debit"], } entries = frappe.get_all( @@ -427,7 +427,7 @@ def get_doc_info(vouchers, doctype, tax_category_map, net_total_map=None): elif doctype == "Payment Entry": value = [entry.paid_amount, entry.paid_amount_after_tax, entry.base_paid_amount] else: - value = [entry.total_amount] * 3 + value = [entry.total_debit] * 3 net_total_map[(doctype, entry.name)] = value From 744f3457de4c947e11a6137c3b55f66840555fee Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:48:59 +0530 Subject: [PATCH 06/12] fix: purchase return entry issue (backport #44721) (#44736) fix: purchase return entry issue (#44721) (cherry picked from commit 1f5d7072e7644aead90743e8316097bf1d0d4afb) Co-authored-by: rohitwaghchaure --- .../controllers/sales_and_purchase_return.py | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py index c26644c870b5..f661cc33c63b 100644 --- a/erpnext/controllers/sales_and_purchase_return.py +++ b/erpnext/controllers/sales_and_purchase_return.py @@ -71,16 +71,13 @@ def validate_returned_items(doc): valid_items = frappe._dict() - select_fields = "item_code, qty, stock_qty, rate, parenttype, conversion_factor" + select_fields = "item_code, qty, stock_qty, rate, parenttype, conversion_factor, name" if doc.doctype != "Purchase Invoice": select_fields += ",serial_no, batch_no" if doc.doctype in ["Purchase Invoice", "Purchase Receipt", "Subcontracting Receipt"]: select_fields += ",rejected_qty, received_qty" - if doc.doctype in ["Purchase Receipt", "Purchase Invoice"]: - select_fields += ",name" - for d in frappe.db.sql( f"""select {select_fields} from `tab{doc.doctype} Item` where parent = %s""", doc.return_against, @@ -108,11 +105,13 @@ def validate_returned_items(doc): for d in doc.get("items"): key = d.item_code raise_exception = False - if doc.doctype in ["Purchase Receipt", "Purchase Invoice"]: + if doc.doctype in ["Purchase Receipt", "Purchase Invoice", "Sales Invoice"]: field = frappe.scrub(doc.doctype) + "_item" if d.get(field): key = (d.item_code, d.get(field)) raise_exception = True + elif doc.doctype == "Delivery Note": + key = (d.item_code, d.get("dn_detail")) if d.item_code and (flt(d.qty) < 0 or flt(d.get("received_qty")) < 0): if key not in valid_items: @@ -124,7 +123,7 @@ def validate_returned_items(doc): ) else: ref = valid_items.get(key, frappe._dict()) - validate_quantity(doc, d, ref, valid_items, already_returned_items) + validate_quantity(doc, key, d, ref, valid_items, already_returned_items) if ( ref.rate @@ -174,12 +173,12 @@ def validate_returned_items(doc): frappe.throw(_("Atleast one item should be entered with negative quantity in return document")) -def validate_quantity(doc, args, ref, valid_items, already_returned_items): +def validate_quantity(doc, key, args, ref, valid_items, already_returned_items): fields = ["stock_qty"] if doc.doctype in ["Purchase Receipt", "Purchase Invoice", "Subcontracting Receipt"]: fields.extend(["received_qty", "rejected_qty"]) - already_returned_data = already_returned_items.get(args.item_code) or {} + already_returned_data = already_returned_items.get(key) or {} company_currency = erpnext.get_company_currency(doc.company) stock_qty_precision = get_field_precision( @@ -262,15 +261,20 @@ def get_already_returned_items(doc): column += """, sum(abs(child.rejected_qty) * child.conversion_factor) as rejected_qty, sum(abs(child.received_qty) * child.conversion_factor) as received_qty""" + field = ( + frappe.scrub(doc.doctype) + "_item" + if doc.doctype in ["Purchase Invoice", "Purchase Receipt", "Sales Invoice"] + else "dn_detail" + ) data = frappe.db.sql( f""" - select {column} + select {column}, {field} from `tab{doc.doctype} Item` child, `tab{doc.doctype}` par where child.parent = par.name and par.docstatus = 1 and par.is_return = 1 and par.return_against = %s - group by item_code + group by item_code, {field} """, doc.return_against, as_dict=1, @@ -280,7 +284,7 @@ def get_already_returned_items(doc): for d in data: items.setdefault( - d.item_code, + (d.item_code, d.get(field)), frappe._dict( { "qty": d.get("qty"), From c86174d0f2bfa3171ea9f56c4c7f4bfed9611a36 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 17 Dec 2024 14:48:15 +0530 Subject: [PATCH 07/12] fix: broken CI - pin ubuntu-22.04 --- .github/workflows/patch.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/patch.yml b/.github/workflows/patch.yml index d6a03af535f5..c39b4be9acba 100644 --- a/.github/workflows/patch.yml +++ b/.github/workflows/patch.yml @@ -16,7 +16,7 @@ concurrency: jobs: test: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 timeout-minutes: 60 name: Patch Test From 2d12f2cebd1ee9f8f4a520e3ba208939f35fe202 Mon Sep 17 00:00:00 2001 From: venkat102 Date: Fri, 13 Dec 2024 11:22:17 +0530 Subject: [PATCH 08/12] fix: set company bank account if default account not set in mode of payment (cherry picked from commit 91c7e3d5f3168736f40973816594a57e36d0f625) --- .../doctype/payment_entry/payment_entry.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 5da1c0d35d96..f4819aaea594 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -1088,6 +1088,24 @@ frappe.ui.form.on('Payment Entry', { if (r.message) { if (!frm.doc.mode_of_payment) { frm.set_value(field, r.message.account); + } else { + frappe.call({ + method: "frappe.client.get_value", + args: { + doctype: "Mode of Payment Account", + filters: { + parent: frm.doc.mode_of_payment, + company: frm.doc.company, + }, + fieldname: "default_account", + parent: "Mode of Payment", + }, + callback: function (res) { + if (!res.message.default_account) { + frm.set_value(field, r.message.account); + } + }, + }); } frm.set_value('bank', r.message.bank); frm.set_value('bank_account_no', r.message.bank_account_no); From 0688c0ab6b2f7c92d4ca282835aa7b97cb8ad1e8 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 17 Dec 2024 17:40:32 +0530 Subject: [PATCH 09/12] fix: allow all dispatch address for drop ship invoice --- erpnext/public/js/queries.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/public/js/queries.js b/erpnext/public/js/queries.js index f014e6303ff2..14d07230d0da 100644 --- a/erpnext/public/js/queries.js +++ b/erpnext/public/js/queries.js @@ -107,9 +107,12 @@ $.extend(erpnext.queries, { }, dispatch_address_query: function (doc) { + var filters = { link_doctype: "Company", link_name: doc.company || "" }; + var is_drop_ship = doc.items.some((item) => item.delivered_by_supplier); + if (is_drop_ship) filters = {}; return { query: "frappe.contacts.doctype.address.address.address_query", - filters: { link_doctype: "Company", link_name: doc.company || "" }, + filters: filters, }; }, From 8a9c457d372a08e49d51e24863083f83d20d3b8a Mon Sep 17 00:00:00 2001 From: ljain112 Date: Fri, 13 Dec 2024 13:46:15 +0530 Subject: [PATCH 10/12] fix: User permissions in financial statements (cherry picked from commit a626372d660a061de4594f92efaeac0a45d4bd57) --- erpnext/accounts/report/financial_statements.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 16886cd939a4..4c376effc2af 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -526,7 +526,16 @@ def get_accounting_entries( query = apply_additional_conditions(doctype, query, from_date, ignore_closing_entries, filters) query = query.where(gl_entry.account.isin(accounts)) - entries = query.run(as_dict=True) + query = query.get_sql() + + from frappe.desk.reportview import build_match_conditions + + match_conditions = build_match_conditions(doctype) + + if match_conditions: + query += "and" + match_conditions + + entries = frappe.db.sql(query, as_dict=True) return entries From 3a7e335d4b616f72aceebaf96216c1631be4e57a Mon Sep 17 00:00:00 2001 From: ljain112 Date: Tue, 17 Dec 2024 18:49:38 +0530 Subject: [PATCH 11/12] fix: using query.walk() for escaping (cherry picked from commit 5ea131c763633e1c93abddcbcd551d6d10df7336) --- erpnext/accounts/report/financial_statements.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index 4c376effc2af..cd0f7e90e04e 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -526,8 +526,6 @@ def get_accounting_entries( query = apply_additional_conditions(doctype, query, from_date, ignore_closing_entries, filters) query = query.where(gl_entry.account.isin(accounts)) - query = query.get_sql() - from frappe.desk.reportview import build_match_conditions match_conditions = build_match_conditions(doctype) @@ -535,9 +533,9 @@ def get_accounting_entries( if match_conditions: query += "and" + match_conditions - entries = frappe.db.sql(query, as_dict=True) + query, params = query.walk() - return entries + return frappe.db.sql(query, params, as_dict=True) def apply_additional_conditions(doctype, query, from_date, ignore_closing_entries, filters): From 0a7832d8d38e3e47bebd3ec53e2cd180eb357460 Mon Sep 17 00:00:00 2001 From: venkat102 Date: Sun, 15 Dec 2024 22:55:24 +0530 Subject: [PATCH 12/12] fix: update discount when pricing rule is changed (cherry picked from commit 8338d1d5b45dc20049130d96546fad002a64ba99) --- erpnext/accounts/doctype/pricing_rule/pricing_rule.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py index 902af5c2a772..2f8332377630 100644 --- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py +++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py @@ -328,6 +328,8 @@ def get_pricing_rule_for_item(args, doc=None, for_validate=False): "parent": args.parent, "parenttype": args.parenttype, "child_docname": args.get("child_docname"), + "discount_percentage": 0.0, + "discount_amount": 0, } )