Skip to content

Commit

Permalink
[MIG] partner_stage_only_confirmed: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yankinmax committed Mar 26, 2024
1 parent 5bbf5db commit b90d86f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
1 change: 1 addition & 0 deletions partner_stage_only_confirmed/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Contributors
------------

- Silvio Gregorini <silvio.gregorini@camptocamp.com>
- Maksym Yankin <maksym.yankin@camptocamp.com>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion partner_stage_only_confirmed/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"author": "Odoo Community Association (OCA), Camptocamp",
"website": "https://github.com/OCA/partner-contact",
"category": "Partner Management",
"version": "12.0.1.0.0",
"version": "17.0.1.0.0",
"license": "AGPL-3",
"depends": ["partner_stage"],
"installable": True,
Expand Down
48 changes: 26 additions & 22 deletions partner_stage_only_confirmed/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,35 @@ class Base(models.AbstractModel):
_inherit = "base"

@api.model
def fields_view_get(self, *args, **kwargs):
def get_view(self, view_id=None, view_type="form", **options):
# OVERRIDE: display only confirmed partners on Many2one fields related
# to ``res.partner`` on form views.
res = super().fields_view_get(*args, **kwargs)
if res["type"] == "form" and self._filter_only_confirmed():
res = super().get_view(view_id, view_type, **options)

Check warning on line 16 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L16

Added line #L16 was not covered by tests
if view_type == "form" and self._filter_only_confirmed():
doc = etree.XML(res["arch"])

Check warning on line 18 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L18

Added line #L18 was not covered by tests
for fname, fvalues in tuple(res["fields"].items()):
ftype, frel = fvalues.get("type"), fvalues.get("relation")
if (ftype, frel) != ("many2one", "res.partner"):
continue
for node in doc.xpath("//field[@name='%s']" % fname):
domain = node.get("domain")
if not domain:
domain = "[('state', '=', 'confirmed')]"
elif isinstance(domain, str):
if domain in ("", "[]"):
domain = "[('state', '=', 'confirmed')]"
else:
domain = domain[:-1]
domain += ", ('state', '=', 'confirmed')]"
else:
domain = list(domain)
domain.append(("state", "=", "confirmed"))
domain = str(domain)
node.set("domain", domain)
for model_name, model_fields in res["models"].items():
for fname in model_fields:
model = self.env[model_name]
field_obj = model._fields.get(fname)

Check warning on line 22 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L21-L22

Added lines #L21 - L22 were not covered by tests
if field_obj:
ftype, fcomodel_name = field_obj.type, field_obj.comodel_name

Check warning on line 24 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L24

Added line #L24 was not covered by tests
if (ftype, fcomodel_name) != ("many2one", "res.partner"):
continue

Check warning on line 26 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L26

Added line #L26 was not covered by tests
for node in doc.xpath("//field[@name='%s']" % fname):
domain = node.get("domain")

Check warning on line 28 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L28

Added line #L28 was not covered by tests
if not domain:
domain = "[('state', '=', 'confirmed')]"

Check warning on line 30 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L30

Added line #L30 was not covered by tests
elif isinstance(domain, str):
if domain in ("", "[]"):
domain = "[('state', '=', 'confirmed')]"

Check warning on line 33 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L33

Added line #L33 was not covered by tests
else:
domain = domain[:-1]
domain += ", ('state', '=', 'confirmed')]"

Check warning on line 36 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L35-L36

Added lines #L35 - L36 were not covered by tests
else:
domain = list(domain)
domain.append(("state", "=", "confirmed"))
domain = str(domain)
node.set("domain", domain)
res["arch"] = etree.tostring(doc)
return res

Check warning on line 43 in partner_stage_only_confirmed/models/base.py

View check run for this annotation

Codecov / codecov/patch

partner_stage_only_confirmed/models/base.py#L38-L43

Added lines #L38 - L43 were not covered by tests

Expand Down
1 change: 1 addition & 0 deletions partner_stage_only_confirmed/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Silvio Gregorini \<<silvio.gregorini@camptocamp.com>\>
- Maksym Yankin \<<maksym.yankin@camptocamp.com>\>
1 change: 1 addition & 0 deletions partner_stage_only_confirmed/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<ul class="simple">
<li>Silvio Gregorini &lt;<a class="reference external" href="mailto:silvio.gregorini&#64;camptocamp.com">silvio.gregorini&#64;camptocamp.com</a>&gt;</li>
<li>Maksym Yankin &lt;<a class="reference external" href="mailto:maksym.yankin&#64;camptocamp.com">maksym.yankin&#64;camptocamp.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down

0 comments on commit b90d86f

Please sign in to comment.