-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: 17.0
Are you sure you want to change the base?
Conversation
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.
…o ensure accurate data mapping
…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.
…ning _get_all_contracts method
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.
…lter by unit of measure
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.
… date to ensure accurate data retrieval
…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
Hi @BonnetAdam, |
|
||
DAYS = [ |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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?
"monday_location_id", | ||
"tuesday_location_id", | ||
"wednesday_location_id", | ||
"thursday_location_id", | ||
"friday_location_id", | ||
"saturday_location_id", | ||
"sunday_location_id", | ||
"exceptional_location_id", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this possible ?
"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 |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"carbon.factor", | |
comodel_name="carbon.factor", |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
…constant in _compute_work_days_home method
Description
Calculate carbon emission for home working employees
Related Issues
Self proofreading checklist
and meets the project's coding standards?
reflect your changes?
run upon committing to catch any potential issues?