Skip to content

Commit

Permalink
TA#48502 [IMP] Add pre-commit-config, flake8 and workflow to repo (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
majouda authored Jan 9, 2024
1 parent d24b267 commit 007e73c
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 22 deletions.
12 changes: 12 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[flake8]
max-line-length = 88
max-complexity = 16
# B = bugbear
# B9 = bugbear opinionated (incl line length)
select = C,E,F,W,B,B9
# E203: whitespace before ':' (black behaviour)
# E501: flake8 line length (covered by bugbear B950)
# W503: line break before binary operator (black behaviour)
ignore = E203,E501,W503,F821
per-file-ignores=
__init__.py:F401
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
30 changes: 30 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
^setup/|/static/description/index\.html$|
# We don't want to mess with tool-generated files
.svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|
# Maybe reactivate this when all README files include prettier ignore tags?
^README\.md$|
# Library files can have extraneous formatting (even minimized)
/static/(src/)?lib/|
# Repos using Sphinx to generate docs don't need prettying
^docs/_templates/.*\.html$|
# Don't bother non-technical authors with formatting issues in docs
readme/.*\.(rst|md)$|
# Ignore build and dist directories in addons
/build/|/dist/|
# You don't usually want a bot to modify your legal texts
(LICENSE.*|COPYING.*)
default_language_version:
python: python3
node: "14.13.0"
repos:
- repo: https://github.com/PyCQA/flake8
rev: 3.8.3
hooks:
- id: flake8
name: flake8
additional_dependencies: ["flake8-bugbear==20.1.4"]
2 changes: 1 addition & 1 deletion hr_employee_declaration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# © 2023 Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import models
from . import models
1 change: 0 additions & 1 deletion hr_employee_declaration/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
'data/survey_type.xml',
'data/ir_cron.xml',
'data/queue_job_function_data.xml',
#'demo/survey.xml',
'views/hr_employee_with_declaration_smart_button.xml',
'views/hr_employee_with_declaration_settings.xml',
'views/survey_type_with_is_employee_declaration.xml',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ def send_declaration_survey_by_email(self):
})

def _add_token_to_declaration_body(self, body, user_input):
url_with_token = '%s?%s' % (user_input.survey_id.get_start_url(), werkzeug.urls.url_encode(
{'answer_token': user_input and user_input.access_token or None}))
url_with_token = '%s?%s' % (
user_input.survey_id.get_start_url(), werkzeug.urls.url_encode(
{'answer_token': user_input and user_input.access_token or None}
)
)

if '__URL__' not in body:
raise ValidationError(_(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUpClass(cls):
"email": "test@example.com",
"groups_id": [
(4, cls.env.ref("hr.group_hr_user").id),
],
],
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,15 @@ def check_extended_security_all(self):
wizard._is_internal_employee()
and not self.env.user.has_internal_employee_access()
):
raise AccessError(
_(
"You are not allowed to access private information of internal employees."
)
)
raise AccessError(_("You are not allowed to access private "
"information of internal employees."))

if (
wizard._is_external_employee()
and not self.env.user.has_external_employee_access()
):
raise AccessError(
_(
"You are not allowed to access private information of external employees."
)
)
raise AccessError(_("You are not allowed to access private "
"information of external employees."))

def check_extended_security_write(self):
super().check_extended_security_write()
Expand Down
3 changes: 2 additions & 1 deletion hr_timesheet_enhanced/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"website": "https://bit.ly/numigi-com",
"license": "LGPL-3",
"category": "Human Resources",
"summary": """Add automations with value of active field and deletion of associated project""",
"summary": """Add automations with value of active
field and deletion of associated project""",
"depends": [
"hr_timesheet",
],
Expand Down
15 changes: 10 additions & 5 deletions hr_working_space/models/hr_attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@
# © 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, fields, models
from odoo import fields, models


class HRWorkingSpace(models.Model):
""" Add working spaces to attendance"""
_inherit = "hr.attendance"

working_space_id = fields.Many2one('hr.working.space', string='Working Space', required=True)
working_space_id = fields.Many2one(
'hr.working.space',
string='Working Space',
required=True
)


class HREmployeeWorkingSpace(models.Model):
""" Add the management of the working space at the attendance."""
_inherit = 'hr.employee'


def attendance_manual_working_space(self, next_action, working_space_id=None, entered_pin=None):
def attendance_manual_working_space(
self, next_action, working_space_id=None, entered_pin=None):
res = self.attendance_manual(next_action, entered_pin=entered_pin)
if working_space_id:
attendance = self.env['hr.attendance'].search([('id', '=', res['action']['attendance']['id'])], limit=1)
attendance = self.env['hr.attendance'].search(
[('id', '=', res['action']['attendance']['id'])], limit=1)
attendance.working_space_id = working_space_id
return res
3 changes: 2 additions & 1 deletion hr_working_space/models/hr_working_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ class HRAttendanceWithWorkingSpace(models.Model):
name = fields.Char(string='Name', required=True)
icon = fields.Char(
"Icon",
help="Font Awesome code of the icon that will represent the working space. See https://fontawesome.com/icons?d=gallery."
help="Font Awesome code of the icon that will represent the working space. "
"See https://fontawesome.com/icons?d=gallery."
)

0 comments on commit 007e73c

Please sign in to comment.