Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
1704 Lượt xem

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





Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 2 24
2271
1
thg 4 25
2573
1
thg 3 25
2325
4
thg 8 24
3767
1
thg 3 24
951