0

I need to create a new Many2one field in Odoo 17, extending the standard res.partner model so that the domain of the newly created res_partner.settore_principale field and its possible values are selected dynamically according to the value of the res_partner.x_studio_macrocategoria attribute of the same record, both in case the latter is modified and in case it hasn't been.

I tries to create a new field with a callback defining it's domain, as shown below:

    settore_principale = fields.Many2one(
        'res.partner.industry', 
        string="Settore",
        domain=lambda self: self._compute_settore_domain()  # I tried both with and without str()
    )
    
    def _compute_settore_domain(self):
        domain = [('x_studio_settore_padre', '=', False)]
        if self.x_studio_macrocategoria: 
            domain.append(('x_studio_macrocategoria', '=', self.x_studio_macrocategoria))
        return domain  # Return domain as a list of tuples, not string

    @api.onchange('x_studio_macrocategoria')
    def _onchange_macrocategoria(self):
        return {'domain': {'settore_principale': self._compute_settore_domain()}}

fact is that on loading the addon, even on a first try, I receive the following error:

odoo.addons.base.models.ir_qweb.QWebException: Error while render the template
UndefinedColumn: column res_partner.settore_principale does not exist
LINE 1: ...uid", "res_partner"."write_date" AS "write_date", "res_partn...
                                                             ^

it appears that while the code gets parsed and executed in at least a partially correct way, it doesn't allow Odoo to follow with the actual field creation in the database.

Could anyone help me understand what i'm doing wrong?

Thanks in advance

2
  • 1
    Are you using the field: test_sale_id in any view of your model ? Have you defined this field in another module ? Commented Nov 21, 2024 at 19:39
  • @AhrimannSteiner my bad, i tried to change the name of the field to verify it was not a problem with a failed module loading, I tried to re-run the code and it's the settore_principale causing the error, I updated the question Commented Nov 22, 2024 at 8:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.