Skip to content

Commit

Permalink
fix: handle partial invoice against provisional entry
Browse files Browse the repository at this point in the history
(cherry picked from commit 2a46799)
  • Loading branch information
GursheenK authored and mergify[bot] committed Feb 29, 2024
1 parent 0182b95 commit 87596e6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1023,17 +1023,20 @@ def make_item_gl_entries(self, gl_entries):

if provisional_accounting_for_non_stock_items:
if item.purchase_receipt:
provisional_account = frappe.db.get_value(
"Purchase Receipt Item", item.pr_detail, "provisional_expense_account"
) or self.get_company_default("default_provisional_account")
provisional_account, pr_base_rate = frappe.get_cached_value(
"Purchase Receipt Item", item.pr_detail, ["provisional_expense_account", "base_rate"]
)
provisional_account = provisional_account or self.get_company_default(
"default_provisional_account"
)
purchase_receipt_doc = purchase_receipt_doc_map.get(item.purchase_receipt)

if not purchase_receipt_doc:
purchase_receipt_doc = frappe.get_doc("Purchase Receipt", item.purchase_receipt)
purchase_receipt_doc_map[item.purchase_receipt] = purchase_receipt_doc

# Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt
expense_booked_in_pr, credit = frappe.db.get_value(
expense_booked_in_pr = frappe.db.get_value(
"GL Entry",
{
"is_cancelled": 0,
Expand All @@ -1042,13 +1045,18 @@ def make_item_gl_entries(self, gl_entries):
"voucher_detail_no": item.pr_detail,
"account": provisional_account,
},
["name", "credit"],
"name",
)

if expense_booked_in_pr:
# Intentionally passing purchase invoice item to handle partial billing
purchase_receipt_doc.add_provisional_gl_entry(
item, gl_entries, self.posting_date, provisional_account, reverse=1, item_amount=credit
item,
gl_entries,
self.posting_date,
provisional_account,
reverse=1,
item_amount=(item.qty * pr_base_rate),
)

if not self.is_internal_transfer():
Expand Down

0 comments on commit 87596e6

Please sign in to comment.