Skip to content

Commit

Permalink
[MIG] partner_multi_relation: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BT-mchechlacz committed Nov 15, 2024
1 parent a6b2d03 commit 63bed45
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 92 deletions.
52 changes: 27 additions & 25 deletions partner_multi_relation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Partner Relations
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github
:target: https://github.com/OCA/partner-contact/tree/17.0/partner_multi_relation
:target: https://github.com/OCA/partner-contact/tree/18.0/partner_multi_relation
:alt: OCA/partner-contact
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/partner-contact-17-0/partner-contact-17-0-partner_multi_relation
:target: https://translation.odoo-community.org/projects/partner-contact-18-0/partner-contact-18-0-partner_multi_relation
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/partner-contact&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -66,14 +66,14 @@ Partner Types
The Partner Type fields allow to constrain what type of partners can be
used on the left and right sides of the relation.

- In the example above, the assistant-relation only makes sense between
people, so you would choose 'Person' for both partner types.
- In the example above, the assistant-relation only makes sense between
people, so you would choose 'Person' for both partner types.

|image3|

- For a relation 'is a competitor of', both sides would be companies.
- A relation 'has worked for' should have persons on the left side and
companies on the right side.
- For a relation 'is a competitor of', both sides would be companies.
- A relation 'has worked for' should have persons on the left side and
companies on the right side.

If you leave these fields empty, the relation is applicable to all types
of partners.
Expand Down Expand Up @@ -125,10 +125,10 @@ type.

4 possible behaviors are available:

- Do not allow change that will result in invalid relations
- Allow existing relations that do not fit changed conditions
- End relations per today, if they do not fit changed conditions
- Delete relations that do not fit changed conditions
- Do not allow change that will result in invalid relations
- Allow existing relations that do not fit changed conditions
- End relations per today, if they do not fit changed conditions
- Delete relations that do not fit changed conditions

Searching Partners With Relations
---------------------------------
Expand Down Expand Up @@ -179,7 +179,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/partner-contact/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_multi_relation%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_multi_relation%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -195,18 +195,20 @@ Authors
Contributors
------------

