Skip to content

Commit

Permalink
[MIG] Migration smile_base to v14
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien DRECQ committed Feb 25, 2021
1 parent 0f5813a commit 66b64d6
Show file tree
Hide file tree
Showing 39 changed files with 2,033 additions and 0 deletions.
91 changes: 91 additions & 0 deletions smile_base/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
==========
Smile Base
==========

.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-Smile_SA%2Fodoo_addons-lightgray.png?logo=github
:target: https://github.com/Smile-SA/odoo_addons/tree/13.0/smile_base
:alt: Smile-SA/odoo_addons

|badge2| |badge3|

* Make French the default language if installed
* Disable the scheduled action "Update Notification" which sends companies and users info to Odoo S.A.
* Correct date and time format for French language
* Review the menu "Applications"
* Remove the menu "App store" and "Update modules" from apps.odoo.com.
* Add sequence and display window actions in IrValues
* Force to call unlink method at removal of remote object linked by a fields.many2one with ondelete='cascade'
* Add BaseModel.store_set_values and BaseModel._compute_store_set
* Improve BaseModel.load method performance
* Disable email sending/fetching by default

**Table of contents**

.. contents::
:local:

Usage
=====

Add this module to your addons, it will auto install.

To enable email sending, add in your configuration file:
* enable_email_sending = True

To enable email fetching, add in your configuration file:
* enable_email_fetching = True

To enable sending of companies and users info to Odoo S.A., add in your configuration file:
* enable_publisher_warranty_contract_notification = True

Changes done at migration
=========================

The feature adding a colored ribbon to make your environments recognisable at
first glance was removed during migration to Odoo 12.0.
We recommand to instead install modules `web_environment_ribbon <https://github.com/OCA/web/tree/12.0/web_environment_ribbon>`_ and `server_environment_ir_config_parameter <https://github.com/OCA/server-env/tree/12.0/server_environment_ir_config_parameter>`_.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/Smile-SA/odoo_addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/Smile-SA/odoo_addons/issues/new?body=module:%20smile_base%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

GDPR / EU Privacy
=================

This addons does not collect any data and does not set any browser cookies.

Credits
=======

Authors
~~~~~~~

* Smile SA

Contributors
~~~~~~~~~~~~

* Corentin Pouhet-Brunerie
* Majda EL MARIOULI

Maintainers
~~~~~~~~~~~

This module is maintained by the Smile SA.

Since 1991 Smile has been a pioneer of technology and also the European expert in open source solutions.

.. image:: https://avatars0.githubusercontent.com/u/572339?s=200&v=4
:alt: Smile SA
:target: http://smile.fr

This module is part of the `odoo-addons <https://github.com/Smile-SA/odoo_addons>`_ project on GitHub.

You are welcome to contribute.
94 changes: 94 additions & 0 deletions smile_base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# -*- coding: utf-8 -*-
# (C) 2019 Smile (<http://www.smile.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import controllers
from . import models
from . import tools
from . import wizard

from odoo.api import Environment, SUPERUSER_ID
from odoo import tools


def pre_init_hook(cr):
env = Environment(cr, SUPERUSER_ID, {})
fetchmail = env['ir.module.module'].search([
('name', '=', 'fetchmail'),
], limit=1)
if fetchmail.state != 'installed':
fetchmail.button_install()


def post_init_hook(cr, registry):
add_act_window_id_in_context(cr)
disable_update_notification_cron(cr)
set_default_lang(cr)
correct_datetime_format_fr(cr)
correct_datetime_format_eng(cr)
remove_menus(cr)


def add_act_window_id_in_context(cr):
env = Environment(cr, SUPERUSER_ID, {})
env['ir.actions.act_window'].with_context(active_test=False).search([])._update_context()


def disable_update_notification_cron(cr):
env = Environment(cr, SUPERUSER_ID, {})
cron = env.ref('mail.ir_cron_module_update_notification', False)
if cron:
cron.active = tools.config.get(
'enable_publisher_warranty_contract_notification', False)


def set_default_lang(cr):
env = Environment(cr, SUPERUSER_ID, {})
if env['res.lang'].search([('code', '=', 'fr_FR')], limit=1):
partner_lang_field_id = env.ref('base.field_res_partner__lang').id
value = env['ir.default'].search([('field_id', '=', partner_lang_field_id)], limit=1)
vals = {
'field_id': partner_lang_field_id,
'json_value': '"fr_FR"',
}
if value:
value.write(vals)
else:
value.create(vals)


