Hi Maxwell,
The error you're encountering:
TypeError: 'bool' object does not support the context manager protocol
is due to the incorrect use of a with statement on a boolean value. This occurs specifically at the following line in the Odoo core:
with self._check_balanced(container):
Odoo expects _check_balanced() to return a context manager, but your custom code appears to return a boolean (True or False) instead.
Solution
You should review your custom override of _check_balanced() in the AccountMove model, likely located in:
- Mtts/invoice_cost_price/models/invoice_cost_price.py, or
- Mtts/analytic_account_policy/models/account_account.py
If your method looks like this:
def _check_balanced(self, container): return True # Incorrect
Replace it with the correct context manager format:
from contextlib import contextmanager @contextmanager def _check_balanced(self, container): yield
Or, if you have no special logic to implement, delegate back to Odoo's original method:
def _check_balanced(self, container): return super()._check_balanced(container)
Next Steps
- Search all custom modules for _check_balanced overrides.
- Fix the return type to ensure it is a proper context manager.
- Restart the server and test the confirmation action again.
This change should resolve the TypeError and restore functionality across modules that rely on this method, including stock and accounting.
Yes, Thank you so much, It's really working