From 802e63a9d77af37abb29c8a28e093d0a08a89612 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 28 Jun 2021 11:24:32 +0530 Subject: [PATCH 1/9] fix: Do not consider cancelled entries in party dashboard --- erpnext/accounts/party.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index e025fc6905..b97dc401e6 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -542,6 +542,7 @@ def get_dashboard_info(party_type, party, loyalty_program=None): select company, sum(debit_in_account_currency) - sum(credit_in_account_currency) from `tabGL Entry` where party_type = %s and party=%s + and is_cancelled = 0 group by company""", (party_type, party))) for d in companies: From 5069095984270bd7599fce078444557489523e84 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Thu, 1 Jul 2021 09:31:31 +0530 Subject: [PATCH 2/9] fix: Auto process deferred accounting for multi-company setup --- erpnext/accounts/deferred_revenue.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/deferred_revenue.py b/erpnext/accounts/deferred_revenue.py index 2f86c6c1de..335e8a15ab 100644 --- a/erpnext/accounts/deferred_revenue.py +++ b/erpnext/accounts/deferred_revenue.py @@ -301,17 +301,21 @@ def process_deferred_accounting(posting_date=None): start_date = add_months(today(), -1) end_date = add_days(today(), -1) - for record_type in ('Income', 'Expense'): - doc = frappe.get_doc(dict( - doctype='Process Deferred Accounting', - posting_date=posting_date, - start_date=start_date, - end_date=end_date, - type=record_type - )) + companies = frappe.get_all('Company') - doc.insert() - doc.submit() + for company in companies: + for record_type in ('Income', 'Expense'): + doc = frappe.get_doc(dict( + doctype='Process Deferred Accounting', + company=company.name, + posting_date=posting_date, + start_date=start_date, + end_date=end_date, + type=record_type + )) + + doc.insert() + doc.submit() def make_gl_entries(doc, credit_account, debit_account, against, amount, base_amount, posting_date, project, account_currency, cost_center, item, deferred_process=None): From 8c1b764a90ed543df6d350e1184128354f5f6311 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 5 Jul 2021 21:49:10 +0530 Subject: [PATCH 3/9] fix: Debug tests --- .../doctype/purchase_invoice/test_purchase_invoice.py | 1 + .../test_service_level_agreement.py | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index ec93314c0f..2ce65c13bf 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -1042,6 +1042,7 @@ class TestPurchaseInvoice(unittest.TestCase): where voucher_type='Purchase Invoice' and voucher_no=%s order by account asc""", (purchase_invoice.name), as_dict=1) + print(gl_entries) for i, gle in enumerate(gl_entries): self.assertEqual(expected_gle[i][0], gle.account) self.assertEqual(expected_gle[i][1], gle.debit) diff --git a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py index 2a8446d29f..4ef4930659 100644 --- a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py +++ b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py @@ -81,6 +81,7 @@ class TestServiceLevelAgreement(unittest.TestCase): # check SLA custom fields created for leads sla_fields = get_service_level_agreement_fields() + frappe.clear_cache(doctype=doctype) meta = frappe.get_meta(doctype, cached=False) for field in sla_fields: @@ -219,9 +220,9 @@ class TestServiceLevelAgreement(unittest.TestCase): lead.reload() self.assertEqual(lead.agreement_status, 'Fulfilled') - def tearDown(self): - for d in frappe.get_all("Service Level Agreement"): - frappe.delete_doc("Service Level Agreement", d.name, force=1) + # def tearDown(self): + # for d in frappe.get_all("Service Level Agreement"): + # frappe.delete_doc("Service Level Agreement", d.name, force=1) def get_service_level_agreement(default_service_level_agreement=None, entity_type=None, entity=None, doctype="Issue"): From c21d3d486597a3a88a98fb34c8616bb6117a6499 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 5 Jul 2021 22:47:59 +0530 Subject: [PATCH 4/9] fix: Debug tests --- .../service_level_agreement/test_service_level_agreement.py | 1 + 1 file changed, 1 insertion(+) diff --git a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py index 4ef4930659..61666f142a 100644 --- a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py +++ b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py @@ -103,6 +103,7 @@ class TestServiceLevelAgreement(unittest.TestCase): # check SLA docfields created sla_fields = get_service_level_agreement_fields() + frappe.clear_cache(doctype=doctype) meta = frappe.get_meta(doctype.name, cached=False) for field in sla_fields: From 32436eceda9d976692aa6a48f75738d77a00af9a Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Mon, 5 Jul 2021 23:34:09 +0530 Subject: [PATCH 5/9] fix: Debug tests --- .../service_level_agreement/test_service_level_agreement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py index 61666f142a..e5076193e2 100644 --- a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py +++ b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py @@ -103,7 +103,7 @@ class TestServiceLevelAgreement(unittest.TestCase): # check SLA docfields created sla_fields = get_service_level_agreement_fields() - frappe.clear_cache(doctype=doctype) + frappe.clear_cache(doctype=doctype.doctype) meta = frappe.get_meta(doctype.name, cached=False) for field in sla_fields: From 66c04ca9841a6b30e602a2a29dfd0fa45f3ea3e6 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 6 Jul 2021 10:56:42 +0530 Subject: [PATCH 6/9] fix: Debug tests --- .../service_level_agreement/test_service_level_agreement.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py index e5076193e2..4ef4930659 100644 --- a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py +++ b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py @@ -103,7 +103,6 @@ class TestServiceLevelAgreement(unittest.TestCase): # check SLA docfields created sla_fields = get_service_level_agreement_fields() - frappe.clear_cache(doctype=doctype.doctype) meta = frappe.get_meta(doctype.name, cached=False) for field in sla_fields: From 96eb3be6df20c4d3ac38066ed12e3c1e7d133e3a Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 6 Jul 2021 11:21:44 +0530 Subject: [PATCH 7/9] fix: Debug Tests --- .../service_level_agreement/test_service_level_agreement.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py index 4ef4930659..a5481b1123 100644 --- a/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py +++ b/erpnext/support/doctype/service_level_agreement/test_service_level_agreement.py @@ -220,9 +220,9 @@ class TestServiceLevelAgreement(unittest.TestCase): lead.reload() self.assertEqual(lead.agreement_status, 'Fulfilled') - # def tearDown(self): - # for d in frappe.get_all("Service Level Agreement"): - # frappe.delete_doc("Service Level Agreement", d.name, force=1) + def tearDown(self): + for d in frappe.get_all("Service Level Agreement"): + frappe.delete_doc("Service Level Agreement", d.name, force=1) def get_service_level_agreement(default_service_level_agreement=None, entity_type=None, entity=None, doctype="Issue"): From 8985231a96a967683c3c3d3baad66aedb44757ca Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Tue, 6 Jul 2021 15:34:47 +0530 Subject: [PATCH 8/9] fix: Rewrite tests --- .../purchase_invoice/test_purchase_invoice.py | 37 +++++++++---------- .../purchase_receipt/test_purchase_receipt.py | 32 ++++++++-------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py index 2ce65c13bf..189260a29d 100644 --- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py @@ -231,25 +231,25 @@ class TestPurchaseInvoice(unittest.TestCase): self.assertEqual(expected_values[gle.account][2], gle.credit) def test_purchase_invoice_with_exchange_rate_difference(self): - pr = make_purchase_receipt(currency = "USD", conversion_rate = 70) - pi = make_purchase_invoice(currency = "USD", conversion_rate = 80, do_not_save = "True") + from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice as create_purchase_invoice - pi.items[0].purchase_receipt = pr.name - pi.items[0].pr_detail = pr.items[0].name + pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse='Stores - TCP1', + currency = "USD", conversion_rate = 70) + + pi = create_purchase_invoice(pr.name) + pi.conversion_rate = 80 pi.insert() pi.submit() - # fetching the latest GL Entry with 'Exchange Gain/Loss - _TC' account - gl_entries = frappe.get_all('GL Entry', filters = {'account': 'Exchange Gain/Loss - _TC'}) - voucher_no = frappe.get_value('GL Entry', gl_entries[0]['name'], 'voucher_no') + # Get exchnage gain and loss account + exchange_gain_loss_account = frappe.db.get_value('Company', pi.company, 'exchange_gain_loss_account') - self.assertEqual(pi.name, voucher_no) - - exchange_gain_loss_amount = frappe.get_value('GL Entry', gl_entries[0]['name'], 'debit') + # fetching the latest GL Entry with exchange gain and loss account account + amount = frappe.db.get_value('GL Entry', {'account': exchange_gain_loss_account, 'voucher_no': pi.name}, 'debit') discrepancy_caused_by_exchange_rate_diff = abs(pi.items[0].base_net_amount - pr.items[0].base_net_amount) - self.assertEqual(exchange_gain_loss_amount, discrepancy_caused_by_exchange_rate_diff) + self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount) def test_purchase_invoice_change_naming_series(self): pi = frappe.copy_doc(test_records[1]) @@ -1031,22 +1031,21 @@ class TestPurchaseInvoice(unittest.TestCase): # Check GLE for Purchase Invoice # Zero net effect on final TDS Payable on invoice expected_gle = [ - ['_Test Account Cost for Goods Sold - _TC', 30000, 0], - ['_Test Account Excise Duty - _TC', 0, 3000], - ['Creditors - _TC', 0, 27000], - ['TDS Payable - _TC', 3000, 3000] + ['_Test Account Cost for Goods Sold - _TC', 30000], + ['_Test Account Excise Duty - _TC', -3000], + ['Creditors - _TC', -27000], + ['TDS Payable - _TC', 0] ] - gl_entries = frappe.db.sql("""select account, debit, credit + gl_entries = frappe.db.sql("""select account, sum(debit - credit) as amount from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s + group by account order by account asc""", (purchase_invoice.name), as_dict=1) - print(gl_entries) for i, gle in enumerate(gl_entries): self.assertEqual(expected_gle[i][0], gle.account) - self.assertEqual(expected_gle[i][1], gle.debit) - self.assertEqual(expected_gle[i][2], gle.credit) + self.assertEqual(expected_gle[i][1], gle.amount) def update_tax_witholding_category(company, account, date): from erpnext.accounts.utils import get_fiscal_year diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index d56822a308..dbba21fde1 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -1054,30 +1054,30 @@ class TestPurchaseReceipt(unittest.TestCase): def test_purchase_receipt_with_exchange_rate_difference(self): from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice as create_purchase_invoice - - pi = create_purchase_invoice(currency = "USD", conversion_rate = 70) - - create_warehouse("_Test Warehouse for Valuation", company="_Test Company with perpetual inventory", - properties={"account": '_Test Account Stock In Hand - TCP1'}) + from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import make_purchase_receipt as create_purchase_receipt - pr = make_purchase_receipt(warehouse = '_Test Warehouse for Valuation - TCP1', - company="_Test Company with perpetual inventory", currency = "USD", conversion_rate = 80, - do_not_save = "True") - + pi = create_purchase_invoice(company="_Test Company with perpetual inventory", + cost_center = "Main - TCP1", + warehouse = "Stores - TCP1", + expense_account ="_Test Account Cost for Goods Sold - TCP1", + currency = "USD", conversion_rate = 70) + + pr = create_purchase_receipt(pi.name) + pr.conversion_rate = 80 pr.items[0].purchase_invoice = pi.name pr.items[0].purchase_invoice_item = pi.items[0].name - pr.insert() + pr.save() pr.submit() - # fetching the latest GL Entry with 'Exchange Gain/Loss - TCP1' account - gl_entries = frappe.get_all('GL Entry', filters = {'account': 'Exchange Gain/Loss - TCP1'}) - voucher_no = frappe.get_value('GL Entry', gl_entries[0]['name'], 'voucher_no') - self.assertEqual(pr.name, voucher_no) + # Get exchnage gain and loss account + exchange_gain_loss_account = frappe.db.get_value('Company', pr.company, 'exchange_gain_loss_account') - exchange_gain_loss_amount = frappe.get_value('GL Entry', gl_entries[0]['name'], 'debit') + # fetching the latest GL Entry with exchange gain and loss account account + amount = frappe.db.get_value('GL Entry', {'account': exchange_gain_loss_account, 'voucher_no': pr.name}, 'credit') discrepancy_caused_by_exchange_rate_diff = abs(pi.items[0].base_net_amount - pr.items[0].base_net_amount) - self.assertEqual(exchange_gain_loss_amount, discrepancy_caused_by_exchange_rate_diff) + + self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount) def get_sl_entries(voucher_type, voucher_no): return frappe.db.sql(""" select actual_qty, warehouse, stock_value_difference From 0734901a89d01c4358fa579517a572705a360dc4 Mon Sep 17 00:00:00 2001 From: Noah Jacob Date: Tue, 6 Jul 2021 15:56:10 +0530 Subject: [PATCH 9/9] fix: stock_rbnb not defined (#26345) --- .../stock/doctype/purchase_receipt/purchase_receipt.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 5ba9c7057b..41800e3715 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -291,7 +291,7 @@ class PurchaseReceipt(BuyingController): continue self.add_gl_entry(gl_entries, warehouse_account_name, d.cost_center, stock_value_diff, 0.0, remarks, - stock_rbnb, account_currency=warehouse_account_currency, item=d) + stock_rbnb, account_currency=warehouse_account_currency, item=d) # GL Entry for from warehouse or Stock Received but not billed # Intentionally passed negative debit amount to avoid incorrect GL Entry validation @@ -318,11 +318,11 @@ class PurchaseReceipt(BuyingController): (exchange_rate_map[d.purchase_invoice] - self.conversion_rate) self.add_gl_entry(gl_entries, account, d.cost_center, 0.0, discrepancy_caused_by_exchange_rate_difference, - remarks, self.supplier, debit_in_account_currency=-1 * discrepancy_caused_by_exchange_rate_difference, + remarks, self.supplier, debit_in_account_currency=-1 * discrepancy_caused_by_exchange_rate_difference, account_currency=credit_currency, item=d) - self.add_gl_entry(gl_entries, self.get_company_default("exchange_gain_loss_account"), d.cost_center, discrepancy_caused_by_exchange_rate_difference, 0.0, - remarks, self.supplier, debit_in_account_currency=-1 * discrepancy_caused_by_exchange_rate_difference, + self.add_gl_entry(gl_entries, self.get_company_default("exchange_gain_loss_account"), d.cost_center, discrepancy_caused_by_exchange_rate_difference, 0.0, + remarks, self.supplier, debit_in_account_currency=-1 * discrepancy_caused_by_exchange_rate_difference, account_currency=credit_currency, item=d) # Amount added through landed-cos-voucher @@ -407,6 +407,7 @@ class PurchaseReceipt(BuyingController): against_account = ", ".join([d.account for d in gl_entries if flt(d.debit) > 0]) total_valuation_amount = sum(valuation_tax.values()) amount_including_divisional_loss = negative_expense_to_be_booked + stock_rbnb = self.get_company_default("stock_received_but_not_billed") i = 1 for tax in self.get("taxes"): if valuation_tax.get(tax.name):