- Holger Brunn <[email protected]>
- Stefan Rijnhart <[email protected]>
- Ronald Portier <[email protected]>
- Sandy Carter <[email protected]>
- Bruno Joliveau <[email protected]>
- Adriana Ierfino <[email protected]>
- Numigi (tm) and all its contributors (https://bit.ly/numigiens)
- Radovan Skolnik <[email protected]>, KEMA SK s.r.o.
(https://www.kema.sk)
- `DynApps NV <https://www.dynapps.be>`__:
- Holger Brunn <[email protected]>
- Stefan Rijnhart <[email protected]>
- Ronald Portier <[email protected]>
- Sandy Carter <[email protected]>
- Bruno Joliveau <[email protected]>
- Adriana Ierfino <[email protected]>
- Numigi (tm) and all its contributors (https://bit.ly/numigiens)
- Radovan Skolnik <[email protected]>, KEMA SK s.r.o.
(https://www.kema.sk)
- `DynApps NV <https://www.dynapps.be>`__:

- Raf Ven
- Raf Ven

- Marcin Chechłacz <[email protected]>

Maintainers
-----------
Expand All @@ -221,6 +223,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/17.0/partner_multi_relation>`_ project on GitHub.
This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/18.0/partner_multi_relation>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion partner_multi_relation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Partner Relations",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"author": "Therp BV,Camptocamp,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/partner-contact",
"complexity": "normal",
Expand Down
4 changes: 2 additions & 2 deletions partner_multi_relation/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import numbers

from odoo import _, api, exceptions, fields, models
from odoo import api, exceptions, fields, models
from odoo.osv.expression import FALSE_LEAF, OR, is_leaf


Expand Down Expand Up @@ -75,7 +75,7 @@ def _search_relation_type_id(self, operator, value):
)
if operator not in SUPPORTED_OPERATORS:
raise exceptions.ValidationError(
_('Unsupported search operator "%s"') % operator
self.env._('Unsupported search operator "%s"') % operator
)
type_selection_model = self.env["res.partner.relation.type.selection"]
relation_type_selection = []
Expand Down
24 changes: 14 additions & 10 deletions partner_multi_relation/models/res_partner_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# pylint: disable=api-one-deprecated
"""Store relations (connections) between partners."""

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import ValidationError


Expand Down Expand Up @@ -65,7 +65,7 @@ def _check_dates(self):
and record.date_start > record.date_end
):
raise ValidationError(
_("The starting date cannot be after the ending date.")
self.env._("The starting date cannot be after the ending date.")
)

@api.constrains("left_partner_id", "type_id")
Expand All @@ -92,19 +92,21 @@ def _check_partner(self, side):
"""
for record in self:
assert side in ["left", "right"]
ptype = getattr(record.type_id, "contact_type_%s" % side)
partner = getattr(record, "%s_partner_id" % side)
ptype = getattr(record.type_id, f"contact_type_{side}")
partner = getattr(record, f"{side}_partner_id")
if (ptype == "c" and not partner.is_company) or (
ptype == "p" and partner.is_company
):
raise ValidationError(
_("The %s partner is not applicable for this " "relation type.")
% side
self.env._(
f"The {side} partner is not applicable for this "
f"relation type."
)
)
category = getattr(record.type_id, "partner_category_%s" % side)
category = getattr(record.type_id, f"partner_category_{side}")
if category and category.id not in partner.category_id.ids:
raise ValidationError(
_(
self.env._(
"The {partner} partner does not have category {category}."
).format(partner=side, category=category.name)
)
Expand All @@ -119,7 +121,7 @@ def _check_not_with_self(self):
if record.left_partner_id == record.right_partner_id:
if not (record.type_id and record.type_id.allow_self):
raise ValidationError(
_("Partners cannot have a relation with themselves.")
self.env._("Partners cannot have a relation with themselves.")
)

@api.constrains(
Expand Down Expand Up @@ -154,5 +156,7 @@ def _check_relation_uniqueness(self):
]
if record.search(domain):
raise ValidationError(
_("There is already a similar relation with overlapping dates")
self.env._(
"There is already a similar relation with overlapping dates"
)
)
26 changes: 16 additions & 10 deletions partner_multi_relation/models/res_partner_relation_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from psycopg2.extensions import AsIs

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import MissingError, ValidationError
from odoo.tools import drop_view_if_exists

Expand Down Expand Up @@ -216,7 +216,10 @@ def _search_any_partner_id(self, operator, value):
)
def _compute_display_name(self):
for record in self:
record.display_name = f"{record.this_partner_id.name} {record.type_selection_id.display_name} {record.other_partner_id.name}"
record.display_name = (
f"{record.this_partner_id.name} {record.type_selection_id.display_name}"
f" {record.other_partner_id.name}"
)

@api.onchange("type_selection_id")
def onchange_type_selection_id(self):
Expand All @@ -234,14 +237,15 @@ def check_partner_domain(partner, partner_domain, side):
partner_model = self.env["res.partner"]
partners_found = partner_model.search(test_domain, limit=1)
if not partners_found:
warning["title"] = _("Error!")
warning["title"] = self.env._("Error!")
if partner:
warning["message"] = (
_("%s partner incompatible with relation type.") % side.title()
self.env._("%s partner incompatible with relation type.")
% side.title()
)
else:
warning["message"] = (
_("No %s partner available for relation type.") % side
self.env._("No %s partner available for relation type.") % side
)
return warning

Expand Down Expand Up @@ -286,10 +290,12 @@ def check_partner_domain(partner, partner_domain, side):
)
if this_partner_id:
this_partner = partner_model.browse(this_partner_id)
warning = check_partner_domain(this_partner, this_partner_domain, _("this"))
warning = check_partner_domain(
this_partner, this_partner_domain, self.env._("this")
)
if not warning and other_partner_domain:
warning = check_partner_domain(
self.other_partner_id, other_partner_domain, _("other")
self.other_partner_id, other_partner_domain, self.env._("other")
)
if warning:
result["warning"] = warning
Expand All @@ -314,8 +320,8 @@ def check_type_selection_domain(type_selection_domain):
type_model = self.env["res.partner.relation.type.selection"]
types_found = type_model.search(test_domain, limit=1)
if not types_found:
warning["title"] = _("Error!")
warning["message"] = _(
warning["title"] = self.env._("Error!")
warning["message"] = self.env._(
"Relation type incompatible with selected partner(s)."
)
return warning
Expand Down Expand Up @@ -444,7 +450,7 @@ def create(self, vals_list):
type_selection = self._get_type_selection_from_vals(vals)
if not type_selection: # Should not happen
raise ValidationError(
_("No relation type specified in vals: %s.") % vals
self.env._("No relation type specified in vals: %s.") % vals
)
corrected_vals.append(self._correct_vals(vals, type_selection))
type_selections.append(type_selection)
Expand Down
41 changes: 25 additions & 16 deletions partner_multi_relation/models/res_partner_relation_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
"""Define the type of relations that can exist between partners."""

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import ValidationError
from odoo.osv.expression import AND, OR

HANDLE_INVALID_ONCHANGE = [
("restrict", _("Do not allow change that will result in invalid relations")),
("ignore", _("Allow existing relations that do not fit changed conditions")),
("end", _("End relations per today, if they do not fit changed conditions")),
("delete", _("Delete relations that do not fit changed conditions")),
(
"restrict",
"Do not allow change that will result in invalid relations",
),
(
"ignore",
"Allow existing relations that do not fit changed conditions",
),
(
"end",
"End relations per today, if they do not fit changed conditions",
),
("delete", "Delete relations that do not fit changed conditions"),
]


Expand Down Expand Up @@ -61,7 +70,7 @@ class ResPartnerRelationType(models.Model):
def get_partner_types(self):
"""A partner can be an organisation or an individual."""
# pylint: disable=no-self-use
return [("c", _("Organisation")), ("p", _("Person"))]
return [("c", self.env._("Organisation")), ("p", self.env._("Person"))]

@api.model
def _end_active_relations(self, relations):
Expand Down Expand Up @@ -90,26 +99,26 @@ def check_existing(self, vals):

def get_type_condition(vals, side):
"""Add if needed check for contact type."""
fieldname1 = "contact_type_%s" % side
fieldname2 = "%s_partner_id.is_company" % side
fieldname1 = f"contact_type_{side}"
fieldname2 = f"{side}_partner_id.is_company"
contact_type = fieldname1 in vals and vals[fieldname1] or False
if contact_type == "c":
# Records that are not companies are invalid:
return [(fieldname2, "=", False)]
if contact_type == "p":
# Records that are companies are invalid:
return [(fieldname2, "=", True)]
return []
return [(0, "=", 1)]

def get_category_condition(vals, side):
"""Add if needed check for partner category."""
fieldname1 = "partner_category_%s" % side
fieldname2 = "%s_partner_id.category_id" % side
fieldname1 = f"partner_category_{side}"
fieldname2 = f"{side}_partner_id.category_id"
category_id = fieldname1 in vals and vals[fieldname1] or False
if category_id:
# Records that do not have the specified category are invalid:
return [(fieldname2, "not in", [category_id])]
return []
return [(0, "=", 1)]

for this in self:
handling = (
Expand All @@ -119,7 +128,7 @@ def get_category_condition(vals, side):
)
if handling == "ignore":
continue
invalid_conditions = []
invalid_conditions = [(0, "=", 1)]
for side in ["left", "right"]:
invalid_conditions = OR(
[invalid_conditions, get_type_condition(vals, side)]
Expand All @@ -128,7 +137,7 @@ def get_category_condition(vals, side):
[invalid_conditions, get_category_condition(vals, side)]
)
if not invalid_conditions:
return
continue
# only look at relations for this type
invalid_domain = AND([[("type_id", "=", this.id)], invalid_conditions])
invalid_relations = relation_model.with_context(active_test=False).search(
Expand All @@ -137,7 +146,7 @@ def get_category_condition(vals, side):
if invalid_relations:
if handling == "restrict":
raise ValidationError(
_(
self.env._(
"There are already relations not satisfying the"
" conditions for partner type or category."
)
Expand Down Expand Up @@ -169,7 +178,7 @@ def _check_no_existing_reflexive_relations(self):
relations = relation_type._get_reflexive_relations()
if relations:
raise ValidationError(
_(
self.env._(
"Reflexivity could not be disabled for the relation "
"type {relation_type}. There are existing reflexive "
"relations defined for the following partners: "
Expand Down
1 change: 1 addition & 0 deletions partner_multi_relation/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
(<https://www.kema.sk>)
- [DynApps NV](https://www.dynapps.be):
- Raf Ven
- Marcin Chechłacz \<<[email protected]>\>
8 changes: 4 additions & 4 deletions partner_multi_relation/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
read_res_partner_relation,access_res_partner_relation,model_res_partner_relation,,1,0,0,0
read_res_partner_relation_all,access_res_partner_relation,model_res_partner_relation_all,,1,0,0,0
read_res_partner_relation_type,access_res_partner_relation_type,model_res_partner_relation_type,,1,0,0,0
read_res_partner_relation_type_selection,access_res_partner_relation_type,model_res_partner_relation_type_selection,,1,0,0,0
read_res_partner_relation,access_res_partner_relation,model_res_partner_relation,base.group_user,1,0,0,0
read_res_partner_relation_all,access_res_partner_relation,model_res_partner_relation_all,base.group_user,1,0,0,0
read_res_partner_relation_type,access_res_partner_relation_type,model_res_partner_relation_type,base.group_user,1,0,0,0
read_res_partner_relation_type_selection,access_res_partner_relation_type,model_res_partner_relation_type_selection,base.group_user,1,0,0,0
crud_res_partner_relation,access_res_partner_relation,model_res_partner_relation,base.group_partner_manager,1,1,1,1
crud_res_partner_relation_all,access_res_partner_relation,model_res_partner_relation_all,base.group_partner_manager,1,1,1,1
crud_res_partner_relation_type,access_res_partner_relation_type,model_res_partner_relation_type,sales_team.group_sale_manager,1,1,1,1
Loading

0 comments on commit 63bed45

Please sign in to comment.