Skip to content

Commit

Permalink
TA#48502 [IMP] Add pre-commit-config, flake8 and workflow to repo (#132)
Browse files Browse the repository at this point in the history
* TA#48502 [IMP] Add pre-commit-config, flake8 and workflow to repo
  • Loading branch information
majouda authored Jan 22, 2024
1 parent 649579d commit feb2442
Show file tree
Hide file tree
Showing 30 changed files with 102 additions and 49 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: pre-commit

on:
pull_request:
branches:
- "14.0*"
push:
branches:
- "14.0"

jobs:
pre-commit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v2
with:
python-version: "3.11"
- name: Get python version
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure --color=always
- name: Check that all files generated by pre-commit are in git
run: |
newfiles="$(git ls-files --others --exclude-from=.gitignore)"
if [ "$newfiles" != "" ] ; then
echo "Please check-in the following files:"
echo "$newfiles"
exit 1
fi
1 change: 0 additions & 1 deletion auth_oauth_microsoft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@

from . import models
from . import controllers

3 changes: 2 additions & 1 deletion automatic_activity_deadlines/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

{
"name": "Automatic Activity Deadlines",
"summary": "Allow configure the delay to deadline for scheduled activities created automatically by the system",
"summary": """Allow configure the delay to deadline for scheduled
activities created automatically by the system""",
"version": "12.0.1.0.0",
"website": "https://bit.ly/numigi-com",
"author": "Numigi",
Expand Down
3 changes: 1 addition & 2 deletions base_extended_security/controllers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ def _get_args_and_kwargs_with_new_domain(method, args, kwargs, domain):

if len(args) > argument_index:
args = (
args[:argument_index] + [domain] +
args[argument_index + 1:]
args[:argument_index] + [domain] + args[argument_index + 1:]
)

else:
Expand Down
11 changes: 6 additions & 5 deletions base_extended_security/models/ir_ui_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from lxml import etree
from odoo import api, models
from typing import Iterable
from odoo import models


class ViewWithButtonsHiden(models.Model):
Expand All @@ -15,8 +14,9 @@ def postprocess_and_fields(self, node, model=None, validate=False):
This method is called in Odoo when generating the final xml of a view.
"""
arch, fields = super().postprocess_and_fields(node, model=model, validate=validate)

arch, fields = super().postprocess_and_fields(
node, model=model, validate=validate
)
is_nested_view = bool(self._context.get('base_model_name'))
view_model = model or self.model

Expand Down Expand Up @@ -72,7 +72,8 @@ def _hide_one2many_view_buttons_with_access_blocked(env, fields):
:param env: the Odoo environment
:param fields: the field definitions
"""
one2many_fields = (f for f in fields.values() if 'type' in f.keys() and f['type'] == 'one2many')
one2many_fields = (
f for f in fields.values() if 'type' in f.keys() and f['type'] == 'one2many')
for field in one2many_fields:
model = field['relation']

Expand Down
2 changes: 1 addition & 1 deletion base_extended_security/tests/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

from odoo import fields, models
from odoo import models
from odoo.exceptions import AccessError
from odoo.osv.expression import AND
from odoo.tests.common import SavepointCase
Expand Down
17 changes: 11 additions & 6 deletions base_extended_security/tests/test_search.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# © 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import pytest
from ddt import ddt, data, unpack
from odoo.addons.test_http_request.common import mock_odoo_request
from .common import ControllerCase
Expand Down Expand Up @@ -32,15 +31,17 @@ def _read_group(self, domain, fields, groupby, domain_kwarg):
@data(True, False)
def test_read_group_with_empty_domain(self, domain_kwarg):
groups = self._read_group(
[], fields=['customer_rank'], groupby='customer_rank', domain_kwarg=domain_kwarg)
[], fields=['customer_rank'], groupby='customer_rank',
domain_kwarg=domain_kwarg)
assert len(groups) == 2
assert groups[0]['customer_rank_count'] == self.customer_count - 1

@data(True, False)
def test_read_group_with_supplier_domain(self, domain_kwarg):
domain = [('supplier_rank', '>', 0)]
groups = self._read_group(
domain, fields=['customer_rank'], groupby='customer_rank', domain_kwarg=domain_kwarg)
domain, fields=['customer_rank'], groupby='customer_rank',
domain_kwarg=domain_kwarg)
assert len(groups) == 1
assert groups[0]['customer_rank_count'] == self.supplier_customer_count

