fix: Code cleanup
This commit is contained in:
parent
b4b6c8e262
commit
cf7af62b05
@ -517,7 +517,7 @@ class PurchaseInvoice(BuyingController):
|
||||
if d.category in ('Valuation', 'Total and Valuation')
|
||||
and flt(d.base_tax_amount_after_discount_amount)]
|
||||
|
||||
exchange_rate_map, net_rate_map = get_pr_or_pi_details(self)
|
||||
exchange_rate_map, net_rate_map = get_purchase_document_details(self)
|
||||
|
||||
for item in self.get("items"):
|
||||
if flt(item.base_net_amount):
|
||||
@ -640,7 +640,7 @@ class PurchaseInvoice(BuyingController):
|
||||
if item.get('purchase_receipt'):
|
||||
if exchange_rate_map[item.purchase_receipt] and \
|
||||
self.conversion_rate != exchange_rate_map[item.purchase_receipt] and \
|
||||
item.net_rate == net_rate_map[item.item_code]:
|
||||
item.net_rate == net_rate_map[item.pr_detail]:
|
||||
|
||||
discrepancy_caused_by_exchange_rate_difference = (item.qty * item.net_rate) * \
|
||||
(exchange_rate_map[item.purchase_receipt] - self.conversion_rate)
|
||||
@ -1172,32 +1172,32 @@ class PurchaseInvoice(BuyingController):
|
||||
self.db_set('status', self.status, update_modified = update_modified)
|
||||
|
||||
# to get details of purchase invoice/receipt from which this doc was created for exchange rate difference handling
|
||||
def get_pr_or_pi_details(doc):
|
||||
def get_purchase_document_details(doc):
|
||||
if doc.doctype == 'Purchase Invoice':
|
||||
pr_or_pi = 'purchase_receipt'
|
||||
doc_reference = 'purchase_receipt'
|
||||
items_reference = 'pr_detail'
|
||||
pr_or_pi_doctype = 'Purchase Receipt'
|
||||
pr_or_pi_items_table = 'Purchase Receipt Item'
|
||||
parent_doctype = 'Purchase Receipt'
|
||||
child_doctype = 'Purchase Receipt Item'
|
||||
else:
|
||||
pr_or_pi = 'purchase_invoice'
|
||||
doc_reference = 'purchase_invoice'
|
||||
items_reference = 'purchase_invoice_item'
|
||||
pr_or_pi_doctype = 'Purchase Invoice'
|
||||
pr_or_pi_items_table = 'Purchase Invoice Item'
|
||||
parent_doctype = 'Purchase Invoice'
|
||||
child_doctype = 'Purchase Invoice Item'
|
||||
|
||||
purchase_receipts_or_invoices = []
|
||||
pr_or_pi_items = []
|
||||
items = []
|
||||
|
||||
for item in doc.get('items'):
|
||||
if item.get(pr_or_pi):
|
||||
purchase_receipts_or_invoices.append(item.get(pr_or_pi))
|
||||
if item.get(doc_reference):
|
||||
purchase_receipts_or_invoices.append(item.get(doc_reference))
|
||||
if item.get(items_reference):
|
||||
pr_or_pi_items.append(item.get(items_reference))
|
||||
items.append(item.get(items_reference))
|
||||
|
||||
exchange_rate_map = frappe._dict(frappe.get_all(pr_or_pi_doctype, filters={'name': ('in',
|
||||
exchange_rate_map = frappe._dict(frappe.get_all(parent_doctype, filters={'name': ('in',
|
||||
purchase_receipts_or_invoices)}, fields=['name', 'conversion_rate'], as_list=1))
|
||||
|
||||
net_rate_map = frappe._dict(frappe.get_all(pr_or_pi_items_table, filters={'name': ('in',
|
||||
pr_or_pi_items)}, fields=['item_code', 'net_rate'], as_list=1))
|
||||
net_rate_map = frappe._dict(frappe.get_all(child_doctype, filters={'name': ('in',
|
||||
items)}, fields=['name', 'net_rate'], as_list=1))
|
||||
|
||||
return exchange_rate_map, net_rate_map
|
||||
|
||||
|
@ -231,12 +231,11 @@ class TestPurchaseInvoice(unittest.TestCase):
|
||||
self.assertEqual(expected_values[gle.account][2], gle.credit)
|
||||
|
||||
def test_purchase_invoice_with_exchange_rate_difference(self):
|
||||
set_gst_settings()
|
||||
pr = make_purchase_receipt(currency = "USD", conversion_rate = 70)
|
||||
pi = make_purchase_invoice(currency = "USD", conversion_rate = 80, do_not_save = "True")
|
||||
|
||||
for item in pi.items:
|
||||
item.purchase_receipt = pr.name
|
||||
pi.items[0].purchase_receipt = pr.name
|
||||
pi.items[0].pr_detail = pr.items[0].name
|
||||
|
||||
pi.insert()
|
||||
pi.submit()
|
||||
@ -1072,24 +1071,6 @@ def update_tax_witholding_category(company, account, date):
|
||||
'account': account
|
||||
})
|
||||
tds_category.save()
|
||||
def set_gst_settings():
|
||||
gst_settings = frappe.get_doc("GST Settings")
|
||||
|
||||
gst_account = frappe.get_all(
|
||||
"GST Account",
|
||||
fields=["cgst_account", "sgst_account", "igst_account"],
|
||||
filters = {"company": "_Test Company"}
|
||||
)
|
||||
|
||||
if not gst_account:
|
||||
gst_settings.append("gst_accounts", {
|
||||
"company": "_Test Company",
|
||||
"cgst_account": "CGST - _TC",
|
||||
"sgst_account": "SGST - _TC",
|
||||
"igst_account": "IGST - _TC",
|
||||
})
|
||||
|
||||
gst_settings.save()
|
||||
|
||||
def unlink_payment_on_cancel_of_invoice(enable=1):
|
||||
accounts_settings = frappe.get_doc("Accounts Settings")
|
||||
|
@ -254,7 +254,7 @@ class PurchaseReceipt(BuyingController):
|
||||
return process_gl_map(gl_entries)
|
||||
|
||||
def make_item_gl_entries(self, gl_entries, warehouse_account=None):
|
||||
from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import get_pr_or_pi_details
|
||||
from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import get_purchase_document_details
|
||||
|
||||
stock_rbnb = self.get_company_default("stock_received_but_not_billed")
|
||||
landed_cost_entries = get_item_account_wise_additional_cost(self.name)
|
||||
@ -264,7 +264,7 @@ class PurchaseReceipt(BuyingController):
|
||||
warehouse_with_no_account = []
|
||||
stock_items = self.get_stock_items()
|
||||
|
||||
exchange_rate_map, net_rate_map = get_pr_or_pi_details(self)
|
||||
exchange_rate_map, net_rate_map = get_purchase_document_details(self)
|
||||
|
||||
for d in self.get("items"):
|
||||
if d.item_code in stock_items and flt(d.valuation_rate) and flt(d.qty):
|
||||
@ -312,7 +312,7 @@ class PurchaseReceipt(BuyingController):
|
||||
if d.get('purchase_invoice'):
|
||||
if exchange_rate_map[d.purchase_invoice] and \
|
||||
self.conversion_rate != exchange_rate_map[d.purchase_invoice] and \
|
||||
d.net_rate == net_rate_map[d.item_code]:
|
||||
d.net_rate == net_rate_map[d.purchase_invoice_item]:
|
||||
|
||||
discrepancy_caused_by_exchange_rate_difference = (d.qty * d.net_rate) * \
|
||||
(exchange_rate_map[d.purchase_invoice] - self.conversion_rate)
|
||||
|
@ -1051,6 +1051,7 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
self.assertEqual(len(item_two_gl_entry), 1)
|
||||
|
||||
frappe.db.set_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items', before_test_value)
|
||||
|
||||
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
|
||||
|
||||
@ -1058,22 +1059,26 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
|
||||
create_warehouse("_Test Warehouse for Valuation", company="_Test Company with perpetual inventory",
|
||||
properties={"account": '_Test Account Stock In Hand - TCP1'})
|
||||
|
||||
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")
|
||||
|
||||
for item in pr.items:
|
||||
item.purchase_invoice = pi.name
|
||||
pr.items[0].purchase_invoice = pi.name
|
||||
pr.items[0].purchase_invoice_item = pi.items[0].name
|
||||
|
||||
pr.insert()
|
||||
pr.submit()
|
||||
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')
|
||||
|
||||
voucher_no = frappe.get_value('GL Entry', gl_entries[0]['name'], 'voucher_no')
|
||||
self.assertEqual(pr.name, voucher_no)
|
||||
|
||||
exchange_gain_loss_amount = frappe.get_value('GL Entry', gl_entries[0]['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)
|
||||
|
||||
def get_sl_entries(voucher_type, voucher_no):
|
||||
return frappe.db.sql(""" select actual_qty, warehouse, stock_value_difference
|
||||
from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s
|
||||
|
Loading…
x
Reference in New Issue
Block a user