|
1 | 1 | # Copyright (C) 2018 - TODAY, Pavlov Media
|
2 | 2 | # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
3 | 3 |
|
4 |
| -import ast |
5 |
| -import json as simplejson |
6 | 4 | from datetime import timedelta
|
7 | 5 |
|
8 | 6 | from lxml import etree
|
@@ -144,9 +142,7 @@ def _get_default_parties(self):
|
144 | 142 | """
|
145 | 143 | return deftext
|
146 | 144 |
|
147 |
| - parties = fields.Html( |
148 |
| - tracking=True, default=_get_default_parties, help="Parties of the agreement" |
149 |
| - ) |
| 145 | + parties = fields.Html(default=_get_default_parties, help="Parties of the agreement") |
150 | 146 | dynamic_parties = fields.Html(
|
151 | 147 | compute="_compute_dynamic_parties", help="Compute dynamic parties"
|
152 | 148 | )
|
@@ -233,9 +229,9 @@ def _get_default_parties(self):
|
233 | 229 | field_id = fields.Many2one(
|
234 | 230 | "ir.model.fields",
|
235 | 231 | string="Field",
|
236 |
| - help="""Select target field from the related document model. If it is a |
237 |
| - relationship field you will be able to select a target field at the |
238 |
| - destination of the relationship.""", |
| 232 | + help="""You can select a target field from the related document model. |
| 233 | + If it is a relationship field you will be able to select a target field |
| 234 | + at the destination of the relationship.""", |
239 | 235 | )
|
240 | 236 | sub_object_id = fields.Many2one(
|
241 | 237 | "ir.model",
|
@@ -465,44 +461,22 @@ def copy(self, default=None):
|
465 | 461 | def _exclude_readonly_field(self):
|
466 | 462 | return ["stage_id"]
|
467 | 463 |
|
| 464 | + def _get_agreement_readonly_domain(self): |
| 465 | + return "bool(readonly)" |
| 466 | + |
468 | 467 | @api.model
|
469 |
| - def fields_view_get( |
470 |
| - self, view_id=None, view_type=False, toolbar=False, submenu=False |
471 |
| - ): |
472 |
| - res = super().fields_view_get( |
473 |
| - view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu |
474 |
| - ) |
| 468 | + def get_view(self, view_id=None, view_type=False, **options): |
| 469 | + res = super().get_view(view_id, view_type, **options) |
475 | 470 | # Readonly fields
|
476 | 471 | if view_type == "form":
|
477 | 472 | doc = etree.XML(res["arch"])
|
478 |
| - for node in doc.xpath("//field"): |
| 473 | + for node in doc.xpath("//field[@name][not(ancestor::field)]"): |
479 | 474 | if node.attrib.get("name") in self._exclude_readonly_field():
|
480 | 475 | continue
|
481 |
| - attrs = ast.literal_eval(node.attrib.get("attrs", "{}")) |
482 |
| - if attrs: |
483 |
| - if attrs.get("readonly"): |
484 |
| - attrs["readonly"] = ["|", ("readonly", "=", True)] + attrs[ |
485 |
| - "readonly" |
486 |
| - ] |
487 |
| - else: |
488 |
| - attrs["readonly"] = [("readonly", "=", True)] |
489 |
| - else: |
490 |
| - attrs["readonly"] = [("readonly", "=", True)] |
491 |
| - node.set("attrs", simplejson.dumps(attrs)) |
492 |
| - modifiers = ast.literal_eval( |
493 |
| - node.attrib.get("modifiers", "{}") |
494 |
| - .replace("true", "True") |
495 |
| - .replace("false", "False") |
496 |
| - ) |
497 |
| - readonly = modifiers.get("readonly") |
498 |
| - invisible = modifiers.get("invisible") |
499 |
| - required = modifiers.get("required") |
500 |
| - if isinstance(readonly, bool) and readonly: |
501 |
| - attrs["readonly"] = readonly |
502 |
| - if isinstance(invisible, bool) and invisible: |
503 |
| - attrs["invisible"] = invisible |
504 |
| - if isinstance(required, bool) and required: |
505 |
| - attrs["required"] = required |
506 |
| - node.set("modifiers", simplejson.dumps(attrs)) |
| 476 | + new_r_modifier = self._get_agreement_readonly_domain() |
| 477 | + old_r_modifier = node.attrib.get("readonly") |
| 478 | + if old_r_modifier: |
| 479 | + new_r_modifier = f"({old_r_modifier}) or ({new_r_modifier})" |
| 480 | + node.attrib["readonly"] = new_r_modifier |
507 | 481 | res["arch"] = etree.tostring(doc)
|
508 | 482 | return res
|
0 commit comments