-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored 13.0 branch #1
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
base: 13.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
| from ..utils import convert_to_image, image_to_rgb, n_rgb_to_hex | ||
|
|
||
| URL_BASE = "/web_company_color/static/src/scss/" | ||
| URL_SCSS_GEN_TEMPLATE = URL_BASE + "custom_colors.%d.gen.scss" | ||
| URL_SCSS_GEN_TEMPLATE = f"{URL_BASE}custom_colors.%d.gen.scss" | ||
|
|
||
|
|
||
| class ResCompany(models.Model): | ||
|
|
@@ -96,7 +96,7 @@ def write(self, values): | |
|
|
||
| result = super().write(values) | ||
|
|
||
| if any([field in values for field in fields_to_check]): | ||
| if any(field in values for field in fields_to_check): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.scss_create_or_update_attachment() | ||
| else: | ||
| result = super().write(values) | ||
|
|
@@ -108,24 +108,24 @@ def _scss_get_sanitized_values(self): | |
| # This allow extend company_colors and only sanitize selected fields | ||
| # or add custom values | ||
| values = dict(self.company_colors or {}) | ||
| values.update( | ||
| { | ||
| "color_navbar_bg": (values.get("color_navbar_bg") or "$o-brand-odoo"), | ||
| "color_navbar_bg_hover": ( | ||
| values.get("color_navbar_bg_hover") | ||
| or "$o-navbar-inverse-link-hover-bg" | ||
| ), | ||
| "color_navbar_text": (values.get("color_navbar_text") or "#FFF"), | ||
| } | ||
| ) | ||
| values |= { | ||
| "color_navbar_bg": (values.get("color_navbar_bg") or "$o-brand-odoo"), | ||
| "color_navbar_bg_hover": ( | ||
| values.get("color_navbar_bg_hover") | ||
| or "$o-navbar-inverse-link-hover-bg" | ||
| ), | ||
| "color_navbar_text": (values.get("color_navbar_text") or "#FFF"), | ||
| } | ||
|
Comment on lines
-111
to
+118
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return values | ||
|
|
||
| def _scss_generate_content(self): | ||
| self.ensure_one() | ||
| # ir.attachment need files with content to work | ||
| if not self.company_colors: | ||
| return "// No Web Company Color SCSS Content\n" | ||
| return self.SCSS_TEMPLATE % self._scss_get_sanitized_values() | ||
| return ( | ||
| self.SCSS_TEMPLATE % self._scss_get_sanitized_values() | ||
| if self.company_colors | ||
| else "// No Web Company Color SCSS Content\n" | ||
| ) | ||
|
Comment on lines
-126
to
+128
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def scss_get_url(self): | ||
| self.ensure_one() | ||
|
|
@@ -149,6 +149,6 @@ def scss_create_or_update_attachment(self): | |
| if custom_attachment: | ||
| custom_attachment.sudo().write(values) | ||
| else: | ||
| values.update({"type": "binary", "mimetype": "text/scss"}) | ||
| values |= {"type": "binary", "mimetype": "text/scss"} | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| IrAttachmentObj.sudo().create(values) | ||
| self.env["ir.qweb"].sudo().clear_caches() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,7 @@ def normalize_vec3(vec3): | |
| rgb_sum = [0, 0, 0] | ||
| # Mix. image colors using addition method | ||
| RGBA_WHITE = (255, 255, 255, 255) | ||
| for i in range(0, height * width): | ||
| for i in range(height * width): | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| rgba = img.getpixel((i % width, i / width)) | ||
| if rgba[3] > 128 and rgba != RGBA_WHITE: | ||
| rgb_sum[0] += rgba[0] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,11 +20,11 @@ class ResUsers(models.Model): | |
| def _compute_channel_names(self): | ||
| for record in self: | ||
| res_id = record.id | ||
| record.notify_success_channel_name = "notify_success_%s" % res_id | ||
| record.notify_danger_channel_name = "notify_danger_%s" % res_id | ||
| record.notify_warning_channel_name = "notify_warning_%s" % res_id | ||
| record.notify_info_channel_name = "notify_info_%s" % res_id | ||
| record.notify_default_channel_name = "notify_default_%s" % res_id | ||
| record.notify_success_channel_name = f"notify_success_{res_id}" | ||
| record.notify_danger_channel_name = f"notify_danger_{res_id}" | ||
| record.notify_warning_channel_name = f"notify_warning_{res_id}" | ||
| record.notify_info_channel_name = f"notify_info_{res_id}" | ||
| record.notify_default_channel_name = f"notify_default_{res_id}" | ||
|
Comment on lines
-23
to
+27
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| notify_success_channel_name = fields.Char(compute="_compute_channel_names") | ||
| notify_danger_channel_name = fields.Char(compute="_compute_channel_names") | ||
|
|
@@ -62,7 +62,7 @@ def _notify_channel( | |
| raise exceptions.UserError( | ||
| _("Sending a notification to another user is forbidden.") | ||
| ) | ||
| channel_name_field = "notify_{}_channel_name".format(type_message) | ||
| channel_name_field = f"notify_{type_message}_channel_name" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| bus_message = { | ||
| "type": type_message, | ||
| "message": message, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ def test_notify_success(self): | |
| self.env.user.notify_success(**test_msg) | ||
| news = bus_bus.search(domain) - existing | ||
| self.assertEqual(1, len(news)) | ||
| test_msg.update({"type": SUCCESS}) | ||
| test_msg["type"] = SUCCESS | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.assertDictEqual(test_msg, json.loads(news.message)) | ||
|
|
||
| def test_notify_danger(self): | ||
|
|
@@ -34,7 +34,7 @@ def test_notify_danger(self): | |
| self.env.user.notify_danger(**test_msg) | ||
| news = bus_bus.search(domain) - existing | ||
| self.assertEqual(1, len(news)) | ||
| test_msg.update({"type": DANGER}) | ||
| test_msg["type"] = DANGER | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.assertDictEqual(test_msg, json.loads(news.message)) | ||
|
|
||
| def test_notify_warning(self): | ||
|
|
@@ -47,7 +47,7 @@ def test_notify_warning(self): | |
| self.env.user.notify_warning(**test_msg) | ||
| news = bus_bus.search(domain) - existing | ||
| self.assertEqual(1, len(news)) | ||
| test_msg.update({"type": WARNING}) | ||
| test_msg["type"] = WARNING | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.assertDictEqual(test_msg, json.loads(news.message)) | ||
|
|
||
| def test_notify_info(self): | ||
|
|
@@ -58,7 +58,7 @@ def test_notify_info(self): | |
| self.env.user.notify_info(**test_msg) | ||
| news = bus_bus.search(domain) - existing | ||
| self.assertEqual(1, len(news)) | ||
| test_msg.update({"type": INFO}) | ||
| test_msg["type"] = INFO | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.assertDictEqual(test_msg, json.loads(news.message)) | ||
|
|
||
| def test_notify_default(self): | ||
|
|
@@ -71,7 +71,7 @@ def test_notify_default(self): | |
| self.env.user.notify_default(**test_msg) | ||
| news = bus_bus.search(domain) - existing | ||
| self.assertEqual(1, len(news)) | ||
| test_msg.update({"type": DEFAULT}) | ||
| test_msg["type"] = DEFAULT | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.assertDictEqual(test_msg, json.loads(news.message)) | ||
|
|
||
| def test_notify_many(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,9 +19,7 @@ def service_worker(self): | |
| urls = [] | ||
| urls.extend(self.get_asset_urls("web.assets_common")) | ||
| urls.extend(self.get_asset_urls("web.assets_backend")) | ||
| version_list = [] | ||
| for url in urls: | ||
| version_list.append(url.split("/")[3]) | ||
| version_list = [url.split("/")[3] for url in urls] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| cache_version = "-".join(version_list) | ||
| mimetype = "text/javascript;charset=utf-8" | ||
| content = qweb.render( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,10 +46,7 @@ def values_char_field(self): | |
| def values_int_field(self): | ||
| min_value = int(self.env.context.get("min")) | ||
| max_value = int(self.env.context.get("max")) | ||
| options = [] | ||
| for value in range(min_value, max_value + 1): | ||
| options.append((value, str(value))) | ||
| return options | ||
| return [(value, str(value)) for value in range(min_value, max_value + 1)] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| @api.model | ||
| def values_selection_field(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,9 +11,7 @@ class X2MDemo(models.Model): | |
|
|
||
| def _open_x2m_matrix(self, view_xmlid): | ||
| wiz = self.env["x2m.matrix.demo.wiz"].create({}) | ||
| view_id = self.env.ref( | ||
| "web_widget_x2many_2d_matrix_example.%s" % view_xmlid, | ||
| ).id | ||
| view_id = self.env.ref(f"web_widget_x2many_2d_matrix_example.{view_xmlid}").id | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return { | ||
| "name": "Try x2many 2D matrix widget", | ||
| "type": "ir.actions.act_window", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,19 +16,17 @@ def _default_line_ids(self): | |
| recs = self.env["x2m.demo"].search([]) | ||
| users = self.env["x2m.demo.line"].search([]).mapped("user_id") | ||
| return [ | ||
| ( | ||
| (4, rec.line_ids.filtered(lambda x: x.user_id == usr)[0].id) | ||
| if rec.line_ids.filtered(lambda x: x.user_id == usr) | ||
| else ( | ||
| 0, | ||
| 0, | ||
| { | ||
| "name": "{}'s task on {}".format(usr.name, rec.name), | ||
| "name": f"{usr.name}'s task on {rec.name}", | ||
| "demo_id": rec.id, | ||
| "user_id": usr.id, | ||
| }, | ||
| ) | ||
| # if there isn't a demo line record for the user, create a new one | ||
| if not rec.line_ids.filtered(lambda x: x.user_id == usr) else | ||
| # otherwise, return the line | ||
| (4, rec.line_ids.filtered(lambda x: x.user_id == usr)[0].id) | ||
|
Comment on lines
-19
to
-31
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ): |
||
| for rec in recs | ||
| for usr in users | ||
| ] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines
11-11refactored with the following changes:use-fstring-for-concatenation)