Skip to Content
Menú
This question has been flagged
1 Respondre
1697 Vistes

I inherited a model with an existing field that has a docstring domain, to alter the domain and also add a new field which will be used in the altered domain

e.g

class ProjectTask(models.Model):
_inherit = "project.task"

customer_tree_ids = fields.Many2many(related="project_id.customer_tree_ids")

sale_line_id = fields.Many2one(
domain="""[
('is_service', '=', True),
('is_expense', '=', False),
('state', 'in', ['sale', 'done']),
('order_partner_id', 'in', customer_tree_ids), '|',
('company_id', '=', False), ('company_id', '=', company_id)]""",
)

and in my view


project.task.view.form
project.task








but  I get the error 

Error while validating view near:

Field 'customer_tree_ids' used in domain of python field 'sale_line_id' ([ ('is_service', '=', True), ('is_expense', '=', False), ('state', 'in', ['sale', 'done']), ('order_partner_id', 'in', customer_tree_ids), '|', ('company_id', '=', False), ('company_id', '=', company_id)]) must be present in view but is missing.


This works well in odoo 16.0 but when installing the module in 17.0 then I get this error





Avatar
Descartar
Best Answer

You could try something like this instead


def _get_order_line_domain(self):

    return [('is_service', '=', True), ('is_expense', '=', False), ('state', 'in', ['sale', 'done']),

            ('order_partner_id', 'in', self.customer_tree_ids.ids), '|', ('company_id', '=', False),

            ('company_id', '=', self.company_id.id)]


sale_line_id = fields.Many2one(“sale.order.line”, domain=_get_order_line_domain)


This would solve your problem

Avatar
Descartar
Related Posts Respostes Vistes Activitat
3
de febr. 24
2255
1
d’abr. 25
2563
1
de març 25
2323
4
d’ag. 24
3761
1
de març 24
951