Mathias Markl 7 years ago
parent
commit
2cf0fea232
  1. 133
      muk_web_client_refresh/models/refresh_rule.py
  2. 3
      muk_web_client_refresh/security/ir.model.access.csv
  3. BIN
      muk_web_client_refresh/static/description/demo.mp4
  4. 23
      muk_web_client_refresh/tests/__init__.py
  5. 76
      muk_web_client_refresh/tests/test_refresh.py
  6. 27
      muk_web_client_refresh/views/refresh_menu.xml
  7. 65
      muk_web_client_refresh/views/refresh_rule_view.xml
  8. 2
      muk_web_preview_mail/tests/test_mail_parse.py
  9. 2
      muk_web_preview_rst/tests/test_rst.py

133
muk_web_client_refresh/models/refresh_rule.py

@ -1,133 +0,0 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
#
###################################################################################
import logging
from odoo import _
from odoo import models, modules, api, fields
from odoo.exceptions import ValidationError, AccessError
_logger = logging.getLogger(__name__)
class RefreshRule(models.Model):
_name = 'muk_web_client_refresh.rule'
_description = "Auto Refresh Rule"
name = fields.Char(
string="Name",
required=True)
model = fields.Many2one(
'ir.model',
string="Model",
required=True,
help="Select model for which you want to refresh the corresponding views.")
refresh_create = fields.Boolean(
string="Refresh on Create",
default=True)
refresh_write = fields.Boolean(
string="Refresh on Writes",
default=True)
refresh_unlink = fields.Boolean(
string="Refresh on Unlink",
default=True)
_sql_constraints = [
('model_uniq', 'unique(model)',
("There is already a rule defined on this model."))
]
def _register_hook(self):
super(RefreshRule, self)._register_hook()
return self._patch_methods()
@api.multi
def _patch_methods(self):
for rule in self:
model = self.env[rule.model.model]
if rule.refresh_create:
model._patch_method('create', rule._make_create())
if rule.refresh_write:
model._patch_method('write', rule._make_write())
if rule.refresh_unlink:
model._patch_method('unlink', rule._make_unlink())
@api.multi
def _revert_methods(self):
for rule in self:
model = self.env[rule.model.model]
for method in ['create', 'write', 'unlink']:
if getattr(rule, 'refresh_%s' % method) and hasattr(getattr(model, method), 'origin'):
model._revert_method(method)
@api.model
def create(self, vals):
record = super(RefreshRule, self).create(vals)
record._register_hook()
modules.registry.Registry(self.env.cr.dbname).signal_changes()
return record
@api.multi
def write(self, vals):
self._revert_methods()
result = super(RefreshRule, self).write(vals)
self._patch_methods()
modules.registry.Registry(self.env.cr.dbname).signal_changes()
return result
@api.multi
def unlink(self):
self._revert_methods()
modules.registry.Registry(self.env.cr.dbname).signal_changes()
return super(RefreshRule, self).unlink()
@api.multi
def _make_create(self):
@api.model
@api.returns('self', lambda value: value.id)
def create_refresh(self, vals, **kwargs):
result = create_refresh.origin(self, vals, **kwargs)
self.env['bus.bus'].sendone('refresh', [self.env.cr.dbname, self._name, self._uid])
return result
return create_refresh
@api.multi
def _make_write(self):
@api.multi
def write_refresh(self, vals, **kwargs):
result = write_refresh.origin(self, vals, **kwargs)
self.env['bus.bus'].sendone('refresh', [self.env.cr.dbname, self._name, self._uid])
return result
return write_refresh
@api.multi
def _make_unlink(self):
@api.multi
def unlink_refresh(self, **kwargs):
result = unlink_refresh.origin(self, **kwargs)
self.env['bus.bus'].sendone('refresh', [self.env.cr.dbname, self._name, self._uid])
return result
return unlink_refresh

3
muk_web_client_refresh/security/ir.model.access.csv

@ -1,3 +0,0 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_refresh_rule_manager,refresh_rule_manager,model_muk_web_client_refresh_rule,base.group_erp_manager,1,1,1,1

BIN
muk_web_client_refresh/static/description/demo.mp4

23
muk_web_client_refresh/tests/__init__.py

@ -1,23 +0,0 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
#
###################################################################################
from . import test_refresh

76
muk_web_client_refresh/tests/test_refresh.py

