Skip to content

Conversation

@hbrunn
Copy link
Member

@hbrunn hbrunn commented Dec 8, 2025

this transforms

<field attrs={'required': [('field', '=', value)]}>

to

<field required="field == value" />

which is quite a pain to do manually

Copy link
Collaborator

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks !

Copy link
Member

@StefanRijnhart StefanRijnhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

It seems attrs="{'invisible': [('some_field', '=', True)]} is transformed to invisible="some_field == True". Can you make this invisible="some_field"?

@hbrunn hbrunn force-pushed the master-v17-attrs-conversion branch from 43818da to b5b5841 Compare December 10, 2025 16:49
@hbrunn
Copy link
Member Author

hbrunn commented Dec 10, 2025

@StefanRijnhart added that. At first, I deliberately didn't include handling the = True case here because a =/!= False domain leaf will be is (not) null in sql, which is guaranteed to map to falsiness/truthiness, while != True could be any truthy value that's not True. But then I think you're right and nobody uses it that way, so we're better off supporting the much more realistic case where this is used on boolean fields

@StefanRijnhart
Copy link
Member

StefanRijnhart commented Dec 13, 2025

Thanks, boolean issue is now solved. Next issue I now encounter is attrs with newlines in the XML.

                <attribute name="attrs">{'invisible': ['|', '|', '&amp;',                                                                                                                     
                    ('picking_type_code', '!=', 'outgoing'),                                                                                                                                  
                    ('some_field', '=', False),                                                                                                                                          
                    ('state', 'in', ('draft', 'cancel')),                                                                                                                                     
                    ('other_field', '=', False)]}                                                                                                                                               
                </attribute>

Such a snippet leads to

  File "/home/venv/py3.12-test3/lib/python3.12/site-packages/odoo_module_migrate/migration_scripts/migrate_160_170.py", line 361, in attrs_to_attributes
    attrs_expression = ast.parse(attrs_string, mode="eval")
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/.pyenv/versions/3.12.9/lib/python3.12/ast.py", line 52, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 6
    
IndentationError: unexpected indent

@hbrunn hbrunn force-pushed the master-v17-attrs-conversion branch from b5b5841 to 40ee4a2 Compare December 14, 2025 18:20
@hbrunn
Copy link
Member Author

hbrunn commented Dec 14, 2025

@StefanRijnhart thank you for battle testing this, fixed

Copy link
Member

@StefanRijnhart StefanRijnhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, working well now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants