Skip to content

Commit

Permalink
Merge pull request #1532 from camptocamp/14.0-fix-build
Browse files Browse the repository at this point in the history
[14.0][FIX] fix build
  • Loading branch information
simahawk authored May 15, 2024
2 parents 24db291 + 0e223de commit 9d1f20b
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 44 deletions.
9 changes: 5 additions & 4 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Do NOT update manually; changes here will be overwritten by Copier
_commit: v1.14.2
_commit: v1.20
_src_path: https://github.com/OCA/oca-addons-repo-template.git
ci: GitHub
dependency_installation_mode: PIP
convert_readme_fragments_to_markdown: false
generate_requirements_txt: true
github_check_license: true
github_ci_extra_env:
Expand All @@ -13,6 +13,7 @@ github_enable_makepot: true
github_enable_stale_action: false
github_enforce_dev_status_compatibility: false
include_wkhtmltopdf: false
odoo_test_flavor: Both
odoo_version: 14.0
org_name: Shopinvader
org_slug: shopinvader
Expand All @@ -21,6 +22,6 @@ repo_description: Odoo REST APIs for e-commerce.
repo_name: Shopinvader
repo_slug: odoo-shopinvader
repo_website: https://github.com/shopinvader/odoo-shopinvader
travis_apt_packages: []
travis_apt_sources: []
use_pyproject_toml: false
use_ruff: false

1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ globals:
odoo: readonly
openerp: readonly
owl: readonly
luxon: readonly

# Styling is handled by Prettier, so we only need to enable AST rules;
# see https://github.com/OCA/maintainer-quality-tools/pull/618#issuecomment-558576890
Expand Down
13 changes: 12 additions & 1 deletion .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ jobs:
pre-commit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- 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
Expand All @@ -25,6 +27,15 @@ jobs:
run: pip install pre-commit
- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure --color=always
env:
# Consider valid a PR that changes README fragments but doesn't
# change the README.rst file itself. It's not really a problem
# because the bot will update it anyway after merge. This way, we
# lower the barrier for functional contributors that want to fix the
# readme fragments, while still letting developers get README
# auto-generated (which also helps functionals when using runboat).
# DOCS https://pre-commit.com/#temporarily-disabling-hooks
SKIP: oca-gen-addon-readme
- name: Check that all files generated by pre-commit are in git
run: |
newfiles="$(git ls-files --others --exclude-from=.gitignore)"
Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ on:
- "14.0-ocabot-*"

jobs:
unreleased-deps:
runs-on: ubuntu-latest
name: Detect unreleased dependencies
steps:
- uses: actions/checkout@v3
- run: |
for reqfile in requirements.txt test-requirements.txt ; do
if [ -f ${reqfile} ] ; then
result=0
# reject non-comment lines that contain a / (i.e. URLs, relative paths)
grep "^[^#](?!.*(locomotivecms)).*/" ${reqfile} || result=$?
if [ $result -eq 0 ] ; then
echo "Unreleased dependencies found in ${reqfile}."
exit 1
fi
fi
done
test:
runs-on: ubuntu-22.04
container: ${{ matrix.container }}
Expand All @@ -23,6 +40,7 @@ jobs:
name: test with Odoo
- container: ghcr.io/oca/oca-ci/py3.8-ocb14.0:latest
name: test with OCB
makepot: "true"
services:
postgres:
image: postgres:9.6
Expand All @@ -36,7 +54,7 @@ jobs:
PIP_EXTRA_INDEX_URL: "https://wheelhouse.shopinvader.com/simple/"
REST_API_METHOD_FIX_DECORATOR_DEPRECATE_LOG_DISABLE: 1
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
persist-credentials: false
- name: Install addons and dependencies
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ __pycache__/
*.py[cod]
/.venv
/.pytest_cache
/.ruff_cache