Expand Down Expand Up @@ -101,7 +102,8 @@ def _test_name_search_with_empty_domain(self, name_kwarg, domain_kwarg):
)
@unpack
def test_name_search_with_supplier_domain(self, name_kwarg, domain_kwarg):
ids = self._name_search('My Partner', [('supplier_rank', '>', 0)], name_kwarg, domain_kwarg)
ids = self._name_search('My Partner', [('supplier_rank', '>', 0)],
name_kwarg, domain_kwarg)
assert self.customer.id not in ids
assert self.supplier.id not in ids
assert self.supplier_customer.id in ids
Expand Down Expand Up @@ -153,8 +155,11 @@ def test_search_read_with_empty_domain(self, use_search_read_route, domain_kwarg
(False, True),
)
@unpack
def test_search_read_with_supplier_domain(self, use_search_read_route, domain_kwarg):
ids = self._search_read([('supplier_rank', '>', 0)], use_search_read_route, domain_kwarg)
def test_search_read_with_supplier_domain(self,
use_search_read_route, domain_kwarg):
ids = self._search_read([('supplier_rank', '>', 0)],
use_search_read_route,
domain_kwarg)
assert self.customer.id not in ids
assert self.supplier.id not in ids
assert self.supplier_customer.id in ids
3 changes: 2 additions & 1 deletion base_extended_security/tests/test_security_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ def _get_nested_ir_rule_many2many_arch(self):
('unlink', 'delete'),
)
@unpack
def test_in_nested_many2many_list__view_property_not_disabled(self, access_type, view_property):
def test_in_nested_many2many_list__view_property_not_disabled(
self, access_type, view_property):
self.env['extended.security.rule'].create({
'model_id': self.env.ref('base.model_ir_rule').id,
'group_ids': [(4, self.group.id)],
Expand Down
6 changes: 4 additions & 2 deletions base_extended_security_grid/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class Base(models.AbstractModel):
_inherit = 'base'

@api.model
def read_grid(self, row_fields, col_field, cell_field, domain=None, range=None, readonly_field=None, orderby=None):
def read_grid(self, row_fields, col_field, cell_field, domain=None, range=None,
readonly_field=None, orderby=None):
base_domain = normalize_domain(domain)
security_domain = self.get_extended_security_domain()
complete_domain = AND((base_domain, security_domain))
return super().read_grid(row_fields, col_field, cell_field, complete_domain, range, readonly_field, orderby)
return super().read_grid(row_fields, col_field, cell_field, complete_domain,
range, readonly_field, orderby)
1 change: 0 additions & 1 deletion base_external_report_layout/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# © 2023 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

2 changes: 1 addition & 1 deletion base_view_mode_restricted/models/ir_actions_act_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from itertools import chain
from odoo import api, fields, models
from odoo import fields, models


class IrActionsActWindow(models.Model):
Expand Down
3 changes: 1 addition & 2 deletions base_xml_rename/models/ir_ui_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ def rename(self, ref, lang, value, field='name'):

menu = self.env.ref(ref)
should_update_action_name = (
is_lang_installed(self.env, lang) and
menu.action and field == 'name'
is_lang_installed(self.env, lang) and menu.action and field == 'name'
)
if should_update_action_name:
menu.action.with_context(lang=lang).name = value
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ def _get_boc_response(self, url):
if response.status_code >= 400:
raise ValidationError(
_(
"The request to the Valet api of the Bank of Canada terminated with an error.\n\n{} : {}".format(
"The request to the Valet api of the Bank of Canada terminated"
"with an error.\n\n{} : {}".format(
response.text, url
)
)
Expand Down
10 changes: 6 additions & 4 deletions currency_rate_update_boc/tests/test_currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ def setUpClass(cls):
}
)

cls.test_boc_url = "https://www.bankofcanada.ca/valet/observations/FXUSDCAD,FXEURCAD?start_date=%s&end_date=%s" % (
cls.date_string, cls.date_string)
cls.test_boc_url = (
"https://www.bankofcanada.ca/valet/observations/"
"FXUSDCAD,FXEURCAD?start_date=%s&end_date=%s"
) % (cls.date_string, cls.date_string)
cls.dumb_test_boc_url = "https://www.bankofcanada.ca/valet/observations/"

@data("CAD", "USD", "EUR")
Expand Down Expand Up @@ -79,12 +81,12 @@ def test_rates_x2x(self):

def test_invalid_currency(self):
with pytest.raises(ValidationError):
rates = self.provider._obtain_rates(
self.provider._obtain_rates(
"USD", ["ZZZZ"], self.date, self.date)

def test_invalid_date(self):
with pytest.raises(ValidationError):
rates = self.provider._obtain_rates(
self.provider._obtain_rates(
"USD", ["ZZZZ"], self.date, self.date - timedelta(5)
)

Expand Down
2 changes: 1 addition & 1 deletion dms_document_url/models/ir_attachment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# © 2022 - Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import fields, models
from odoo import models


class IrAttachment(models.Model):
Expand Down
2 changes: 1 addition & 1 deletion mail_activity_not_deleted/models/mail_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _compute_state(self):
def unlink(self):
self._send_signal_done()
self.write(
{"active": False, "date_done": datetime.now(),}
{"active": False, "date_done": datetime.now()}
)
for activity in self:
activity._update_record_date_deadline()
Expand Down
2 changes: 1 addition & 1 deletion mail_activity_not_deleted/models/mail_activity_mixin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# © 2023 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, fields, models
from odoo import fields, models


class MailActivityMixin(models.AbstractModel):
Expand Down
8 changes: 6 additions & 2 deletions mail_activity_not_deleted/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ def systray_get_activities(self):
'model': activity['model'],
'type': 'activity',
'icon': icon,
'total_count': 0, 'today_count': 0, 'overdue_count': 0, 'planned_count': 0,
'total_count': 0,
'today_count': 0,
'overdue_count': 0,
'planned_count': 0,
}
user_activities[activity['model']]['%s_count' % activity['states']] += activity['count']
user_activities[activity['model']]['%s_count' % activity['states']
] += activity['count']
if activity['states'] in ('today', 'overdue'):
user_activities[activity['model']]['total_count'] += activity['count']

Expand Down
2 changes: 1 addition & 1 deletion mail_bot_no_pong/models/mail_bot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# © 2020 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo import models


class MailBot(models.AbstractModel):
Expand Down
2 changes: 1 addition & 1 deletion mail_notification_no_action_button/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# © 2022 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, models
from odoo import models


class MailThread(models.AbstractModel):
Expand Down
9 changes: 6 additions & 3 deletions mail_notification_no_action_button/tests/test_crm_lead.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ def setUpClass(cls):
}
)
cls.partner = cls.user.partner_id
cls.lead = cls.env["crm.lead"].create({"name": "M Lead",})
cls.lead = cls.env["crm.lead"].create({"name": "M Lead"})
cls.subtype = cls.env.ref("mail.mt_comment")
cls.lead.message_subscribe([cls.partner.id], subtype_ids=[cls.subtype.id])

def send_notification_email(self):
message = self.lead.message_post(
body="Test", mail_auto_delete=False, send_after_commit=False, force_send=True,
subtype_id=self.subtype.id,
body="Test",
mail_auto_delete=False,
send_after_commit=False,
force_send=True,
subtype_id=self.subtype.id
)
return self.env["mail.mail"].search(
[("mail_message_id", "=", message.id)], limit=1
Expand Down
3 changes: 2 additions & 1 deletion mail_template_default/models/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class MailTemplate(models.Model):
@api.constrains("is_default_template", "model_id")
def _check_unique_default_template(self):
for record in self:
if record.search_count([("is_default_template", "=", True), ("model_id", "=", record.model_id.id)]) > 1:
if record.search_count([("is_default_template", "=", True),
("model_id", "=", record.model_id.id)]) > 1:
raise ValidationError(_(
"This object already has a default template associated. \n"
"You cannot assign more than one default template by object."
Expand Down
3 changes: 2 additions & 1 deletion mail_template_default/tests/test_mail_template_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def test_get_default_template(self):
)
self.mail_1.is_default_template = False
self.assertEquals(
self.env["mail.compose.message"].with_context(default_model="res.partner").default_get(["template_id"]),
self.env["mail.compose.message"].with_context(
default_model="res.partner").default_get(["template_id"]),
{}
)
1 change: 0 additions & 1 deletion private_data_group/controllers/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def _get_related_model(model: str, relation: str):


def _raise_private_field_access_error(model: str, field: str):
context = request.env.context # pylint: disable=unused-variable
raise AccessError(
_('You do not have access to the field {field} of model {model}')
.format(field=field, model=model)
Expand Down
1 change: 0 additions & 1 deletion private_data_group/controllers/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
get_domain_from_args_and_kwargs,
)
from odoo.http import request
from odoo.tools import pycompat
from typing import Iterable
from .common import check_model_fields_access, extract_fields_from_domain

Expand Down
2 changes: 1 addition & 1 deletion private_data_group/tests/test_dataset_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setUp(self):
)

self.employee = self.env["hr.employee"].create(
{"name": "Employee", "sinid": "123 456 789", "user_id": self.user.id,}
{"name": "Employee", "sinid": "123 456 789", "user_id": self.user.id}
)
self.fields = ("name", "sinid")
self.domain = [("id", "=", self.employee.id)]
Expand Down
3 changes: 1 addition & 2 deletions private_data_group/tests/test_res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def setUpClass(cls):

def test_if_is_authorized__access_error_not_raised(self):
self.user.groups_id |= self.group
self.private_address.with_user(
self.user).check_extended_security_all()
self.private_address.with_user(self.user).check_extended_security_all()

def test_if_not_authorized__access_error_raised(self):
with pytest.raises(AccessError):
Expand Down
5 changes: 3 additions & 2 deletions queue_job_auto_requeue/models/queue_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def auto_requeue_cron(self):
min_time = datetime.now() - timedelta(seconds=int(time_limit))

stalled_jobs = (
started_jobs.filtered(lambda j: j.date_started < min_time) |
enqueued_jobs.filtered(lambda j: j.date_enqueued < min_time)
started_jobs.filtered(
lambda j: j.date_started < min_time) | enqueued_jobs.filtered(
lambda j: j.date_enqueued < min_time)
)

for job in stalled_jobs:
Expand Down
2 changes: 1 addition & 1 deletion utm_archive/models/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
class UtmCampaign(models.Model):
_inherit = "utm.campaign"

active = fields.Boolean(string="Active")
active = fields.Boolean(string="Active")
Loading

0 comments on commit feb2442

Please sign in to comment.