From 5b042f5031771697c4de69915b303cf816685c14 Mon Sep 17 00:00:00 2001 From: MuK IT GmbH Date: Mon, 5 Nov 2018 14:37:48 +0000 Subject: [PATCH] publish muk_web_client_refresh - 12.0 --- muk_web_client_refresh/__init__.py | 23 ++++++- muk_web_client_refresh/__manifest__.py | 4 +- muk_web_client_refresh/doc/changelog.rst | 5 ++ muk_web_client_refresh/models/__init__.py | 1 + .../models/base_automation.py | 62 +++++++++++++++++++ .../static/description/index.html | 13 ++-- 6 files changed, 101 insertions(+), 7 deletions(-) create mode 100644 muk_web_client_refresh/models/base_automation.py diff --git a/muk_web_client_refresh/__init__.py b/muk_web_client_refresh/__init__.py index 64773bc..9a3acec 100644 --- a/muk_web_client_refresh/__init__.py +++ b/muk_web_client_refresh/__init__.py @@ -17,5 +17,26 @@ # ################################################################################### +from odoo import api, SUPERUSER_ID + from . import controllers -from . import models \ No newline at end of file +from . import models + +REFRESH_RULE_MODELS = [ + 'account.bank.statement', 'account.invoice', 'account.journal', + 'account.move', 'crm.lead', 'event.event', 'fleet.vehicle', 'hr.contract', + 'hr.department', 'hr.employee', 'hr.job', 'hr.leave', 'lunch.order', + 'mrp.bom', 'mrp.document', 'mrp.workorder', 'product.category', + 'product.template', 'project.project', 'project.task', 'purchase.order', + 'repair.order', 'res.partner', 'res.users', 'sale.order', 'slide.slide', + 'stock.inventory', 'stock.move', 'survey.page', 'survey.survey', +] + +def _install_initialize_rules(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + for model_name in REFRESH_RULE_MODELS: + env['base.automation'].create_refresh_rules(model_name) + +def _uninstall_remove_rules(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + env['base.automation'].search([('state', '=', 'refresh')]).unlink() diff --git a/muk_web_client_refresh/__manifest__.py b/muk_web_client_refresh/__manifest__.py index 76a76e6..3cbe3b2 100644 --- a/muk_web_client_refresh/__manifest__.py +++ b/muk_web_client_refresh/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Web Refresh", "summary": """Web Client Refresh""", - "version": "12.0.2.1.6", + "version": "12.0.2.2.0", "category": "Extra Tools", "license": "AGPL-3", "website": "http://www.mukit.at", @@ -51,4 +51,6 @@ }, "application": False, "installable": True, + "post_init_hook": "_install_initialize_rules", + "uninstall_hook": "_uninstall_remove_rules", } \ No newline at end of file diff --git a/muk_web_client_refresh/doc/changelog.rst b/muk_web_client_refresh/doc/changelog.rst index dbc118c..18c3cf2 100644 --- a/muk_web_client_refresh/doc/changelog.rst +++ b/muk_web_client_refresh/doc/changelog.rst @@ -1,3 +1,8 @@ +`2.2.0` +------- + +- Automatically initiate refresh rules + `2.1.0` ------- diff --git a/muk_web_client_refresh/models/__init__.py b/muk_web_client_refresh/models/__init__.py index b2536e5..212b347 100644 --- a/muk_web_client_refresh/models/__init__.py +++ b/muk_web_client_refresh/models/__init__.py @@ -19,4 +19,5 @@ from . import base from . import ir_actions +from . import base_automation from . import res_config_settings diff --git a/muk_web_client_refresh/models/base_automation.py b/muk_web_client_refresh/models/base_automation.py new file mode 100644 index 0000000..8d5465b --- /dev/null +++ b/muk_web_client_refresh/models/base_automation.py @@ -0,0 +1,62 @@ +################################################################################### +# +# Copyright (C) 2018 MuK IT GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +import logging + +from odoo import api, models, fields + +_logger = logging.getLogger(__name__) + +class BaseAutomation(models.Model): + + _inherit = 'base.automation' + + #---------------------------------------------------------- + # Functions + #---------------------------------------------------------- + + @api.model + def create_refresh_rules(self, model_name): + model = self.env['ir.model'].search( + [('model', '=', model_name)], limit=1) + if model_name in self.env and model.exists(): + triggers = [ + ('on_create', 'Creation'), + ('on_write', 'Update'), + ('on_unlink', 'Deletion') + ] + for trigger in triggers: + refresh_rules = self.search([ + ('model_id', '=', model.id), + ('trigger', '=', trigger[0]) + ], limit=1) + if refresh_rules.exists(): + refresh_rules.write({ + 'active': True + }) + else: + self.create({ + 'trigger': trigger[0], + 'state': 'refresh', + 'model_id': model.id, + 'name': "Refresh %s on %s" % ( + model.name, + trigger[1] + ) + }) \ No newline at end of file diff --git a/muk_web_client_refresh/static/description/index.html b/muk_web_client_refresh/static/description/index.html index 5bad68c..40a1031 100644 --- a/muk_web_client_refresh/static/description/index.html +++ b/muk_web_client_refresh/static/description/index.html @@ -52,7 +52,7 @@
-

Customize Process

+

Chatter Support

@@ -101,15 +101,18 @@ contact us, if you need any help with your Odoo integration or addiontal features.
\ No newline at end of file