@ -1,76 +0,0 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
#
###################################################################################
import os
import base64
import unittest
from contextlib import closing
from odoo import _
from odoo.tests import common
class RefreshTestCase(common.TransactionCase):
at_install = False
post_install = True
def setUp(self):
super(RefreshTestCase, self).setUp()
self.partner = self.env['res.partner'].sudo()
self.model = self.env['ir.model'].sudo()
self.bus = self.env['bus.bus'].sudo()
self.rule = self.env['muk_web_client_refresh.rule'].sudo()
def tearDown(self):
super(RefreshTestCase, self).tearDown()
def test_refresh_rule(self):
start = self.bus.search([], count=True)
model = self.model.search([('model', '=', 'res.partner')], limit=1)
rule = self.rule.create({
'name': "TestRule",
'model': model.id,
'refresh_create': True,
'refresh_write': True,
'refresh_unlink': True})
partner = self.partner.create({
'name': "Test",
})
create = self.bus.search([], count=True)
self.assertTrue(start < create)
partner.write({'name': "Rename"})
write = self.bus.search([], count=True)
self.assertTrue(write > create)
partner.unlink()
delete = self.bus.search([], count=True)
self.assertTrue(write < delete)
rule.write({'refresh_create': False})
start = self.bus.search([], count=True)
partner = self.partner.create({
'name': "Test",
})
create = self.bus.search([], count=True)
self.assertTrue(start == create)
rule.unlink()
partner.unlink()
delete = self.bus.search([], count=True)
self.assertTrue(start == delete)

27
muk_web_client_refresh/views/refresh_menu.xml

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
-->
<odoo>
<menuitem id="cat_menu_refresh"
name="Auto Refresh"
sequence="50"
parent="base.menu_custom" />
</odoo>

65
muk_web_client_refresh/views/refresh_rule_view.xml

@ -1,65 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (C) 2017 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 <http://www.gnu.org/licenses/>.
-->
<odoo>
<record id="view_refresh_rule_tree" model="ir.ui.view">
<field name="name">muk_web_client_refresh_rule.tree</field>
<field name="model">muk_web_client_refresh.rule</field>
<field name="arch" type="xml">
<tree string="Document Settings">
<field name="name" />
<field name="model"/>
<field name="refresh_create" />
<field name="refresh_write" />
<field name="refresh_unlink" />
</tree>
</field>
</record>
<record id="view_refresh_rule_form" model="ir.ui.view">
<field name="name">muk_web_client_refresh_rule.form</field>
<field name="model">muk_web_client_refresh.rule</field>
<field name="arch" type="xml">
<form string="Refresh Rule">
<sheet>
<group string="General">
<field name="name"/>
<field name="model"/>
</group>
<group string="Access Rights">
<field name="refresh_create"/>
<field name="refresh_write"/>
<field name="refresh_unlink"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="action_refresh_rule" model="ir.actions.act_window">
<field name="name">Rules</field>
<field name="res_model">muk_web_client_refresh.rule</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_dms_settings" name="Rules"
parent="cat_menu_refresh" action="action_refresh_rule" />
</odoo>

2
muk_web_preview_mail/tests/test_mail_parse.py

@ -44,7 +44,7 @@ class MailParseTestCase(common.HttpCase):
def test_parse_mail(self): def test_parse_mail(self):
self.authenticate('admin', 'admin') self.authenticate('admin', 'admin')
url = "/web/preview/converter/mail"
url = "/web/preview/mail"
params = {'url': "/web/content?id={}".format(self.sample_mail_attachment.id)} params = {'url': "/web/content?id={}".format(self.sample_mail_attachment.id)}
url_parts = list(urlparse(url)) url_parts = list(urlparse(url))
query = dict(parse_qsl(url_parts[4])) query = dict(parse_qsl(url_parts[4]))

2
muk_web_preview_rst/tests/test_rst.py

@ -44,7 +44,7 @@ class ReStructuredTextParseTestCase(common.HttpCase):
def test_rst(self): def test_rst(self):
self.authenticate('admin', 'admin') self.authenticate('admin', 'admin')
url = "/web/preview/converter/mail"
url = "/web/preview/rst"
params = {'url': "/web/content?id={}".format(self.sample.id)} params = {'url': "/web/content?id={}".format(self.sample.id)}
url_parts = list(urlparse(url)) url_parts = list(urlparse(url))
query = dict(parse_qsl(url_parts[4])) query = dict(parse_qsl(url_parts[4]))

Loading…
Cancel
Save