# C extensions
*.so
Expand Down
2 changes: 2 additions & 0 deletions .oca_hooks.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[MESSAGES_CONTROL]
disable=xml-deprecated-data-node,xml-deprecated-tree-attribute
19 changes: 18 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ exclude: |
/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:
Expand All @@ -41,12 +45,25 @@ repos:
language: fail
files: '[a-zA-Z0-9_]*/i18n/en\.po$'
- repo: https://github.com/oca/maintainer-tools
rev: ab1d7f6
rev: 9a170331575a265c092ee6b24b845ec508e8ef75
hooks:
# update the NOT INSTALLABLE ADDONS section above
- id: oca-update-pre-commit-excluded-addons
- id: oca-fix-manifest-website
args: ["https://github.com/shopinvader/odoo-shopinvader"]
- id: oca-gen-addon-readme
args:
- --addons-dir=.
- --branch=14.0
- --org-name=shopinvader
- --repo-name=odoo-shopinvader
- --if-source-changed
- --keep-source-digest
- repo: https://github.com/OCA/odoo-pre-commit-hooks
rev: v0.0.25
hooks:
- id: oca-checks-odoo-module
- id: oca-checks-po
- repo: https://github.com/myint/autoflake
rev: v1.4
hooks:
Expand Down
2 changes: 1 addition & 1 deletion shopinvader/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Shopinvader",
"summary": "Shopinvader",
"version": "14.0.5.24.12",
"version": "14.0.5.24.13",
"category": "e-commerce",
"website": "https://github.com/shopinvader/odoo-shopinvader",
"author": "Akretion",
Expand Down
15 changes: 11 additions & 4 deletions shopinvader/demo/pricelist_demo.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- pylint:disable=duplicate-xml-record-id -->
<odoo noupdate="1">

<record id="pricelist_1" model="product.pricelist">
Expand All @@ -21,9 +20,17 @@
To be sure that only our new item is assigned to the price list
we reassign the item_ids....
-->
<record id="pricelist_1" model="product.pricelist">
<field name="item_ids" eval="[(6, 0, [ref('shopinvader.item_1')])]" />
</record>
<function model="product.pricelist" name="write">
<value
model="product.pricelist"
eval="obj().env.ref('shopinvader.pricelist_1').ids"
/>
<value
eval="{
'item_ids': [(6, 0, [ref('shopinvader.item_1')])],
}"
/>
</function>


