Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
1696 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
3
úno 24
2251
1
dub 25
2562
1
bře 25
2321
4
srp 24
3759
1
bře 24
951