79473940

Date: 2025-02-27 21:12:41
Score: 1.5
Natty:
Report link

I found a solution to my issue, and I want to share it in case someone else encounters the same problem in the future.

The key was to define a field with a search method in the model. Since store=False fields cannot be used directly in domain filters, I implemented a custom search function to map user_country_id to country_id.

Add this field to the model

user_country_id = fields.Many2one(
    'res.country', string="User Country",
    store=False, search="_search_user_country"
)

def _search_user_country(self, operator, value):
    """Defines how `user_country_id` is used in domain searches"""
    return [('country_id', operator, self.env.user.country_id.id)]

Then, modify the view’s domain condition like this:

<field name="domain">[('user_country_id', '=', 1)]</field>
Reasons:
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: japs