def correct_datetime_format_fr(cr):
env = Environment(cr, SUPERUSER_ID, {})
language = env['res.lang'].search([('code', '=', 'fr_FR')], limit=1)
if language:
language.write({
'date_format': '%d/%m/%Y',
'time_format': '%H:%M:%S',
'grouping': '[3, 3, 3, 3, 3]',
'decimal_point': ',',
'thousands_sep': ' ',
})


def correct_datetime_format_eng(cr):
env = Environment(cr, SUPERUSER_ID, {})
language = env['res.lang'].search([('code', '=', 'en_US')], limit=1)
if language:
language.write({
'date_format': '%m/%d/%Y',
'time_format': '%H:%M:%S',
'grouping': '[3, 3, 3, 3, 3]',
'decimal_point': '.',
'thousands_sep': ',',
})


def remove_menus(cr):
env = Environment(cr, SUPERUSER_ID, {})
for menu_id in ('base.module_mi', 'base.menu_module_updates'):
try:
env.ref(menu_id).unlink()
except ValueError:
pass


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

{
"name": "Smile Base",
"version": "0.2.3",
"depends": [
'mail',
'web_editor',
],
"author": "Smile",
"license": 'AGPL-3',
"description": """""",
"summary": "",
"website": "",
"category": 'Tools',
"sequence": 20,
"data": [
"security/base_security.xml",
"security/res_users.xml",
"data/warning_data.xml",
"views/ir_actions_view.xml",
"views/template.xml",
"views/ir_actions_server_view.xml",
],
"qweb": [
"static/src/xml/base.xml",
],
"pre_init_hook": 'pre_init_hook',
"post_init_hook": 'post_init_hook',
"auto_install": True,
"installable": True,
"application": False,
}
5 changes: 5 additions & 0 deletions smile_base/controllers/__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 main
76 changes: 76 additions & 0 deletions smile_base/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
# (C) 2019 Smile (<http://www.smile.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64

from odoo import http
from odoo.http import request

from odoo.addons.web.controllers.main import content_disposition


class Download(http.Controller):
"""
Example of utilisation:
1) Add a "Download" button of type "object" on your form view
2) Define the method for downloading the file
from odoo import api, models
from odoo.tools import ustr
class StockMove(models.Model):
_inherit = 'stock.move'
def _get_datas(self):
self.ensure_one()
return ustr("Stock n°%s") % self.id
def button_get_file(self):
self.ensure_one()
return {
'type': 'ir.actions.act_url',
'url': '/download/saveas?model=%(model)s&record_id
%(record_id)s&method=%(method)s&filename=%(filename)s' % {
'filename': 'stock_infos.txt',
'model': self._name,
'record_id': self.id,
'method': '_get_datas',
},
'target': 'self',
}
"""

@http.route('/download/saveas', type='http', auth="public")
def saveas(self, model, record_id, method, encoded=False, filename=None,
**kw):
""" Download link for files generated on the fly.
:param str model: name of the model to fetch the data from
:param str record_id: id of the record from which to fetch the data
:param str method: name of the method used to fetch data
:param bool encoded: whether the data is encoded in base64
:param str filename: the file's name, if any
:returns: :class:`werkzeug.wrappers.Response`
"""
Model = request.registry[model]
cr, uid, context = request.cr, request.uid, request.context
datas = getattr(Model, method)(cr, uid, int(record_id), context)
if not datas:
return request.not_found()
filecontent = datas[0]
if not filecontent:
return request.not_found()
if encoded:
filecontent = base64.b64decode(filecontent)
if not filename:
filename = '%s_%s' % (model.replace('.', '_'), record_id)
return request.make_response(
filecontent, [
('Content-Type', 'application/octet-stream'),
('Content-Disposition', content_disposition(filename)),
])
16 changes: 16 additions & 0 deletions smile_base/data/warning_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<data noupdate="1">

<record id="warning_popup" model="ir.actions.server">
<field name="name">Warning</field>
<field name="model_id" ref="base.model_res_users"/>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">raise Warning(env['ir.translation']._get_source(None, 'code', user.lang, source='Feature not yet implemented'))</field>
</record>

</data>

</odoo>
Loading

0 comments on commit 66b64d6

Please sign in to comment.