</odoo>
2 changes: 1 addition & 1 deletion shopinvader_auth_api_key/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Shopinvader Auth Api Key",
"summary": """
Shopinvader API_KEY Authentication""",
"version": "14.0.1.1.1",
"version": "14.0.1.1.2",
"license": "AGPL-3",
"author": "ACSONE SA/NV",
"website": "https://github.com/shopinvader/odoo-shopinvader",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
>shopinvader.backend.form (in shopinvader_auth_api_key)</field>
<field name="model">shopinvader.backend</field>
<field name="inherit_id" ref="shopinvader.shopinvader_backend_view_form" />
<field name="model">shopinvader.backend</field>
<field name="arch" type="xml">
<group name="auth" position="inside">
<field name="auth_api_key_id" />
Expand Down
2 changes: 1 addition & 1 deletion shopinvader_image/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Shopinvader image",
"summary": "Add the export of Image for Shopinvader",
"version": "14.0.1.3.0",
"version": "14.0.1.3.1",
"category": "e-commerce",
"website": "https://github.com/shopinvader/odoo-shopinvader",
"author": "Akretion",
Expand Down
14 changes: 9 additions & 5 deletions shopinvader_image/models/shopinvader_image_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright 2021 Camptocamp SA (http://www.camptocamp.com)
# @author Simone Orsi <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from hashlib import sha1

from odoo import fields, models

Expand Down Expand Up @@ -53,7 +54,11 @@ def _get_images_store_hash(self):
self.ensure_one()
if not self[self._image_field]:
return False
return str(hash(self._get_images_store_hash_tuple()))
# NOTE : from python 3.9 on we should use
# usedforsecurity=False with sha1
return sha1(
str(self._get_images_store_hash_tuple()).encode("utf-8")
).hexdigest()

def _get_images_store_hash_timestamp(self):
"""Get the timestamp of the last modification of the images
Expand All @@ -63,12 +68,11 @@ def _get_images_store_hash_timestamp(self):
:return: datetime
"""
images_relation = self[self._image_field]
timestamps = [
*images_relation.mapped("write_date"),
*images_relation.mapped("image_id.write_date"),
timestamps = [x.write_date for x in images_relation] + [
x.image_id.write_date for x in images_relation
]
if "tag_id" in images_relation._fields:
timestamps += images_relation.mapped("tag_id.write_date")
timestamps += [x.tag_id.write_date for x in images_relation if x.tag_id]
return max(timestamps) if timestamps else False

def _get_images_store_hash_tuple(self):
Expand Down
48 changes: 30 additions & 18 deletions shopinvader_image/tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from datetime import timedelta

import mock
from unittest import mock

from odoo import fields

Expand All @@ -30,8 +29,9 @@ def test_basic_images_compute(self):
for scale in self.backend.shopinvader_variant_resize_ids:
img = image[scale.key]
self.assertEqual(img["alt"], self.shopinvader_variant.name)
src = img["src"].replace("-_", "_")
self.assertTrue(
img["src"].startswith(
src.startswith(
"https://foo.com/customizable-desk-config_{0.size_x}_{0.size_y}".format(
scale
)
Expand All @@ -54,8 +54,9 @@ def test_basic_images_compute_no_cdn_url(self):
for scale in self.backend.shopinvader_variant_resize_ids:
img = image[scale.key]
self.assertEqual(img["alt"], self.shopinvader_variant.name)
src = img["src"].replace("-_", "_")
self.assertTrue(
img["src"].startswith(
src.startswith(
"/customizable-desk-config_{0.size_x}_{0.size_y}".format(scale)
)
)
Expand All @@ -75,23 +76,34 @@ def test_hash_and_compute_flag(self):
# and it always corresponds to the time the transaction started.
# To overcome this, we manually overwrite write_date
now = fields.Datetime.now()
variant.image_ids.write_date = now
variant.images_store_hash = variant._get_images_store_hash()
# Change hash when relation is updated
variant.image_ids[0].write_date = now + timedelta(seconds=1)
self.assertTrue(variant._images_must_recompute())
variant.images_store_hash = variant._get_images_store_hash()
# Change hash when image is updated
variant.image_ids[0].image_id.write_date = now + timedelta(seconds=2)
self.assertTrue(variant._images_must_recompute())
variant.images_store_hash = variant._get_images_store_hash()
# Change hash when tag is updated
with mock.patch.object(
type(variant.image_ids), "write_date", new_callable=mock.PropertyMock
) as mocked:
mocked.return_value = now
variant.images_store_hash = variant._get_images_store_hash()
# Change hash when relation is updated
mocked.return_value = now + timedelta(seconds=100)
# variant.image_ids[0].write_date = now + timedelta(seconds=1)
self.assertTrue(variant._images_must_recompute())
variant.images_store_hash = variant._get_images_store_hash()
with mock.patch.object(
type(variant.image_ids.image_id),
"write_date",
new_callable=mock.PropertyMock,
) as mocked:
mocked.return_value = now + timedelta(seconds=2)
self.assertTrue(variant._images_must_recompute())
variant.images_store_hash = variant._get_images_store_hash()
# Change hash when tag is updated
tag = self.env.ref("shopinvader_image.image_tag_1")
variant.image_ids[0].tag_id = tag
variant.images_store_hash = variant._get_images_store_hash()
tag.write_date = now + timedelta(seconds=3)
self.assertTrue(variant._images_must_recompute())
variant.images_store_hash = variant._get_images_store_hash()
with mock.patch.object(
type(variant.image_ids.tag_id), "write_date", new_callable=mock.PropertyMock
) as mocked:
mocked.return_value = now + timedelta(seconds=3)
self.assertTrue(variant._images_must_recompute())
variant.images_store_hash = variant._get_images_store_hash()

def test_images_recompute(self):
variant = self.shopinvader_variant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@


class SaleCase(CommonSaleCase):
def download(self, id, **params):
def _test_download(self, _id, **params):
with mock.patch(
"odoo.addons.shopinvader.services." "abstract_download.content_disposition"
) as mocked_cd:
request = mock.MagicMock()
abstract_download.request = request
mocked_cd.return_value = "attachment; filename=test"
self.service.download(id, **params)
self.service.download(_id, **params)
self.assertEqual(1, request.make_response.call_count)
content, headers = request.make_response.call_args[0]
self.assertTrue(content)
Expand All @@ -21,7 +21,7 @@ def download(self, id, **params):

def test_sale_order_report_without_price(self):
self.sale.action_confirm_cart()
report_with_price = self.download(self.sale.id, no_price=False)
report_with_price = self._test_download(self.sale.id, no_price=False)
prices = [
"885.00",
"2,655.00",
Expand All @@ -32,12 +32,12 @@ def test_sale_order_report_without_price(self):
for price in prices:
self.assertIn(price, report_with_price)

report_without_price = self.download(self.sale.id, no_price=True)
report_without_price = self._test_download(self.sale.id, no_price=True)
for price in prices:
self.assertNotIn(price, report_without_price)

def test_sale_order_report_without_price_default_with_price(self):
self.sale.action_confirm_cart()
default_report = self.download(self.sale.id)
report_with_price = self.download(self.sale.id, no_price=False)
default_report = self._test_download(self.sale.id)
report_with_price = self._test_download(self.sale.id, no_price=False)
self.assertEquals(default_report, report_with_price)

0 comments on commit 9d1f20b

Please sign in to comment.