Skip to content

Commit

Permalink
[17.0][MIG] agreement_legal: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ilo committed Oct 25, 2024
1 parent ff0c7b3 commit cddeef9
Show file tree
Hide file tree
Showing 21 changed files with 273 additions and 329 deletions.
1 change: 1 addition & 0 deletions agreement_legal/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Contributors
- Sandip Mangukiya <[email protected]>
- Yves Goldberg <[email protected]>
- Tharathip Chaweewongphan <[email protected]>
- Italo LOPES <[email protected]>

Other credits
-------------
Expand Down
56 changes: 15 additions & 41 deletions agreement_legal/models/agreement.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Copyright (C) 2018 - TODAY, Pavlov Media
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import ast
import json as simplejson
from datetime import timedelta

from lxml import etree
Expand Down Expand Up @@ -144,9 +142,7 @@ def _get_default_parties(self):
"""
return deftext

parties = fields.Html(
tracking=True, default=_get_default_parties, help="Parties of the agreement"
)
parties = fields.Html(default=_get_default_parties, help="Parties of the agreement")
dynamic_parties = fields.Html(
compute="_compute_dynamic_parties", help="Compute dynamic parties"
)
Expand Down Expand Up @@ -233,9 +229,9 @@ def _get_default_parties(self):
field_id = fields.Many2one(
"ir.model.fields",
string="Field",
help="""Select target field from the related document model. If it is a
relationship field you will be able to select a target field at the
destination of the relationship.""",
help="""You can select a target field from the related document model.
If it is a relationship field you will be able to select a target field
at the destination of the relationship.""",
)
sub_object_id = fields.Many2one(
"ir.model",
Expand Down Expand Up @@ -465,44 +461,22 @@ def copy(self, default=None):
def _exclude_readonly_field(self):
return ["stage_id"]

def _get_agreement_readonly_domain(self):
return "bool(readonly)"

@api.model
def fields_view_get(
self, view_id=None, view_type=False, toolbar=False, submenu=False
):
res = super().fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
)
def get_view(self, view_id=None, view_type=False, **options):
res = super().get_view(view_id, view_type, **options)
# Readonly fields
if view_type == "form":
doc = etree.XML(res["arch"])
for node in doc.xpath("//field"):
for node in doc.xpath("//field[@name][not(ancestor::field)]"):
if node.attrib.get("name") in self._exclude_readonly_field():
continue
attrs = ast.literal_eval(node.attrib.get("attrs", "{}"))
if attrs:
if attrs.get("readonly"):
attrs["readonly"] = ["|", ("readonly", "=", True)] + attrs[
"readonly"
]
else:
attrs["readonly"] = [("readonly", "=", True)]
else:
attrs["readonly"] = [("readonly", "=", True)]
node.set("attrs", simplejson.dumps(attrs))
modifiers = ast.literal_eval(
node.attrib.get("modifiers", "{}")
.replace("true", "True")
.replace("false", "False")
)
readonly = modifiers.get("readonly")
invisible = modifiers.get("invisible")
required = modifiers.get("required")
if isinstance(readonly, bool) and readonly:
attrs["readonly"] = readonly
if isinstance(invisible, bool) and invisible:
attrs["invisible"] = invisible
if isinstance(required, bool) and required:
attrs["required"] = required
node.set("modifiers", simplejson.dumps(attrs))
new_r_modifier = self._get_agreement_readonly_domain()
old_r_modifier = node.attrib.get("readonly")
if old_r_modifier:
new_r_modifier = f"({old_r_modifier}) or ({new_r_modifier})"
node.attrib["readonly"] = new_r_modifier
res["arch"] = etree.tostring(doc)
return res
1 change: 1 addition & 0 deletions agreement_legal/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- Sandip Mangukiya \<<[email protected]>\>
- Yves Goldberg \<<[email protected]>\>
- Tharathip Chaweewongphan \<<[email protected]>\>
- Italo LOPES \<<[email protected]>\>
1 change: 1 addition & 0 deletions agreement_legal/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ <h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<li>Sandip Mangukiya &lt;<a class="reference external" href="mailto:smangukiya&#64;opensourceintegrators.com">smangukiya&#64;opensourceintegrators.com</a>&gt;</li>
<li>Yves Goldberg &lt;<a class="reference external" href="mailto:yves&#64;ygol.com">yves&#64;ygol.com</a>&gt;</li>
<li>Tharathip Chaweewongphan &lt;<a class="reference external" href="mailto:tharathipc&#64;ecosoft.co.th">tharathipc&#64;ecosoft.co.th</a>&gt;</li>
<li>Italo LOPES &lt;<a class="reference external" href="mailto:italo.lopes&#64;camptocamp.com">italo.lopes&#64;camptocamp.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand Down
2 changes: 1 addition & 1 deletion agreement_legal/static/src/js/form_view.esm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @odoo-module **/

import {registry} from "@web/core/registry";
import {FormController} from "@web/views/form/form_controller";
import {formView} from "@web/views/form/form_view";
import {registry} from "@web/core/registry";
import {useService} from "@web/core/utils/hooks";

export class AgreementFormController extends FormController {
Expand Down
4 changes: 2 additions & 2 deletions agreement_legal/static/src/js/kanban_view.esm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @odoo-module **/

import {registry} from "@web/core/registry";
import {KanbanController} from "@web/views/kanban/kanban_controller";
import {kanbanView} from "@web/views/kanban/kanban_view";
import {registry} from "@web/core/registry";
import {useService} from "@web/core/utils/hooks";

export class AgreementKanbanController extends KanbanController {
Expand All @@ -19,7 +19,7 @@ export class AgreementKanbanController extends KanbanController {
export const AgreementKanbanView = {
...kanbanView,
Controller: AgreementKanbanController,
buttonTemplate: "agreement.KanbanView.Buttons",
buttonTemplate: "agreement_legal.KanbanViewButtons",
};

registry.category("views").add("agreement_template_kanban", AgreementKanbanView);
4 changes: 2 additions & 2 deletions agreement_legal/static/src/js/list_view.esm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @odoo-module **/

import {registry} from "@web/core/registry";
import {ListController} from "@web/views/list/list_controller";
import {listView} from "@web/views/list/list_view";
import {registry} from "@web/core/registry";
import {useService} from "@web/core/utils/hooks";

export class AgreementListController extends ListController {
Expand All @@ -19,7 +19,7 @@ export class AgreementListController extends ListController {
export const AgreementListView = {
...listView,
Controller: AgreementListController,
buttonTemplate: "agreement.ListView.Buttons",
buttonTemplate: "agreement_legal.ListView",
};

registry.category("views").add("agreement_template_tree", AgreementListView);
64 changes: 0 additions & 64 deletions agreement_legal/static/src/xml/agreement.xml

This file was deleted.

21 changes: 21 additions & 0 deletions agreement_legal/static/src/xml/agreement_form_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>

<t t-inherit="web.FormView" t-inherit-mode="extension">
<xpath
expr="//*[@class='btn btn-secondary o_form_button_create']"
position="after"
>
<t t-if="props.resModel === 'agreement'">
<t t-call="agreement_legal.TemplateButton" />
</t>
</xpath>
<xpath
expr="//*[@class='btn btn-secondary o_form_button_create']"
position="attributes"
>
<attribute name="t-if">canCreateTemplate</attribute>
</xpath>
</t>

</templates>
24 changes: 24 additions & 0 deletions agreement_legal/static/src/xml/agreement_kanban_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>

<t
t-name="agreement_legal.KanbanViewButtons"
t-inherit="web.KanbanView.Buttons"
t-inherit-mode="primary"
>
<div role="toolbar" position="inside">
<t t-call="agreement_legal.TemplateButton" />
</div>
</t>
<t
t-name="agreement_legal.KanbanView"
t-inherit="web.KanbanView"
t-inherit-mode="primary"
>
<xpath expr="//button[hasclass('o-kanban-button-new')]" position="attributes">
<attribute name="t-if">!noCreate and canCreateTemplate</attribute>
</xpath>
</t>


</templates>
17 changes: 17 additions & 0 deletions agreement_legal/static/src/xml/agreement_list_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>
<t
t-name="agreement_legal.ListView"
t-inherit="web.ListView.Buttons"
t-inherit-mode="primary"
>
<xpath expr="//div[hasclass('o_list_buttons')]" position="attributes">
<attribute name="t-if">canCreateTemplate</attribute>
</xpath>
<xpath expr="//div[hasclass('o_list_buttons')]" position="after">
<t t-call="agreement_legal.TemplateButton" />
</xpath>
</t>


</templates>
15 changes: 15 additions & 0 deletions agreement_legal/static/src/xml/agreement_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates>

<t t-name="agreement_legal.TemplateButton">
<button
type="button"
t-if="!canCreateTemplate"
t-on-click="onClickCreateFromTemplate"
class="create_agreement_from_template btn btn-primary mx-1"
>
Create From Template
</button>
</t>

</templates>
12 changes: 5 additions & 7 deletions agreement_legal/tests/test_agreement.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@ def test_read_group_stage_ids(self):

# Test fields_view_get
def test_agreement_fields_view_get(self):
res = self.env["agreement"].fields_view_get(
res = self.env["agreement"].get_view(
view_id=self.ref("agreement_legal.partner_agreement_form_view"),
view_type="form",
)
doc = etree.XML(res["arch"])
field = doc.xpath("//field[@name='partner_contact_id']")
self.assertEqual(
field[0].get("modifiers", ""), '{"readonly": [["readonly", "=", true]]}'
)
self.assertEqual(field[0].get("readonly", ""), "readonly")

def test_action_create_new_version(self):
self.test_agreement.create_new_version()
Expand All @@ -125,10 +123,10 @@ def test_cron(self):
self.agreement_type.write(
{"review_user_id": self.env.user.id, "review_days": 0}
)
self.agreement_type.flush()
self.agreement_type.flush_recordset()
self.test_agreement.write({"agreement_type_id": self.agreement_type.id})
self.test_agreement.flush()
self.test_agreement.refresh()
self.test_agreement.flush_recordset()
self.test_agreement.invalidate_recordset()
self.assertFalse(
self.env["mail.activity"].search_count(
[
Expand Down
Loading

0 comments on commit cddeef9

Please sign in to comment.