Skip to content

Commit

Permalink
Pre-commit tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon authored and ecino committed Apr 20, 2023
1 parent 30c5208 commit c49e51e
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 28 deletions.
3 changes: 1 addition & 2 deletions partner_tag_smart_assignation/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Smart Tagger",
"summary": "Smart tagger, module to have smart tags who " "update themselves alone",
"version": "14.0.1.0.0",
"category": "Other",
"summary": "Smart tagger, module to have smart tags who " "update themselves alone",
"sequence": 150,
"author": "Compassion CH, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/partner-contact",
Expand Down
18 changes: 8 additions & 10 deletions partner_tag_smart_assignation/models/res_partner_category.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Copyright (C) 2019 Compassion CH (http://www.compassion.ch)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import datetime
from odoo import models, fields, api
from datetime import datetime

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


class ResPartnerCategory(models.Model):
_inherit = "res.partner.category"

tag_filter_condition_id = fields.Many2one(
"ir.filters", "Domain filter"
)
tag_filter_condition_id = fields.Many2one("ir.filters", "Domain filter")
smart = fields.Boolean(
help="Enable this to automatically assign the category on partners "
"matching a given filter domain or SQL query."
Expand Down Expand Up @@ -42,9 +41,7 @@ class ResPartnerCategory(models.Model):
"partner_id",
)

tagged_partner_count = fields.Integer(
compute="_compute_number_tags", stored=True
)
tagged_partner_count = fields.Integer(compute="_compute_number_tags", stored=True)

@api.model
def create(self, vals):
Expand All @@ -70,7 +67,8 @@ def check_condition(self):
model_link = self.env[me.tag_filter_condition_id.model_id]
if me.tag_filter_partner_field not in model_link:
raise ValidationError(
"The chosen model has no field %s" % me.tag_filter_partner_field
_("The chosen model has no field %s")
% me.tag_filter_partner_field
)

@api.constrains("tag_filter_sql_query")
Expand All @@ -85,7 +83,7 @@ def check_sql_query(self):
or not self.env["res.partner"].browse(row[0]).exists()
):
raise ValidationError(
"The SQL query should only return partner ids"
_("The SQL query should only return partner ids")
)

def update_partner_tags(self):
Expand Down
9 changes: 4 additions & 5 deletions partner_tag_smart_assignation/tests/test_smart_tagger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from odoo.tests.common import SavepointCase
import logging

from odoo.tests.common import SavepointCase

logger = logging.getLogger(__name__)


Expand All @@ -19,8 +20,6 @@ def setUpClass(cls):
cls.partners = (
michel_fletcher + chao_wang + david_simpson + john_m_brown + charlie_bernard
)
cls.o_partners = chao_wang + david_simpson + john_m_brown
cls.non_o_partners = michel_fletcher + charlie_bernard
cls.michel_fletcher = michel_fletcher

def create_condition(self):
Expand Down Expand Up @@ -63,10 +62,10 @@ def test_create_tag(self):
Tag all partners which have the letter 'o' in the name.
"""
smart_tag = self.create_tag()
for partner in self.o_partners:
for partner in self.partners.filtered(lambda t: "o" in t.name):
self.assertTrue(partner in smart_tag.partner_ids)

for partner in self.non_o_partners:
for partner in self.partners.filtered(lambda t: "o" not in t.name):
self.assertFalse(partner in smart_tag.partner_ids)

for partner in smart_tag.partner_ids:
Expand Down
46 changes: 35 additions & 11 deletions partner_tag_smart_assignation/views/smart_tagger_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,63 @@
<record id="view_smart_tagger_tree" model="ir.ui.view">
<field name="name">Smart Tags</field>
<field name="model">res.partner.category</field>
<field name="inherit_id" ref="base.view_partner_category_list"/>
<field name="inherit_id" ref="base.view_partner_category_list" />
<field name="arch" type="xml">
<field name="display_name" position="after">
<field name="smart"/>
<field name="smart" />
</field>
</field>
</record>

<record id="view_smart_tagger_form" model="ir.ui.view">
<field name="name">Smart Tags</field>
<field name="model">res.partner.category</field>
<field name="inherit_id" ref="base.view_partner_category_form"/>
<field name="inherit_id" ref="base.view_partner_category_form" />
<field name="arch" type="xml">
<xpath expr="//group[1]" position="before">
<div class="oe_button_box" name="button_box">
<button type='object' name='open_tags' class="oe_stat_button" icon="fa-female">
<field name="tagged_partner_count" readonly="1" widget="statinfo" string="Partners"/>
<button
type='object'
name='open_tags'
class="oe_stat_button"
icon="fa-female"
>
<field
name="tagged_partner_count"
readonly="1"
widget="statinfo"
string="Partners"
/>
</button>
</div>
</xpath>
<field name="parent_id" position="after">
<field name="smart"/>
<field name="tag_filter_join_operator" attrs="{'invisible': [('smart', '=', False)],}"/>
<field name="tag_filter_condition_id" attrs="{'invisible': [('smart', '=', False)],}" context="{'default_model_id':'res.partner'}"/>
<field name="tag_filter_partner_field" attrs="{'invisible': ['|', ('smart', '=', False), ('tag_filter_condition_id', '=', False)],}"/>
<field name="tag_filter_sql_query" attrs="{'invisible': [('smart', '=', False)],}" widget="ace"/>
<field name="smart" />
<field
name="tag_filter_join_operator"
attrs="{'invisible': [('smart', '=', False)],}"
/>
<field
name="tag_filter_condition_id"
attrs="{'invisible': [('smart', '=', False)],}"
context="{'default_model_id':'res.partner'}"
/>
<field
name="tag_filter_partner_field"
attrs="{'invisible': ['|', ('smart', '=', False), ('tag_filter_condition_id', '=', False)],}"
/>
<field
name="tag_filter_sql_query"
attrs="{'invisible': [('smart', '=', False)],}"
widget="ace"
/>
</field>
</field>
</record>

<record model="ir.actions.server" id="event_smart_tagger_update_action">
<field name="name">Update Smart Tagger</field>
<field name="binding_model_id" ref="model_res_partner_category"/>
<field name="binding_model_id" ref="model_res_partner_category" />
<field name="model_id" ref="model_res_partner_category" />
<field name="state">code</field>
<field name="code">
Expand Down
6 changes: 6 additions & 0 deletions setup/partner_tag_smart_assignation/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit c49e51e

Please sign in to comment.