I override the Delivery Note class to generate the specific accounting entries for service order but when the status is draft it doesn’t display the accounting entries
import frappe
from erpnext.stock.doctype.delivery_note.delivery_note import DeliveryNote
from erpnext.accounts.general_ledger import (
make_gl_entries,
make_reverse_gl_entries,
process_gl_map,
)
class CustomDeliveryNote(DeliveryNote):
def validate(self):
super().validate()
def on_cancel(self):
super().on_cancel()
def on_submit(self):
self.update_stock_ledger()
if self.custom_is_service_order:
self.custom_make_gl_entries()
else:
super().on_submit()
def custom_create_gl_entries(self, gl_entries):
"""
Creates GL Entries for COS and CWIP
"""
if len(self.items) >= 0:
wo_name = self.items[0].against_sales_order
se_detail_filters = {
"custom_sales_order": wo_name,
"docstatus": 1
}
se_detail = frappe.get_all("Stock Entry Detail", filters=se_detail_filters, fields=["*"])
ta_accomplishment = frappe.get_all("Technician Accomplishment", filters={"sales_order": wo_name}, fields=["*"])
amount = sum(float(item.amount) for item in se_detail)
amount += sum(float(item.labor_cost) for item in ta_accomplishment)
# COS Default Company Account
debit_account = frappe.get_value("Company", self.company, "default_expense_account")
# Capital Work in Progress
credit_account = frappe.get_value("Company", self.company, "capital_work_in_progress_account")
gl_entries.append(
self.get_gl_dict({
"account": debit_account,
"posting_date": self.posting_date,
"against": credit_account,
"debit": amount,
"debit_in_account_currency": amount,
"voucher_no": self.name,
"voucher_type": self.doctype,
"project": self.items[0].project,
"cost_center": self.items[0].cost_center,
"remarks": "TEST"
},
"PHP",
item=self,
)
)
# Create Credit Capital Work in Progress GL Entry
gl_entries.append(
self.get_gl_dict({
"account": credit_account,
"posting_date": self.posting_date,
"against": debit_account,
"credit": amount,
"credit_in_account_currency": amount,
"voucher_no": self.name,
"voucher_type": self.doctype,
"project": self.project,
"cost_center": self.items[0].cost_center,
"remarks": "TEST"
},
"PHP",
item=self,
)
)
def custom_make_gl_entries(self, cancel=False, adv_adj=False):
"""
Custom GL entries logic.
"""
gl_entries = []
self.custom_create_gl_entries(gl_entries)
process_gl_map(gl_entries, merge_entries=False)
make_gl_entries(gl_entries, cancel=cancel, adv_adj=adv_adj)