Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
1639 Представления

Hello everyone, i'd  like to pass attribute to xpath on .py file on odoo17 please help

@api.model
    def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
        res = super(SaleOrder, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)

        if view_type == 'form':
            # Parse the view architecture
            doc = etree.XML(res['arch'])

            # Find the product_template_id field inside order_line and add the 'no_create' option
            for field in doc.xpath("//field[@name='order_line']//field[@name='product_template_id']"):
                field.set("options", "{'no_create': True, 'no_create_edit': True, 'no_open': True}")

            # Update the view architecture
            res['arch'] = etree.tostring(doc, encoding='unicode')

        return res 
Аватар
Отменить
Автор Лучший ответ
Hi, thanks for the your reply, this code you giving is also not working, on  xml it accepts but on python is not coming I'm trying to add restrictions to some companies on creating products on sale order, is there is any other way to achieve that please. 																				
@api.model
def _get_view(self, view_id=None, view_type='form', **options):
arch, view = super()._get_view(view_id, view_type, **options)
active_company = self.env.company
if view_type == 'form' and active_company.company:
for node in arch.xpath("//field[@name='order_line']//field[@name='product_template_id']"):
#i tried fields.set and node.set still not working.
node.set('options', "{'no_create': True, 'no_create_edit': True, 'no_open': True}")
return arch, view
Аватар
Отменить
Лучший ответ

Hi,

fields_view_get no longer exist in Odoo 17.Instead of that use _get_view and try the below code:@api.model

def _get_view(self, view_id=None, view_type='form', **options):

       arch, view = super()._get_view(view_id, view_type, **options)

       if view_type == 'form':

               for node in arch.xpath("//field[@name='order_line']//field[@name='product_template_id']"):

                    field.set("options", "{'no_create': True, 'no_create_edit': True, 'no_open': True}")

       return arch, view


Hope it helps

Аватар
Отменить
Related Posts Ответы Просмотры Активность
4
июл. 25
4479
1
февр. 25
1497
1
авг. 25
188
4
июл. 25
1562
1
июл. 25
865