|
3 | 3 | import logging
|
4 | 4 | import re
|
5 | 5 |
|
| 6 | +import lxml |
| 7 | + |
6 | 8 | try:
|
7 | 9 | from contextlib import suppress
|
8 | 10 | except ImportError:
|
@@ -310,42 +312,49 @@ def adapt_domains(cr, model, old, new, adapter=None, skip_inherit=(), force_adap
|
310 | 312 | cr.execute("SELECT id, model FROM ir_ui_view WHERE {} ~ %s".format(arch_db), [match_old])
|
311 | 313 | for view_id, view_model in cr.fetchall():
|
312 | 314 | # Note: active=None is important to not reactivate views!
|
313 |
| - with suppress(_Skip), edit_view(cr, view_id=view_id, active=None) as view: |
314 |
| - modified = False |
315 |
| - for node in view.xpath( |
316 |
| - "//filter[contains(@domain, '{0}')]|//field[contains(@filter_domain, '{0}')]".format(old) |
317 |
| - ): |
318 |
| - attr = "domain" if "domain" in node.attrib else "filter_domain" |
319 |
| - domain = _adapt_one_domain( |
320 |
| - cr, target_model, old, new, view_model, node.get(attr), adapter=adapter, force_adapt=force_adapt |
321 |
| - ) |
322 |
| - if domain: |
323 |
| - node.set(attr, unicode(domain)) |
324 |
| - modified = True |
325 |
| - |
326 |
| - for node in view.xpath("//field[contains(@domain, '{0}')]".format(old)): |
327 |
| - # as <fields> can happen in sub-views, we should deternine the actual model the field belongs to |
328 |
| - path = list(reversed([p.get("name") for p in node.iterancestors("field")])) + [node.get("name")] |
329 |
| - field_model = _model_of_path(cr, view_model, path) |
330 |
| - if not field_model: |
331 |
| - continue |
332 |
| - |
333 |
| - domain = _adapt_one_domain( |
334 |
| - cr, |
335 |
| - target_model, |
336 |
| - old, |
337 |
| - new, |
338 |
| - field_model, |
339 |
| - node.get("domain"), |
340 |
| - adapter=adapter, |
341 |
| - force_adapt=force_adapt, |
342 |
| - ) |
343 |
| - if domain: |
344 |
| - node.set("domain", unicode(domain)) |
345 |
| - modified = True |
346 |
| - |
347 |
| - if not modified: |
348 |
| - raise _Skip |
| 315 | + try: |
| 316 | + with suppress(_Skip), edit_view(cr, view_id=view_id, active=None) as view: |
| 317 | + modified = False |
| 318 | + for node in view.xpath( |
| 319 | + "//filter[contains(@domain, '{0}')]|//field[contains(@filter_domain, '{0}')]".format(old) |
| 320 | + ): |
| 321 | + attr = "domain" if "domain" in node.attrib else "filter_domain" |
| 322 | + domain = _adapt_one_domain( |
| 323 | + cr, target_model, old, new, view_model, node.get(attr), adapter=adapter, force_adapt=force_adapt |
| 324 | + ) |
| 325 | + if domain: |
| 326 | + node.set(attr, unicode(domain)) |
| 327 | + modified = True |
| 328 | + |
| 329 | + for node in view.xpath("//field[contains(@domain, '{0}')]".format(old)): |
| 330 | + # as <fields> can happen in sub-views, we should deternine the actual model the field belongs to |
| 331 | + path = list(reversed([p.get("name") for p in node.iterancestors("field")])) + [node.get("name")] |
| 332 | + field_model = _model_of_path(cr, view_model, path) |
| 333 | + if not field_model: |
| 334 | + continue |
| 335 | + |
| 336 | + domain = _adapt_one_domain( |
| 337 | + cr, |
| 338 | + target_model, |
| 339 | + old, |
| 340 | + new, |
| 341 | + field_model, |
| 342 | + node.get("domain"), |
| 343 | + adapter=adapter, |
| 344 | + force_adapt=force_adapt, |
| 345 | + ) |
| 346 | + if domain: |
| 347 | + node.set("domain", unicode(domain)) |
| 348 | + modified = True |
| 349 | + |
| 350 | + if not modified: |
| 351 | + raise _Skip |
| 352 | + except lxml.etree.XMLSyntaxError as e: |
| 353 | + if e.msg.startswith("Opening and ending tag mismatch"): |
| 354 | + # this view is already wrong, we don't change it |
| 355 | + _logger.warning("Skipping domain adpatation for invalid view (id=%s):\n%s", view_id, e.msg) |
| 356 | + continue |
| 357 | + raise |
349 | 358 |
|
350 | 359 | # adapt domain in dashboards.
|
351 | 360 | # NOTE: does not filter on model at dashboard selection for handle dotted domains
|
|
0 commit comments