Skip to content

Commit

Permalink
TA#62072 [ADD] pre-commit, flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
majouda committed Apr 15, 2024
1 parent 1f181a3 commit 5e49f10
Show file tree
Hide file tree
Showing 35 changed files with 250 additions and 149 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
37 changes: 28 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +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/pre-commit/pre-commit-hooks
rev: v2.3.0
- repo: https://github.com/PyCQA/flake8
rev: 3.8.3
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 19.3b0
hooks:
- id: black
- id: flake8
name: flake8
additional_dependencies: ["flake8-bugbear==20.1.4"]
2 changes: 1 addition & 1 deletion forward_sorting_area/models/forward_sortation_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,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, fields, models
from odoo import fields, models


class ForwardSortationAera(models.Model):
Expand Down
6 changes: 4 additions & 2 deletions google_partner_address/models/base_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# © 2022 Numigi
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

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


class BaseConfigSettingsWithGoogleMapsAPI(models.TransientModel):
Expand All @@ -28,4 +28,6 @@ def _default_google_maps_api_uri(self):

def set_values(self):
super().set_values()
self.env['ir.config_parameter'].set_param('google_maps_api_key', self.google_maps_api_key)
self.env['ir.config_parameter'].set_param(
'google_maps_api_key', self.google_maps_api_key
)
5 changes: 3 additions & 2 deletions partner_affiliate_invoicing_address/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class Partner(models.Model):
"Invoice address to use",
store=True,
readonly=False,
domain="['|', '&', ('type', '=', 'invoice') ,('parent_id', '=', parent_id), ('id', '=', parent_id)]",
domain="['|', '&', ('type', '=', 'invoice') ,('parent_id', '=', parent_id),"
" ('id', '=', parent_id)]",
)

@api.onchange("use_parent_invoice_address")
Expand All @@ -25,7 +26,7 @@ def _onchange_use_parent_invoice_address(self):
else:
self.invoice_address_to_use_id = False

def _update_for_specific_invoice_address(self, res={}):
def _update_for_specific_invoice_address(self, res):
if res.get(INVOICE, False):
res[INVOICE] = self.commercial_partner_id.invoice_address_to_use_id.id

Expand Down
7 changes: 5 additions & 2 deletions partner_autocomplete_disable/tests/test_res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ def test_whenStartSync_thenPatchedMethodIsCalled(self):
""" make sure the targeted method is called during the process
"""
module_memory_address = (
"odoo.addons.partner_autocomplete_disable.models.res_partner.ResPartnerAutocompleteDisable"
"odoo.addons.partner_autocomplete_disable"
".models.res_partner.ResPartnerAutocompleteDisable"
)
with mock.patch(".".join([module_memory_address, "_rpc_remote_api"])) as mocked:
autocomplete_module_memory_address = (
"odoo.addons.partner_autocomplete.models.res_partner.ResPartner"
)
mocked.return_value = {}, False
with mock.patch(".".join([autocomplete_module_memory_address, "_is_vat_syncable"])) as sync:
with mock.patch(".".join(
[autocomplete_module_memory_address, "_is_vat_syncable"]
)) as sync:
sync.return_value = True
self.autocomplete_sync.start_sync()
assert mocked.call_count == 1
Expand Down
8 changes: 2 additions & 6 deletions partner_category_type/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ def write(self, vals):

def _update_category_ids_from_extra_caetgory_fields(self):
"""Update the partner tags from the custom category fields."""
new_categories = (
self.organization_type_ids |
self.profile_ids |
self.personality_ids |
self.job_position_id
)
new_categories = (self.organization_type_ids | self.profile_ids | (
self.personality_ids | self.job_position_id))
if new_categories != self.category_id:
self.category_id = new_categories
6 changes: 4 additions & 2 deletions partner_change_parent/tests/test_res_partner_change_parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo.api import Environment
from odoo.exceptions import AccessError, ValidationError
from odoo.exceptions import ValidationError
from odoo.tests import common
from odoo.tests.common import users
from odoo.tests.common import users


class TestResPartnerChangeParent(common.SavepointCase):
@classmethod
Expand Down Expand Up @@ -80,6 +81,7 @@ def test_no_source_parent(self):
contact_with_no_company, self.company_1
)
assert new_contact.parent_id, self.company_1

@users('admin')
def test_destination_parent_with_address(self):
"""Test that the address is changed when changing the parent company."""
Expand Down
6 changes: 4 additions & 2 deletions partner_change_parent/wizard/res_partner_change_parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ def _copy_old_contact(self):
address_fields = self.env['res.partner']._address_fields()
default_values.update(((f, False) for f in address_fields))

new_contact = self.contact_id.with_context(mail_notrack=True).copy(default=default_values)
new_contact = self.contact_id.with_context(mail_notrack=True
).copy(default=default_values)

# Rename the new contact to remove `(copy)`.
new_contact.with_context(mail_notrack=True).write({'name': self.contact_id.name})
new_contact.with_context(mail_notrack=True).write(
{'name': self.contact_id.name})

# Propagate the old email to the new contact.
new_contact.with_context(mail_notrack=True).write({'email': email})
Expand Down
2 changes: 1 addition & 1 deletion partner_duplicate_mgmt/models/ir_model_fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# © 2017 Savoir-faire Linux
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, models
from odoo import models


class IrModelFields(models.Model):
Expand Down
6 changes: 3 additions & 3 deletions partner_duplicate_mgmt/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import logging
import re
from odoo import _, api, fields, models
from odoo.exceptions import UserError

