mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 04:09:11 +00:00
fix(Purchase Invoice): Fetch Purchase Receipt details using a function
This commit is contained in:
@@ -517,6 +517,8 @@ 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)]
|
||||||
|
|
||||||
|
purchase_receipt_details = self.get_purchase_receipt_details()
|
||||||
|
|
||||||
for item in self.get("items"):
|
for item in self.get("items"):
|
||||||
if flt(item.base_net_amount):
|
if flt(item.base_net_amount):
|
||||||
account_currency = get_account_currency(item.expense_account)
|
account_currency = get_account_currency(item.expense_account)
|
||||||
@@ -634,10 +636,13 @@ class PurchaseInvoice(BuyingController):
|
|||||||
"project": item.project or self.project
|
"project": item.project or self.project
|
||||||
}, account_currency, item=item))
|
}, account_currency, item=item))
|
||||||
|
|
||||||
# check if the exchange rate has changed
|
if purchase_receipt_details[item.item_code]["conversion_rate"] and \
|
||||||
purchase_receipt_conversion_rate = frappe.db.get_value('Purchase Receipt', {'name': item.purchase_receipt}, ['conversion_rate'])
|
self.conversion_rate != purchase_receipt_details[item.item_code]["conversion_rate"] and \
|
||||||
if purchase_receipt_conversion_rate and self.conversion_rate != purchase_receipt_conversion_rate:
|
item.net_rate == purchase_receipt_details[item.item_code]["net_rate"]:
|
||||||
discrepancy_caused_by_exchange_rate_difference = (item.qty * item.rate) * (purchase_receipt_conversion_rate - self.conversion_rate)
|
|
||||||
|
discrepancy_caused_by_exchange_rate_difference = (item.qty * item.net_rate) * \
|
||||||
|
(purchase_receipt_details[item.item_code]["conversion_rate"] - self.conversion_rate)
|
||||||
|
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict({
|
self.get_gl_dict({
|
||||||
"account": expense_account,
|
"account": expense_account,
|
||||||
@@ -710,6 +715,23 @@ 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_receipt_details = {}
|
||||||
|
for item in self.items:
|
||||||
|
if item.purchase_receipt:
|
||||||
|
purchase_receipt = frappe.get_doc('Purchase Receipt', item.purchase_receipt)
|
||||||
|
pr_item_details = {
|
||||||
|
"conversion_rate" : purchase_receipt.conversion_rate
|
||||||
|
}
|
||||||
|
|
||||||
|
for pr_item in purchase_receipt.items:
|
||||||
|
if pr_item.item_code == item.item_code:
|
||||||
|
pr_item_details["net_rate"] = pr_item.net_rate
|
||||||
|
|
||||||
|
purchase_receipt_details[item.item_code] = pr_item_details
|
||||||
|
|
||||||
|
return purchase_receipt_details
|
||||||
|
|
||||||
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")
|
||||||
|
|||||||
Reference in New Issue
Block a user