Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
damdam-s committed Jan 31, 2025
1 parent 3953407 commit 0200181
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
1 change: 1 addition & 0 deletions mail_contact_type/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
],
"data": [
"security/ir.model.access.csv",
"views/account_move_send_view.xml",
"views/mail_compose_message_view.xml",
"views/mail_contact_type.xml",
"views/res_partner.xml",
Expand Down
34 changes: 15 additions & 19 deletions mail_contact_type/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ def contact_by_types(self, *codes):
]
)

def _get_name(self):
def _compute_display_name(self):
partner = self
name = super()._get_name()
name = super()._compute_display_name()

if (
not self._context.get("show_mail_contact_types")
Expand All @@ -60,33 +60,29 @@ def _get_name(self):

return f"{name} ({mail_contact_types_str})"

@property
def _order(self):
res = super()._order
if not self.env.context.get('show_mail_contact_types'):
return res
order_by_field = "display_name"
return '%s, %s' % (res, order_by_field) if res else order_by_field

@api.model
def _name_search(
self, name, args=None, operator="ilike", limit=100, name_get_uid=None
def name_search(
self, name, args=None, operator="ilike", limit=100
):
partners = super()._name_search(
name, args, operator=operator, limit=limit, name_get_uid=name_get_uid
partners = super().name_search(
name, args, operator=operator, limit=limit
)
if self._context.get("show_mail_contact_types"):
# unfortunately odoo base overwrite _name_search and force an *AND* operator
# between domain provide by `args` and other searching pattern added
# by that base module so here we are running an extra request to return
# all partners with those matching the contact type keeping
# same order as base
fields = [
field
for field in self._get_name_search_order_by_fields().split(",")
if field
]
fields.append("display_name")
partners = self.search(
expression.OR(
[
[("id", "in", partners)],
[("mail_contact_type_ids", "=ilike", name)],
]
),
limit=limit,
order=",".join(fields),
limit=limit
).ids
return partners
4 changes: 2 additions & 2 deletions mail_contact_type/tests/test_mail_contact_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
# @author Alexandre Galdeano <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase


class TestMailContactType(SavepointCase):
class TestMailContactType(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
20 changes: 20 additions & 0 deletions mail_contact_type/views/account_move_send_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2025 Foodles.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="account_move_send_form" model="ir.ui.view">
<field name="name">account move send show_mail_contact_types</field>
<field name="model">account.move.send</field>
<field name="inherit_id" ref="account.account_move_send_form" />
<field name="arch" type="xml">
<field name="mail_partner_ids" position="attributes">
<attribute name="context" operation="update">{
"show_mail_contact_types":1
}
</attribute>
</field>
</field>
</record>
</odoo>
9 changes: 3 additions & 6 deletions mail_contact_type/views/mail_compose_message_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@
<field name="inherit_id" ref="mail.email_compose_message_wizard_form" />
<field name="arch" type="xml">
<field name="partner_ids" position="attributes">
<attribute
name="context"
operation="python_dict"
key="show_mail_contact_types"
>
1
<attribute name="context" operation="update">{
"show_mail_contact_types":1
}
</attribute>
</field>
</field>
Expand Down

0 comments on commit 0200181

Please sign in to comment.