Expand Down Expand Up @@ -239,7 +238,7 @@ def _auto_init(self):
if not cr.fetchone():
try:
cr.execute('CREATE EXTENSION pg_trgm')
except:
except Exception:
message = (
"Could not create the pg_trgm postgresql EXTENSION. "
"You must log to your database as superuser and type "
Expand All @@ -261,7 +260,8 @@ def _auto_init(self):
return res

def action_merge(self):
if not self.env.user.has_group('partner_duplicate_mgmt.group_duplicate_partners_control'):
if not self.env.user.has_group(
'partner_duplicate_mgmt.group_duplicate_partners_control'):
raise UserError(_("You don't have access to merge partners."))

if len(self) != 2:
Expand Down
31 changes: 19 additions & 12 deletions partner_duplicate_mgmt/models/res_partner_duplicate.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def _update_partner_order(self):
The left partner (partner_1_id) must be the partner with the lower id.
"""
duplicates_in_wrong_order = (d for d in self if d.partner_1_id.id > d.partner_2_id.id)
duplicates_in_wrong_order = (
d for d in self if d.partner_1_id.id > d.partner_2_id.id)
for duplicate in duplicates_in_wrong_order:
duplicate.write({
'partner_1_id': duplicate.partner_2_id.id,
Expand Down Expand Up @@ -94,10 +95,9 @@ def _onchange_check_contacts_with_journal_entries(self):
is not reversible.
"""
both_partners_are_contacts = (
self.partner_preserved_id and
self.partner_archived_id and
not self.partner_preserved_id.is_company and
not self.partner_archived_id.is_company
self.partner_preserved_id and self.partner_archived_id and not (
self.partner_preserved_id.is_company) and not (
self.partner_archived_id.is_company)
)

def partner_has_journal_entries(partner):
Expand All @@ -110,11 +110,13 @@ def partner_has_journal_entries(partner):
return self.env['account.move'].sudo().search(
[('partner_id', '=', partner.id)], count=True)

if both_partners_are_contacts and partner_has_journal_entries(self.partner_archived_id):
if both_partners_are_contacts and partner_has_journal_entries(
self.partner_archived_id):
self.warning_message = _(
"Please note that the contact {archived_partner} is linked to journal "
"entries. By merging it with {preserved_partner}, all the accounting "
"history of {archived_partner} will be moved under {preserved_partner}.").format(
"history of {archived_partner} will be moved under"
" {preserved_partner}.").format(
archived_partner=self.partner_archived_id.name,
preserved_partner=self.partner_preserved_id.name,
)
Expand Down Expand Up @@ -200,15 +202,18 @@ def merge_partners(self):

def _log_archived_partner_message(self):
"""Log the message in the mail thread of the archived partner."""
message = _('Merged into {partner}.').format(partner=self.partner_preserved_id.display_name)
message = _('Merged into {partner}.').format(
partner=self.partner_preserved_id.display_name)
self.partner_archived_id.message_post(body=message)

def _log_preserved_partner_message(self):
"""Log the message in the mail thread of the preserved partner."""
message = _('Merged with {partner}.').format(partner=self.partner_archived_id.display_name)
message = _('Merged with {partner}.').format(
partner=self.partner_archived_id.display_name)

if self.merger_reason_id:
reason = _("The merger reason is: {reason}.").format(reason=self.merger_reason_id.name)
reason = _("The merger reason is: {reason}.").format(
reason=self.merger_reason_id.name)
message = '{message}\n\n{reason}'.format(message=message, reason=reason)

self.partner_preserved_id.message_post(body=message)
Expand Down Expand Up @@ -268,7 +273,8 @@ def _get_partner_name_similarity(self, level):
:param level: the similarity level from 1 to 3
:return: the floor similarity limit
"""
parameter = 'partner_duplicate_mgmt.partner_name_similarity_{level}'.format(level=level)
parameter = 'partner_duplicate_mgmt.partner_name_similarity_{level}'.format(
level=level)
return self.env['ir.config_parameter'].sudo().get_param(parameter)

def create_duplicates(self):
Expand All @@ -283,7 +289,8 @@ def action_resolve(self):
self.filtered(lambda x: x.state == 'to_validate').write({'state': 'resolved'})

for record in self:
message = _('The duplicate line ({partner_1}, {partner_2}) is resolved.').format(
message = _('The duplicate line ({partner_1}, {partner_2}) is resolved.'
).format(
partner_1=record.partner_1_id.display_name,
partner_2=record.partner_2_id.display_name,
)
Expand Down
4 changes: 1 addition & 3 deletions partner_duplicate_mgmt/tests/test_res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from odoo.api import Environment
from odoo.tests import common
from odoo.exceptions import UserError
from odoo.tests.common import tagged, users
from odoo.tests.common import users


class TestResPartner(common.SavepointCase):
Expand All @@ -29,7 +29,6 @@ def setUpClass(cls):
cls.partner_5 = cls.env['res.partner'].create({'name': 'Julyenjezequel'})
cls.partner_6 = cls.env['res.partner'].create({'name': 'Julien Jézequel'})


def test_partner_indexed_name_is_lower_case(self):
self.assertEqual(self.partner_1.indexed_name, 'big partner')

Expand Down Expand Up @@ -112,7 +111,6 @@ def test_merge_partners_similarity_1(self):
similarity = self.env['res.partner']._get_min_similarity('Julienjez')
self.assertEqual(similarity, '0.5')


def test_merge_partners_similarity_2(self):
# Similarity of these 2 partners : 0.67
partner = self.env['res.partner'].create({'name': 'Julienjezequel'})
Expand Down
Loading

0 comments on commit 5e49f10

Please sign in to comment.