Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] sustainability_employee_commuting: remote work management #266

Open
wants to merge 20 commits into
base: 17.0
Choose a base branch
from

Conversation

jacopobacci
Copy link
Contributor

Description

Calculate carbon emission for home working employees

Related Issues

Self proofreading checklist

  • Code Review: Have you reviewed your code to ensure it follows best practices
    and meets the project's coding standards?
  • Testing: Have you tested your changes locally to ensure they work as expected?
  • Documentation: Have you updated any relevant documentation or comments to
    reflect your changes?
  • Pre-commit Checks: Have you ensured that pre-commit checks have automatically
    run upon committing to catch any potential issues?

Introduce functionality to track and compute carbon emissions
from employee remote work. Extend existing models and cron jobs
to support this feature, allowing for automatic monthly
calculations. Enhance configuration settings to manage remote
work emission factors, journals, and accounts. This update
addresses the growing need to account for remote work's
environmental impact, providing a comprehensive solution for
sustainability tracking.
…ng and remote work

Introduce test suite to ensure carbon factors for commuting and remote work are processed correctly. Establishes a common setup for carbon factors and validates expected outcomes for cron job executions.
Renames `_cron_remote_work_carbon_account_move_create` to
`_cron_carbon_remote_work_account_move_create` for improved clarity
and consistency in naming conventions across the codebase.
Consolidate commuting and remote work carbon accounting cron jobs into a
single function to reduce code duplication and improve maintainability.
Introduce a mode parameter to handle different carbon accounting types,
ensuring flexibility and scalability. Update XML configurations and tests
to align with the new unified function.
Adjust carbon_value in common.py to reflect accurate emissions
for bicycle and remote work. Update expected results in
test_commuting.py to align with corrected carbon values.
Simplify the cron job function calls by removing the unused to_post
argument. This change enhances code readability and reduces unnecessary
complexity. Adjust related tests and model logic to align with this
refactor.
The addition of the has_location field allows for more precise tracking of employee location status, enhancing data accuracy. The refactoring in res_company improves the efficiency of employee contract retrieval by leveraging the new field, ensuring that only relevant employees are processed.
…t location and fix commuting test expected result

Add a new test case for an employee without a location to ensure
coverage for this scenario. Adjust the expected result in the
commuting test to reflect the correct total value calculation.
Refactor test to calculate the total signed value of all carbon line
origins instead of just one. Adjust expected result to reflect the
aggregated value, ensuring the test accurately validates the
commuting carbon footprint calculation.
…tion

Enhance code maintainability by extracting repeated logic into
dedicated methods. Introduce helper functions for deleting existing
account moves, fetching employees with contracts, calculating averages,
preparing account move lines, and creating account moves. This
refactoring reduces redundancy, improves readability, and ensures
consistency across the codebase. Additionally, improve error handling
by logging detailed error messages and notifying employees of issues
during remote work carbon processing.
…error logging

Enhance `get_employees_with_contracts` to accept a domain filter, improving flexibility. Simplify error logging by removing employee-specific notifications, focusing on general error messages.
…ployee setups

Add tests for various employee configurations, including those with
home and office locations, no location, and no contract. Adjust
expected results to reflect updated scenarios. Improve test
documentation for clarity on remote work carbon emission calculations.
…ecords into batch operations for efficiency and readability
@jacopobacci jacopobacci added the enhancement New feature or request label Jan 30, 2025
@jacopobacci jacopobacci self-assigned this Jan 30, 2025
@sustainabilitybot
Copy link
Collaborator

Hi @BonnetAdam,
some modules you are maintaining are being modified, check this out!


DAYS = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why have you duplicated the variable ?
from odoo.addons.hr_homeworking.models.hr_homeworking import DAYS ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i didn't duplicate any variable, to what are u referring?

sustainability_employee_commuting/models/account_move.py Outdated Show resolved Hide resolved
sustainability_employee_commuting/models/account_move.py Outdated Show resolved Hide resolved
Comment on lines 91 to 98
"monday_location_id",
"tuesday_location_id",
"wednesday_location_id",
"thursday_location_id",
"friday_location_id",
"saturday_location_id",
"sunday_location_id",
"exceptional_location_id",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this possible ?

Suggested change
"monday_location_id",
"tuesday_location_id",
"wednesday_location_id",
"thursday_location_id",
"friday_location_id",
"saturday_location_id",
"sunday_location_id",
"exceptional_location_id",
**DAYS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but like this
@api.depends( *DAYS, "exceptional_location_id", )

@@ -24,16 +24,46 @@ class ResConfigSettings(models.TransientModel):
related="company_id.employee_commuting_carbon_cronjob_active",
readonly=False,
)
employee_remote_work_carbon_factor_id = fields.Many2one(
"carbon.factor",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"carbon.factor",
comodel_name="carbon.factor",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you check in the code above comodel name is not used

    employee_commuting_carbon_factor_id = fields.Many2one(
        "carbon.factor",
        related="company_id.employee_commuting_carbon_factor_id",
        readonly=False,
    )
    employee_commuting_journal_id = fields.Many2one(
        "account.journal",
        related="company_id.employee_commuting_journal_id",
        readonly=False,
    )
    employee_commuting_account_id = fields.Many2one(
        "account.account",
        related="company_id.employee_commuting_account_id",
        readonly=False,
    )
    employee_commuting_carbon_cronjob_active = fields.Boolean(
        "Cron job active",
        related="company_id.employee_commuting_carbon_cronjob_active",
        readonly=False,
    )

from odoo.tests import TransactionCase


class CarbonCommon(TransactionCase):
Copy link
Member

@BonnetAdam BonnetAdam Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't Inherit sustainability common ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because i dont need all that stuff, i think it's better to do module specific common tests setup. here we are in sustainibility_employee_commuting and it's better to have a "dedicated" test setup imo

test(common.py): add cleanup of demo data to ensure test isolation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remote work management
3 participants