def update_variants(variants, template, publish_progress=True): count = 0 for d in variants: variant = dataent.get_doc("Item", d) copy_attributes_to_variant(template, variant) variant.save() count += 1 if publish_progress: dataent.publish_progress(count * 100 / len(variants), title=_("Updating Variants..."))
def create_salary_slips_for_employees(employees, args, publish_progress=True): salary_slips_exists_for = get_existing_salary_slips(employees, args) count = 0 for emp in employees: if emp not in salary_slips_exists_for: args.update({"doctype": "Salary Slip", "employee": emp}) ss = dataent.get_doc(args) ss.insert() count += 1 if publish_progress: dataent.publish_progress( count * 100 / len(set(employees) - set(salary_slips_exists_for)), title=_("Creating Salary Slips...")) payroll_entry = dataent.get_doc("Payroll Entry", args.payroll_entry) payroll_entry.db_set("salary_slips_created", 1) payroll_entry.notify_update()
def submit_salary_slips_for_employees(payroll_entry, salary_slips, publish_progress=True): submitted_ss = [] not_submitted_ss = [] dataent.flags.via_payroll_entry = True count = 0 for ss in salary_slips: ss_obj = dataent.get_doc("Salary Slip", ss[0]) if ss_obj.net_pay < 0: not_submitted_ss.append(ss[0]) else: try: ss_obj.submit() submitted_ss.append(ss_obj) except dataent.ValidationError: not_submitted_ss.append(ss[0]) count += 1 if publish_progress: dataent.publish_progress(count * 100 / len(salary_slips), title=_("Submitting Salary Slips...")) if submitted_ss: payroll_entry.make_accrual_jv_entry() dataent.msgprint( _("Salary Slip submitted for period from {0} to {1}").format( ss_obj.start_date, ss_obj.end_date)) payroll_entry.email_salary_slip(submitted_ss) payroll_entry.db_set("salary_slips_submitted", 1) payroll_entry.notify_update() if not submitted_ss and not not_submitted_ss: dataent.msgprint( _("No salary slip found to submit for the above selected criteria OR salary slip already submitted" )) if not_submitted_ss: dataent.msgprint(_("Could not submit some Salary Slips"))
def assign_salary_structure_for_employees(employees, salary_structure, from_date=None, base=None, variable=None): salary_structures_assignments = [] existing_assignments_for = get_existing_assignments( employees, salary_structure.name, from_date) count = 0 for employee in employees: if employee in existing_assignments_for: continue count += 1 salary_structures_assignment = create_salary_structures_assignment( employee, salary_structure, from_date, base, variable) salary_structures_assignments.append(salary_structures_assignment) dataent.publish_progress( count * 100 / len(set(employees) - set(existing_assignments_for)), title=_("Assigning Structures...")) if salary_structures_assignments: dataent.msgprint(_("Structures have been assigned successfully"))
def show_progress(docnames, message, i, description): n = len(docnames) if n >= 10: dataent.publish_progress(float(i) * 100 / n, title=message, description=description)