Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] edi: edi.conf add btn to view partners #1106

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions edi_oca/models/edi_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime

import pytz
from psycopg2.extensions import AsIs

from odoo import _, api, exceptions, fields, models
from odoo.tools import DotDict, safe_eval
Expand Down Expand Up @@ -198,3 +199,23 @@
backend_ids.append(False)
domain.append(("backend_id", "in", backend_ids))
return self.filtered_domain(domain)

def action_view_partners(self):
# TODO: add tests
partner_model = self.env["res.partner"]
partner_ids = set()

Check warning on line 206 in edi_oca/models/edi_configuration.py

View check run for this annotation

Codecov / codecov/patch

edi_oca/models/edi_configuration.py#L205-L206

Added lines #L205 - L206 were not covered by tests
# Find partners linked to this conf no matter which field
for field in partner_model._fields.values():
if field.type == "many2many" and field.comodel_name == self._name:
query = "SELECT DISTINCT(partner_id) FROM %(table)s WHERE conf_id=%(conf_id)s"
self.env.cr.execute(

Check warning on line 211 in edi_oca/models/edi_configuration.py

View check run for this annotation

Codecov / codecov/patch

edi_oca/models/edi_configuration.py#L210-L211

Added lines #L210 - L211 were not covered by tests
query, {"table": AsIs(field.relation), "conf_id": self.id}
)
partner_ids.update([r[0] for r in self.env.cr.fetchall()])
return {

Check warning on line 215 in edi_oca/models/edi_configuration.py

View check run for this annotation

Codecov / codecov/patch

edi_oca/models/edi_configuration.py#L215

Added line #L215 was not covered by tests
"type": "ir.actions.act_window",
"name": _("Partners"),
"res_model": "res.partner",
"view_mode": "tree,form",
"domain": [("id", "in", list(partner_ids))],
}
9 changes: 9 additions & 0 deletions edi_oca/views/edi_configuration_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
<field name="arch" type="xml">
<form string="EDI Configuration">
<sheet>
<div class="oe_button_box" name="button_box">
<button
type="object"
name="action_view_partners"
class="oe_stat_button"
string="Partners"
icon="fa-eye"
/>
</div>
<field name="active" invisible="1" />
<widget
name="web_ribbon"
Expand Down
2 changes: 1 addition & 1 deletion edi_sale_oca/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<record id="view_partner_form" model="ir.ui.view">
<field name="name">res.partner.view.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="inherit_id" ref="edi_oca.view_partner_form" />
<field name="arch" type="xml">
<group name="edi_main" position="after">
<group name="sale" string="Sale">
Expand Down
Loading