Skip to content

Commit

Permalink
Merge pull request #42140 from nabinhait/provisional_entry_fix3
Browse files Browse the repository at this point in the history
fix: provisional entry for non stock items
  • Loading branch information
ruthra-kumar authored Jul 3, 2024
2 parents 28e8bb7 + d61dab8 commit 09c39fa
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
9 changes: 5 additions & 4 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-12-18 15:38:14.006208",
"modified": "2024-07-02 14:31:51.496466",
"modified_by": "Administrator",
"module": "Accounts",
"name": "GL Entry",
Expand Down Expand Up @@ -322,7 +323,7 @@
],
"quick_entry": 1,
"search_fields": "voucher_no,account,posting_date,against_voucher",
"sort_field": "modified",
"sort_field": "creation",
"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
50 changes: 25 additions & 25 deletions erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,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 @@ -1218,47 +1217,48 @@ 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 09c39fa

Please sign in to comment.