Skip to content

Commit

Permalink
Merge pull request frappe#40519 from nabinhait/provisional-entry-fix
Browse files Browse the repository at this point in the history
fix: provisional entry for non-stock item
  • Loading branch information
nabinhait authored Mar 19, 2024
2 parents 64f1844 + 39d958c commit 419f2a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
11 changes: 7 additions & 4 deletions erpnext/accounts/doctype/gl_entry/gl_entry.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
"fieldname": "voucher_detail_no",
"fieldtype": "Data",
"label": "Voucher Detail No",
"read_only": 1
"read_only": 1,
"search_index": 1
},
{
"fieldname": "project",
Expand Down Expand Up @@ -256,7 +257,8 @@
"icon": "fa fa-list",
"idx": 1,
"in_create": 1,
"modified": "2020-04-07 16:22:33.766994",
"links": [],
"modified": "2024-03-19 18:30:49.613401",
"modified_by": "Administrator",
"module": "Accounts",
"name": "GL Entry",
Expand Down Expand Up @@ -288,5 +290,6 @@
"quick_entry": 1,
"search_fields": "voucher_no,account,posting_date,against_voucher",
"sort_field": "modified",
"sort_order": "DESC"
}
"sort_order": "DESC",
"states": []
}
48 changes: 23 additions & 25 deletions erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,6 @@ def make_item_gl_entries(self, gl_entries):
"Company", self.company, "enable_provisional_accounting_for_non_stock_items"
)
)
self.provisional_enpenses_booked_in_pr = False
if provisional_accounting_for_non_stock_items:
self.get_provisional_accounts()

Expand Down Expand Up @@ -982,47 +981,46 @@ def get_provisional_accounts(self):
fields=["name", "provisional_expense_account", "qty", "base_rate"],
)
default_provisional_account = self.get_company_default("default_provisional_account")
provisional_accounts = set(
[
d.provisional_expense_account if d.provisional_expense_account else default_provisional_account
for d in pr_items
]
)

provisional_gl_entries = frappe.get_all(
"GL Entry",
filters={
"voucher_type": "Purchase Receipt",
"voucher_no": ("in", linked_purchase_receipts),
"account": ("in", provisional_accounts),
"is_cancelled": 0,
},
fields=["voucher_detail_no"],
)
rows_with_provisional_entries = [d.voucher_detail_no for d in provisional_gl_entries]
for item in pr_items:
self.provisional_accounts[item.name] = {
"provisional_account": item.provisional_expense_account or default_provisional_account,
"qty": item.qty,
"base_rate": item.base_rate,
"has_provisional_entry": item.name in rows_with_provisional_entries,
}

def make_provisional_gl_entry(self, gl_entries, item):
if item.purchase_receipt:
if not self.provisional_enpenses_booked_in_pr:
pr_item = self.provisional_accounts.get(item.pr_detail, {})
provisional_account = pr_item.get("provisional_account")
pr_qty = pr_item.get("qty")
pr_base_rate = pr_item.get("base_rate")

# Post reverse entry for Stock-Received-But-Not-Billed if it is booked in Purchase Receipt
provision_gle_against_pr = frappe.db.get_value(
"GL Entry",
{
"is_cancelled": 0,
"voucher_type": "Purchase Receipt",
"voucher_no": item.purchase_receipt,
"voucher_detail_no": item.pr_detail,
"account": provisional_account,
},
["name"],
)
if provision_gle_against_pr:
self.provisional_enpenses_booked_in_pr = True

if self.provisional_enpenses_booked_in_pr:
pr_item = self.provisional_accounts.get(item.pr_detail, {})
if pr_item.get("has_provisional_entry"):
purchase_receipt_doc = frappe.get_cached_doc("Purchase Receipt", item.purchase_receipt)

# Intentionally passing purchase invoice item to handle partial billing
purchase_receipt_doc.add_provisional_gl_entry(
item,
gl_entries,
self.posting_date,
provisional_account,
pr_item.get("provisional_account"),
reverse=1,
item_amount=(min(item.qty, pr_qty) * pr_base_rate),
item_amount=(min(item.qty, pr_item.get("qty")) * pr_item.get("base_rate")),
)

def update_gross_purchase_amount_for_linked_assets(self, item):
Expand Down

0 comments on commit 419f2a5

Please sign in to comment.