Odooers论坛

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

TypeError: 'bool' object does not support the context manager protocol

1 备注
形象
丢弃
形象
odoo
-

Yes, Thank you so much, It's really working

1 答案
0
形象
odoo
最佳答案

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.

形象
丢弃