Browse Source

fix: Create common function for fetching conversion rate details of linked docs

develop
GangaManoj 3 years ago
parent
commit
d748e7f49c
  1. 50
      erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
  2. 26
      erpnext/stock/doctype/purchase_receipt/purchase_receipt.py

50
erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py

@ -517,7 +517,7 @@ class PurchaseInvoice(BuyingController):
if d.category in ('Valuation', 'Total and Valuation') if d.category in ('Valuation', 'Total and Valuation')
and flt(d.base_tax_amount_after_discount_amount)] and flt(d.base_tax_amount_after_discount_amount)]
exchange_rate_map, net_rate_map = self.get_purchase_receipt_details() exchange_rate_map, net_rate_map = get_pr_or_pi_details(self)
for item in self.get("items"): for item in self.get("items"):
if flt(item.base_net_amount): if flt(item.base_net_amount):
@ -717,24 +717,6 @@ class PurchaseInvoice(BuyingController):
self.negative_expense_to_be_booked += flt(item.item_tax_amount, \ self.negative_expense_to_be_booked += flt(item.item_tax_amount, \
item.precision("item_tax_amount")) item.precision("item_tax_amount"))
def get_purchase_receipt_details(self):
purchase_receipts = []
pr_items = []
for item in self.get('items'):
if item.get('purchase_receipt'):
purchase_receipts.append(item.purchase_receipt)
if item.get('pr_detail'):
pr_items.append(item.pr_detail)
exchange_rate_map = frappe._dict(frappe.get_all('Purchase Receipt', filters={'name': ('in',
purchase_receipts)}, fields=['name', 'conversion_rate'], as_list=1))
net_rate_map = frappe._dict(frappe.get_all('Purchase Receipt Item', filters={'name': ('in',
pr_items)}, fields=['item_code', 'net_rate'], as_list=1))
return exchange_rate_map, net_rate_map
def get_asset_gl_entry(self, gl_entries): def get_asset_gl_entry(self, gl_entries):
arbnb_account = self.get_company_default("asset_received_but_not_billed") arbnb_account = self.get_company_default("asset_received_but_not_billed")
eiiav_account = self.get_company_default("expenses_included_in_asset_valuation") eiiav_account = self.get_company_default("expenses_included_in_asset_valuation")
@ -1189,6 +1171,36 @@ class PurchaseInvoice(BuyingController):
if update: if update:
self.db_set('status', self.status, update_modified = update_modified) 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):
if doc.doctype == 'Purchase Invoice':
pr_or_pi = 'purchase_receipt'
items_reference = 'pr_detail'
pr_or_pi_doctype = 'Purchase Receipt'
pr_or_pi_items_table = 'Purchase Receipt Item'
else:
pr_or_pi = 'purchase_invoice'
items_reference = 'purchase_invoice_item'
pr_or_pi_doctype = 'Purchase Invoice'
pr_or_pi_items_table = 'Purchase Invoice Item'
purchase_receipts_or_invoices = []
pr_or_pi_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(items_reference):
pr_or_pi_items.append(item.get(items_reference))
exchange_rate_map = frappe._dict(frappe.get_all(pr_or_pi_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))
return exchange_rate_map, net_rate_map
def get_list_context(context=None): def get_list_context(context=None):
from erpnext.controllers.website_list_for_contact import get_list_context from erpnext.controllers.website_list_for_contact import get_list_context
list_context = get_list_context(context) list_context = get_list_context(context)

26
erpnext/stock/doctype/purchase_receipt/purchase_receipt.py

@ -254,6 +254,8 @@ class PurchaseReceipt(BuyingController):
return process_gl_map(gl_entries) return process_gl_map(gl_entries)
def make_item_gl_entries(self, gl_entries, warehouse_account=None): 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
stock_rbnb = self.get_company_default("stock_received_but_not_billed") stock_rbnb = self.get_company_default("stock_received_but_not_billed")
landed_cost_entries = get_item_account_wise_additional_cost(self.name) landed_cost_entries = get_item_account_wise_additional_cost(self.name)
expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation") expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")
@ -262,7 +264,7 @@ class PurchaseReceipt(BuyingController):
warehouse_with_no_account = [] warehouse_with_no_account = []
stock_items = self.get_stock_items() stock_items = self.get_stock_items()
exchange_rate_map, net_rate_map = self.get_purchase_invoice_details() exchange_rate_map, net_rate_map = get_pr_or_pi_details(self)
for d in self.get("items"): for d in self.get("items"):
if d.item_code in stock_items and flt(d.valuation_rate) and flt(d.qty): if d.item_code in stock_items and flt(d.valuation_rate) and flt(d.qty):
@ -501,28 +503,6 @@ class PurchaseReceipt(BuyingController):
self.add_gl_entry(gl_entries, asset_account, item.cost_center, 0.0, flt(item.landed_cost_voucher_amount), self.add_gl_entry(gl_entries, asset_account, item.cost_center, 0.0, flt(item.landed_cost_voucher_amount),
remarks, expenses_included_in_asset_valuation, project=item.project, item=item) remarks, expenses_included_in_asset_valuation, project=item.project, item=item)
def get_purchase_invoice_details(self):
purchase_invoices = []
pi_items = []
for item in self.get('items'):
if item.get('purchase_invoice'):
purchase_invoices.append(item.purchase_invoice)
if item.get('purchase_invoice_item'):
pi_items.append(item.purchase_invoice_item)
exchange_rate_map = frappe._dict(frappe.get_all('Purchase Invoice', filters={'name': ('in',
purchase_invoices)}, fields=['name', 'conversion_rate'], as_list=1))
print("*"*50)
print("In get_purchase_invoice_details:")
print("exchange_rate_map: ", exchange_rate_map)
net_rate_map = frappe._dict(frappe.get_all('Purchase Invoice Item', filters={'name': ('in',
pi_items)}, fields=['item_code', 'net_rate'], as_list=1))
print("net_rate_map: ", net_rate_map)
return exchange_rate_map, net_rate_map
def update_assets(self, item, valuation_rate): def update_assets(self, item, valuation_rate):
assets = frappe.db.get_all('Asset', assets = frappe.db.get_all('Asset',
filters={ 'purchase_receipt': self.name, 'item_code': item.item_code } filters={ 'purchase_receipt': self.name, 'item_code': item.item_code }

Loading…
Cancel
Save