-
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
draft: [IMP|FIX] Improve performance and fix previous problems #228
base: 17.0
Are you sure you want to change the base?
Conversation
… carbon_factor_id set
…ce when none are found
Hi @jacopobacci, @jguenat, @BonnetAdam, |
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.
- Migration script is okay
- Performance improvements needs more testing (to do again after basics tests are done)
- fallback to company is not good (see comment)
I suggest doing separate PR for each point.
def has_valid_carbon_fallback(self, carbon_type: str): | ||
self.ensure_one() | ||
return self[f"carbon_{carbon_type}_fallback_reference"] and self[ | ||
f"carbon_{carbon_type}_fallback_reference" | ||
].has_valid_carbon_value(carbon_type) | ||
field_name = f"carbon_{carbon_type}_fallback_reference" | ||
need_re_call = False | ||
fallback_reference = getattr(self, field_name) or False | ||
|
||
has_valid_carbon_value = False | ||
if fallback_reference: | ||
has_valid_carbon_value = ( | ||
fallback_reference.has_valid_carbon_value(carbon_type) or False | ||
) | ||
|
||
# Condition explained: if fallback_reference is not set and the current record is not the last one in the list of CARBON_MODELS | ||
if ( | ||
not fallback_reference | ||
and self._name not in CARBON_MODELS | ||
and self._name != CARBON_MODELS[-1] | ||
): | ||
_logger.warning( | ||
f"Fallback reference for '{carbon_type}' is not set on {self}. Setting it to the company." | ||
) | ||
setattr(self, field_name, self.env.company) | ||
need_re_call = True | ||
|
||
if need_re_call: | ||
return self.has_valid_carbon_fallback(carbon_type) | ||
|
||
return fallback_reference and has_valid_carbon_value |
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.
It's not the correct place to do that. Did you try with _get_carbon_compute_default_record and/or get_carbon(in/out)_fallback_records() ?
Description
Related Issues
For the bug where we cannot find a fallback reference, here are the issues: #220
Self proofreading checklist
and meets the project's coding standards?
reflect your changes?
run upon committing to catch any potential issues?
Test Instructions
I haven't tested it out yet, BCH are going to do a deep down search if everything checked out
Additional Notes
Nope all good