# Buggy code
def validate(self):
    super(SalesInvoice, self).validate()
    self.validate_posting_time()
    self.so_dn_required()
    self.validate_proj_cust()
    self.validate_with_previous_doc()
    self.validate_uom_is_integer("stock_uom", "qty")
    self.check_close_sales_order("sales_order")
    self.validate_debit_to_acc()
    self.clear_unallocated_advances("Sales Invoice Advance", "advances")
    self.add_remarks()
    self.validate_write_off_account()
    self.validate_account_for_change_amount()
    self.validate_fixed_asset()
    self.set_income_account_for_fixed_assets()

    if cint(self.is_pos):
        self.validate_pos()

    if cint(self.update_stock):
        self.validate_dropship_item()
        self.validate_item_code()
        self.validate_warehouse()
        self.update_current_stock()
        self.validate_delivery_note()

    if not self.is_opening:
        self.is_opening = "No"

    self.set_against_income_account()
    self.validate_c_form()
    self.validate_time_sheets_are_submitted()
    self.validate_multiple_billing("Delivery Note", "dn_detail", "amount", "items")
    self.update_packing_list()
    self.set_billing_hours_and_amount()
    self.update_timesheet_billing_for_project()
    self.set_status()


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/erpnext/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs
doc.submit()
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 741, in submit
self._submit()
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 730, in _submit
self.save()
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 231, in save
return self._save(*args, **kwargs)
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 264, in _save
self.run_before_save_methods()
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 775, in run_before_save_methods
self.run_method("validate")
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 667, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 892, in composer
return composed(self, method, *args, **kwargs)
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 875, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 661, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File "/home/erpnext/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py", line 89, in validate
self.set_status()
File "/home/erpnext/frappe-bench/apps/erpnext/erpnext/controllers/status_updater.py", line 122, in set_status
if frappe.safe_eval(s[1][5:], None, { "self": self.as_dict(), "getdate": getdate, "nowdate": nowdate }):
AttributeError: 'module' object has no attribute 'safe_eval'

Traceback (most recent call last):
File "/home/erpnext/frappe-bench/apps/frappe/frappe/app.py", line 56, in application
response = frappe.handler.handle()
File "/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py", line 19, in handle
execute_cmd(cmd)
File "/home/erpnext/frappe-bench/apps/frappe/frappe/handler.py", line 42, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File "/home/erpnext/frappe-bench/apps/frappe/frappe/__init__.py", line 907, in call
return fn(*args, **newargs)
File "/home/erpnext/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 19, in savedocs
doc.submit()
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 741, in submit
self._submit()
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 730, in _submit
self.save()
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 231, in save
return self._save(*args, **kwargs)
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 264, in _save
self.run_before_save_methods()
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 775, in run_before_save_methods
self.run_method("validate")
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 667, in run_method
out = Document.hook(fn)(self, *args, **kwargs)
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 892, in composer
return composed(self, method, *args, **kwargs)
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 875, in runner
add_to_return_value(self, fn(self, *args, **kwargs))
File "/home/erpnext/frappe-bench/apps/frappe/frappe/model/document.py", line 661, in
fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
File "/home/erpnext/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.py", line 89, in validate
self.set_status()
File "/home/erpnext/frappe-bench/apps/erpnext/erpnext/controllers/status_updater.py", line 122, in set_status
if frappe.safe_eval(s[1][5:], None, { "self": self.as_dict(), "getdate": getdate, "nowdate": nowdate }):
AttributeError: 'module' object has no attribute 'safe_eval'

# Fixed code
def validate(self):
    super(SalesInvoice, self).validate()
    self.validate_auto_set_posting_time()
    self.so_dn_required()
    self.validate_proj_cust()
    self.validate_with_previous_doc()
    self.validate_uom_is_integer("stock_uom", "qty")
    self.check_close_sales_order("sales_order")
    self.validate_debit_to_acc()
    self.clear_unallocated_advances("Sales Invoice Advance", "advances")
    self.add_remarks()
    self.validate_write_off_account()
    self.validate_account_for_change_amount()
    self.validate_fixed_asset()
    self.set_income_account_for_fixed_assets()

    if cint(self.is_pos):
        self.validate_pos()

    if cint(self.update_stock):
        self.validate_dropship_item()
        self.validate_item_code()
        self.validate_warehouse()
        self.update_current_stock()
        self.validate_delivery_note()

    if not self.is_opening:
        self.is_opening = "No"

    self.set_against_income_account()
    self.validate_c_form()
    self.validate_time_sheets_are_submitted()
    self.validate_multiple_billing("Delivery Note", "dn_detail", "amount", "items")
    self.update_packing_list()
    self.set_billing_hours_and_amount()
    self.update_timesheet_billing_for_project()
    self.set_status()