Skip to content

Commit

Permalink
Merge pull request #40549 from nabinhait/provisional-entry-fix2
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 0725707 + b73f51a commit 1d91e17
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
7 changes: 4 additions & 3 deletions erpnext/accounts/doctype/gl_entry/gl_entry.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,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 @@ -290,7 +291,7 @@
"idx": 1,
"in_create": 1,
"links": [],
"modified": "2023-09-26 12:03:23.031733",
"modified": "2024-03-19 18:43:42.235373",
"modified_by": "Administrator",
"module": "Accounts",
"name": "GL Entry",
Expand Down Expand Up @@ -325,4 +326,4 @@
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
}
2 changes: 0 additions & 2 deletions erpnext/accounts/doctype/gl_entry/gl_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class GLEntry(Document):
account: DF.Link | None
account_currency: DF.Link | None
against: DF.Text | None
against_link: DF.DynamicLink | None
against_type: DF.Link | None
against_voucher: DF.DynamicLink | None
against_voucher_type: DF.Link | None
company: DF.Link | None
Expand Down
46 changes: 22 additions & 24 deletions erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,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 @@ -1149,47 +1148,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:
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")

if not self.provisional_enpenses_booked_in_pr:
# 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:
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 1d91e17

Please sign in to comment.