Skip to content

Instantly share code, notes, and snippets.

@3mrdev
Last active October 14, 2024 13:30
Show Gist options
  • Save 3mrdev/2a4c19200042caee4d75a719bc036a52 to your computer and use it in GitHub Desktop.
Save 3mrdev/2a4c19200042caee4d75a719bc036a52 to your computer and use it in GitHub Desktop.
Date filters one2many field in Payroll salary rules
# Access employee shipments and filter by payslip date range
shipment_count = len(employee.shipments.filtered(
lambda s: s.scheduled_date and s.scheduled_date.date() >= payslip.date_start and s.scheduled_date.date() <= payslip.date_end
))
# Return the shipment count for further calculations if needed
result = shipment_count
# Access employee shipments and filter by payslip date range
total_trip_cost = sum(employee.x_studio_one2many_field_5kk_1ia59qec4.filtered(
lambda s: s.scheduled_date and s.scheduled_date.date() >= payslip.date_from and s.scheduled_date.date() <= payslip.date_to
).mapped('x_studio_trip_expenses'))
# Return the total trip expenses cost for further calculations if needed
result = total_trip_cost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment