Skip to content

Commit

Permalink
[ADD] Module smile_assets_version
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien DRECQ committed Nov 26, 2021
1 parent 2ad0256 commit bc358e6
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions smile_assets_version/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# (C) 2019 Smile (<http://www.smile.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
25 changes: 25 additions & 0 deletions smile_assets_version/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# (C) 2019 Smile (<http://www.smile.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Smile Assets Version",
"version": "0.1",
"sequence": 100,
"category": "Tools",
"author": "Smile",
"license": 'AGPL-3',
"website": 'http://www.smile.fr',
"description": """
This module replace checksum on files assets by checksum based on
code_version of smile_upgrade when server.environment == prod
""",
"depends": [
'website',
'smile_upgrade',
],
"data": [],
'installable': True,
'auto_install': True,
'application': False,
}
5 changes: 5 additions & 0 deletions smile_assets_version/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# (C) 2019 Smile (<http://www.smile.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import ir_qweb
34 changes: 34 additions & 0 deletions smile_assets_version/models/ir_qweb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# (C) 2019 Smile (<http://www.smile.fr>)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

import hashlib
import json

from odoo import models, tools
from odoo.addons.website.models.ir_qweb import AssetsBundleMultiWebsite


class SmileAssetsVersionBundle(AssetsBundleMultiWebsite):

@tools.func.lazy_property
def checksum(self):
def old_checksum():
check = u"%s%s" % (json.dumps(self.files, sort_keys=True),
self.last_modified)
return hashlib.sha1(check.encode('utf-8')).hexdigest()
if tools.config.get('server.environment', False) in \
['preprod', 'prod']:
code_version = \
self.env['ir.config_parameter'].sudo().get_param(
'code.version')
if code_version:
return hashlib.sha1(code_version.encode('utf-8')).hexdigest()
return old_checksum()


class QWeb(models.AbstractModel):
_inherit = 'ir.qweb'

def get_asset_bundle(self, xmlid, files, remains=None, env=None):
return SmileAssetsVersionBundle(xmlid, files, remains=remains, env=env)
Binary file added smile_assets_version/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bc358e6

Please sign in to comment.