recompute_expected_hours.py 930 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env python3
  2. """
  3. Script to force recompute expected_hours_to_date field for existing records
  4. """
  5. import odoo
  6. from odoo import api, fields, models
  7. from odoo.tools import config
  8. def main():
  9. # Initialize Odoo
  10. odoo.cli.server.main()
  11. # Get environment
  12. env = api.Environment(cr, uid, {})
  13. # Get all hr.efficiency records
  14. efficiency_records = env['hr.efficiency'].search([('active', '=', True)])
  15. print(f"Found {len(efficiency_records)} efficiency records to update")
  16. # Force recompute of expected_hours_to_date field
  17. for record in efficiency_records:
  18. record._compute_expected_hours_to_date()
  19. print(f"Updated record {record.id}: {record.employee_id.name} - {record.month_year} - Expected: {record.expected_hours_to_date}")
  20. # Commit changes
  21. env.cr.commit()
  22. print("All records updated successfully!")
  23. if __name__ == "__main__":
  24. main()