Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
“dedinside1337” committed Sep 25, 2024
1 parent 9025591 commit afc6281
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 66 deletions.
8 changes: 4 additions & 4 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ exclude = ["setup/*"]
[format]
exclude = ["setup/*"]

[per-file-ignores]
[lint.per-file-ignores]
"__init__.py" = ["F401", "I001"] # ignore unused and unsorted imports in __init__.py
"__manifest__.py" = ["B018"] # useless expression

[isort]
[lint.isort]
section-order = ["future", "standard-library", "third-party", "odoo", "odoo-addons", "first-party", "local-folder"]

[isort.sections]
[lint.isort.sections]
"odoo" = ["odoo"]
"odoo-addons" = ["odoo.addons"]

[mccabe]
[lint.mccabe]
max-complexity = 16
22 changes: 15 additions & 7 deletions automation_oca/models/automation_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ class AutomationConfiguration(models.Model):
tag_ids = fields.Many2many("automation.tag")
company_id = fields.Many2one("res.company")
domain = fields.Char(
required=True, default="[]", help="Filter to apply", compute="_compute_domain"
required=True,
default="[]",
help="Filter to apply",
compute="_compute_domain",
)
editable_domain = fields.Char(
required=True,
default="[]",
help="Filter to apply",
)
editable_domain = fields.Char(required=True, default="[]", help="Filter to apply")
model_id = fields.Many2one(
"ir.model",
domain=[("is_mail_thread", "=", True)],
Expand Down Expand Up @@ -185,7 +192,8 @@ def cron_automation(self):

def _get_automation_records_to_create(self):
"""
We will find all the records that fulfill the domain but don't have a record created.
We will find all the records that fulfill
the domain but don't have a record created.
Also, we need to check by autencity field if defined.
In order to do this, we will add some extra joins on the query of the domain
Expand Down Expand Up @@ -230,10 +238,10 @@ def _get_automation_records_to_create(self):
", ".join([f'MIN("{next(iter(query._tables))}".id) as id']),
from_clause,
where_clause or "TRUE",
(" ORDER BY %s" % self.order) if query.order else "",
(" LIMIT %d" % self.limit) if query.limit else "",
(" OFFSET %d" % self.offset) if query.offset else "",
"%s.%s" % (Record._table, self.field_id.name),
(f" ORDER BY {self.order}") if query.order else "",
(f" LIMIT {self.limit}") if query.limit else "",
(f" OFFSET {self.offset}") if query.offset else "",
f"{Record._table}.{self.field_id.name}",
)
else:
query_str, params = query.select()
Expand Down
3 changes: 2 additions & 1 deletion automation_oca/models/automation_configuration_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ def _trigger_type_selection(self):
@api.model
def _trigger_types(self):
"""
This function will return a dictionary that map trigger_types to its configurations.
This function will return a dictionary that map
trigger_types to its configurations.
Each trigger_type can contain:
- name (Required field)
- step type: List of step types that succeed after this.
Expand Down
2 changes: 1 addition & 1 deletion automation_oca/models/automation_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _compute_state(self):
def _compute_resource_ref(self):
for record in self:
if record.model and record.model in self.env:
record.resource_ref = "%s,%s" % (record.model, record.res_id or 0)
record.resource_ref = f"{record.model},{record.res_id or 0}"
else:
record.resource_ref = None

Expand Down
3 changes: 1 addition & 2 deletions automation_oca/models/automation_record_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ def _get_mail_tracking_token(self):
def _get_mail_tracking_url(self):
return werkzeug.urls.url_join(
self.get_base_url(),
"automation_oca/track/%s/%s/blank.gif"
% (self.id, self._get_mail_tracking_token()),
f"automation_oca/track/{self.id}/{self._get_mail_tracking_token()}/blank.gif",
)

def _run_mail_context(self):
Expand Down
3 changes: 1 addition & 2 deletions automation_oca/models/mail_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def _prepare_outgoing_body(self):
if parsed.scheme.startswith("http") and parsed.path.startswith("/r/"):
new_href = href.replace(
url,
"%s/au/%s/%s"
% (url, str(self.automation_record_step_id.id), token),
f"{url}/au/{str(self.automation_record_step_id.id)}/{token}",
)
body = body.replace(
markupsafe.Markup(href), markupsafe.Markup(new_href)
Expand Down
8 changes: 2 additions & 6 deletions automation_oca/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class MailThread(models.AbstractModel):
@api.model
def _routing_handle_bounce(self, email_message, message_dict):
"""We want to mark the bounced email"""
result = super(MailThread, self)._routing_handle_bounce(
email_message, message_dict
)
result = super()._routing_handle_bounce(email_message, message_dict)
bounced_msg_ids = message_dict.get("bounced_msg_ids")
if bounced_msg_ids:
self.env["automation.record.step"].search(
Expand All @@ -36,9 +34,7 @@ def _message_route_process(self, message, message_dict, routes):
)
records._set_mail_open()
records._set_mail_reply()
return super(MailThread, self)._message_route_process(
message, message_dict, routes
)
return super()._message_route_process(message, message_dict, routes)

@api.model
def get_automation_access(self, doc_ids, operation, model_name=False):
Expand Down
3 changes: 2 additions & 1 deletion automation_oca/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def setUpClass(cls):
"model_id": cls.env.ref("base.model_res_partner").id,
"subject": "Subject",
"partner_to": "{{ object.id }}",
"body_html": 'My template <a href="https://www.twitter.com" /> with link',
"body_html": 'My template <a href="https://www.twitter.com" /> \
with link',
}
)
cls.partner_01 = cls.env["res.partner"].create(
Expand Down
5 changes: 2 additions & 3 deletions automation_oca/tests/test_automation_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ def test_child_execution_filters(self):
In this case, the task 1_1_1 will only be generated for partner 1 and task 1_2_1
for partner 2
"""
self.configuration.editable_domain = "[('id', 'in', [%s, %s])]" % (
self.partner_01.id,
self.partner_02.id,
self.configuration.editable_domain = (
f"[('id', 'in', [{self.partner_01.id}, {self.partner_02.id}])]"
)

activity_1 = self.create_server_action()
Expand Down
2 changes: 1 addition & 1 deletion automation_oca/tests/test_automation_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ def test_is_test_behavior(self):
)
) as f:
self.assertTrue(f.resource_ref)
f.resource_ref = "%s,%s" % (self.partner_01._name, self.partner_01.id)
f.resource_ref = f"{self.partner_01._name},{self.partner_01.id}"
wizard = f.save()
wizard_action = wizard.test_record()
record = self.env[wizard_action["res_model"]].browse(wizard_action["res_id"])
Expand Down
50 changes: 13 additions & 37 deletions automation_oca/tests/test_automation_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
<head>=20
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8" />
</head>=20
<body style=3D"margin: 0; padding: 0; background: #ffffff;-webkit-text-size-adjust: 100%;">=20
<body style=3D"margin: 0; padding: 0; background: #ffffff;-webkit-text-size-adjust:
100%;">=20
<p>I would gladly answer to your mass mailing !</p>
Expand Down Expand Up @@ -284,7 +285,8 @@ def test_open_wrong_code(self):

def test_no_open(self):
"""
Now we will check the not open validation when it is not opened (should be executed)
Now we will check the not open validation when it is not opened
(should be executed)
"""
activity = self.create_mail_activity()
child_activity = self.create_mail_activity(
Expand Down Expand Up @@ -384,12 +386,7 @@ def test_click(self):
)
self.assertTrue(tracker)
self.url_open(
"/r/%s/au/%s/%s"
% (
tracker.code,
record_activity.id,
record_activity._get_mail_tracking_token(),
)
f"/r/{tracker.code}/au/{record_activity.id}/{record_activity._get_mail_tracking_token()}"
)
self.assertEqual("open", record_activity.mail_status)
self.assertEqual(
Expand All @@ -414,12 +411,7 @@ def test_click(self):
self.assertEqual(1, self.configuration.click_count)
# Now we will check that a second click does not generate a second log
self.url_open(
"/r/%s/au/%s/%s"
% (
tracker.code,
record_activity.id,
record_activity._get_mail_tracking_token(),
)
f"/r/{tracker.code}/au/{record_activity.id}/{record_activity._get_mail_tracking_token()}"
)
self.assertEqual(
1,
Expand Down Expand Up @@ -461,24 +453,13 @@ def test_click_wrong_url(self):
[("url", "=", "https://www.twitter.com")]
)
self.assertTrue(tracker)
self.url_open(
"/r/%s/au/%s/1234"
% (
tracker.code,
record_activity.id,
)
)
self.url_open(f"/r/{tracker.code}/au/{record_activity.id}/1234")
self.assertEqual("sent", record_activity.mail_status)
self.assertFalse(record_child_activity.scheduled_date)
# Now we check the case where the code is not found
tracker.unlink()
self.url_open(
"/r/%s/au/%s/%s"
% (
tracker.code,
record_activity.id,
record_activity._get_mail_tracking_token(),
)
f"/r/{tracker.code}/au/{record_activity.id}/{record_activity._get_mail_tracking_token()}"
)
self.assertEqual("sent", record_activity.mail_status)
self.assertFalse(record_child_activity.scheduled_date)
Expand All @@ -491,7 +472,7 @@ def test_no_click(self):
child_activity = self.create_mail_activity(
parent_id=activity.id, trigger_type="mail_not_clicked"
)
self.configuration.editable_domain = "[('id', '=', %s)]" % self.partner_01.id
self.configuration.editable_domain = f"[('id', '=', {self.partner_01.id})]"
self.configuration.start_automation()
self.env["automation.configuration"].cron_automation()
with self.mock_mail_gateway():
Expand Down Expand Up @@ -520,7 +501,7 @@ def test_no_click_rejected(self):
child_activity = self.create_mail_activity(
parent_id=activity.id, trigger_type="mail_not_clicked"
)
self.configuration.editable_domain = "[('id', '=', %s)]" % self.partner_01.id
self.configuration.editable_domain = f"[('id', '=', {self.partner_01.id})]"
self.configuration.start_automation()
self.env["automation.configuration"].cron_automation()
with self.mock_mail_gateway():
Expand All @@ -542,12 +523,7 @@ def test_no_click_rejected(self):
[("url", "=", "https://www.twitter.com")]
)
self.url_open(
"/r/%s/au/%s/%s"
% (
tracker.code,
record_activity.id,
record_activity._get_mail_tracking_token(),
)
f"/r/{tracker.code}/au/{record_activity.id}/{record_activity._get_mail_tracking_token()}"
)
self.env["automation.record.step"]._cron_automation_steps()
self.assertEqual("rejected", record_child_activity.state)
Expand All @@ -557,15 +533,15 @@ def test_is_test_behavior(self):
We want to ensure that no mails are sent on tests
"""
self.create_mail_activity()
self.configuration.editable_domain = "[('id', '=', %s)]" % self.partner_01.id
self.configuration.editable_domain = f"[('id', '=', {self.partner_01.id})]"
with Form(
self.env["automation.configuration.test"].with_context(
default_configuration_id=self.configuration.id,
defaul_model=self.configuration.model,
)
) as f:
self.assertTrue(f.resource_ref)
f.resource_ref = "%s,%s" % (self.partner_01._name, self.partner_01.id)
f.resource_ref = f"{self.partner_01._name},{self.partner_01.id}"
wizard = f.save()
wizard_action = wizard.test_record()
record = self.env[wizard_action["res_model"]].browse(wizard_action["res_id"])
Expand Down
2 changes: 1 addition & 1 deletion automation_oca/wizards/automation_configuration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _compute_resource_ref(self):
for record in self:
if record.model and record.model in self.env:
res = self.env[record.model].search([], limit=1)
record.resource_ref = "%s,%s" % (record.model, res.id)
record.resource_ref = f"{record.model},{res.id}"
else:
record.resource_ref = None

Check warning on line 37 in automation_oca/wizards/automation_configuration_test.py

View check run for this annotation

Codecov / codecov/patch

automation_oca/wizards/automation_configuration_test.py#L37

Added line #L37 was not covered by tests

Expand Down

0 comments on commit afc6281

Please sign in to comment.