How to Map Requirement in Formula in Salary Structure

Hooks

CRUD Events

You can hook to various CRUD events of any doctype, the syntax for such a hook is as follows,

doc_events = {
      "{doctype}": {
        "{event}": "{dotted.path.to.function}",
    }
}

The hook function will be passed the doc in concern as the only argument.

List of events

  • validate
  • before_save
  • after_save
  • before_insert
  • after_insert
  • before_submit
  • before_cancel
  • before_update_after_submit
  • on_update
  • on_submit
  • on_cancel
  • on_update_after_submit
    Eg,
doc_events = {
    "Salary Slip": {
        "after_insert": path.to.my.custom.calculate_tax",
    }
}

Your script might have a logic like this:

def calculate_tax(doc):
        amount = get_amount(doc)

	doc.append("earnings",{
		"default_amount": 0,
		"amount_based_on_formula": 0,
		"denpends_on_lwp": 0,
		"salary_component": "Tax Band",
		"amount": amount
	})
1 Like