[ADD] document_page from odoo/7.0

This commit is contained in:
Maxime Chambreuil
2014-09-30 15:38:12 -04:00
committed by Dũng (Trần Đình)
parent 767259fa73
commit 1561edddb8
99 changed files with 21291 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 document_page_create_menu
import document_page_show_diff
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -0,0 +1,93 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 openerp import SUPERUSER_ID
from openerp.osv import fields, osv
class document_page_create_menu(osv.osv_memory):
""" Create Menu """
_name = "document.page.create.menu"
_description = "Wizard Create Menu"
_columns = {
'menu_name': fields.char('Menu Name', size=256, required=True),
'menu_parent_id': fields.many2one('ir.ui.menu', 'Parent Menu',
required=True),
}
def default_get(self, cr, uid, fields, context=None):
if context is None:
context = {}
res = super(document_page_create_menu, self).default_get(cr, uid,
fields,
context=
context)
page_id = context.get('active_id')
obj_page = self.pool.get('document.page')
page = obj_page.browse(cr, uid, page_id, context=context)
res['menu_name'] = page.name
return res
def document_page_menu_create(self, cr, uid, ids, context=None):
if context is None:
context = {}
obj_page = self.pool.get('document.page')
obj_menu = self.pool.get('ir.ui.menu')
obj_action = self.pool.get('ir.actions.act_window')
page_id = context.get('active_id', False)
page = obj_page.browse(cr, uid, page_id, context=context)
datas = self.browse(cr, uid, ids, context=context)
data = False
if datas:
data = datas[0]
if not data:
return {}
value = {
'name': 'Document Page',
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'document.page',
'view_id': False,
'type': 'ir.actions.act_window',
'target': 'inlineview',
}
value['domain'] = "[('parent_id','=',%d)]" % (page.id)
value['res_id'] = page.id
action_id = obj_action.create(cr, SUPERUSER_ID, value)
# only the super user is allowed to create menu due to security rules
# on ir.values
menu_id = obj_menu.create(cr, SUPERUSER_ID, {
'name': data.menu_name,
'parent_id': data.menu_parent_id.id,
'icon': 'STOCK_DIALOG_QUESTION',
'action': 'ir.actions.act_window,' + str(action_id),
}, context)
obj_page.write(cr, uid, [page_id], {'menu_id': menu_id})
return {
'type': 'ir.actions.client',
'tag': 'reload',
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Create Menu From view -->
<record id="view_wiki_create_menu" model="ir.ui.view">
<field name="name">Create Menu</field>
<field name="model">document.page.create.menu</field>
<field name="arch" type="xml">
<form string="Create Menu" version="7.0">
<group string="Menu Information">
<field name="menu_name" />
<field name="menu_parent_id" />
</group>
<footer>
<button name="document_page_menu_create" string="Create Menu" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<!-- Create Menu Action -->
<record id="action_wiki_create_menu" model="ir.actions.act_window">
<field name="name">Create Menu</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">document.page.create.menu</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>

View File

@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 openerp.osv import fields, osv
from openerp.tools.translate import _
class showdiff(osv.osv_memory):
""" Disp[ay Difference for History """
_name = 'wizard.document.page.history.show_diff'
def get_diff(self, cr, uid, context=None):
if context is None:
context = {}
history = self.pool.get('document.page.history')
ids = context.get('active_ids', [])
diff = ""
if len(ids) == 2:
if ids[0] > ids[1]:
diff = history.getDiff(cr, uid, ids[1], ids[0])
else:
diff = history.getDiff(cr, uid, ids[0], ids[1])
elif len(ids) == 1:
old = history.browse(cr, uid, ids[0])
nids = history.search(cr, uid, [('page_id', '=', old.page_id.id)])
nids.sort()
diff = history.getDiff(cr, uid, ids[0], nids[-1])
else:
raise osv.except_osv(_('Warning!'), _('You need to select minimum \
one or maximum two history \
revisions!'))
return diff
_columns = {
'diff': fields.text('Diff', readonly=True),
}
_defaults = {
'diff': get_diff
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Create Index Form view -->
<record id="view_wiki_show_diff" model="ir.ui.view">
<field name="name">Show Difference</field>
<field name="model">wizard.document.page.history.show_diff</field>
<field name="arch" type="xml">
<form string="Difference" version="7.0">
<field name="diff" widget="html" options='{"safe": True}'/>
<footer>
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<!-- Create Index Action -->
<record id="action_view_wiki_show_diff" model="ir.actions.act_window">
<field name="name">Difference</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">wizard.document.page.history.show_diff</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<!-- Create Index Action Window -->
<act_window
id="action_view_wiki_show_diff_values"
key2="client_action_multi"
name="Difference"
res_model="wizard.document.page.history.show_diff"
src_model="document.page.history"
view_mode="form"
target="new"
view_type="form"/>
</data>
</openerp>

View File

@@ -0,0 +1,104 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRl (<http://tiny.be>).
#
# 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 osv import osv
from tools.translate import _
class wiki_make_index(osv.osv_memory):
""" Create Index For Selected Page """
_name = "wiki.make.index"
_description = "Create Index"
def wiki_do_index(self, cr, uid, ids, context=None):
""" Makes Index according to page hierarchy
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: list of wiki indexs IDs
"""
if context is None:
context = {}
data = context and context.get('active_ids', []) or []
if not data:
return {'type': 'ir.actions.act_window_close'}
for index_obj in self.browse(cr, uid, ids, context=context):
wiki_pool = self.pool.get('wiki.wiki')
cr.execute("Select id, section from wiki_wiki where id IN %s \
order by section ", (tuple(data),))
lst0 = cr.fetchall()
if not lst0[0][1]:
raise osv.except_osv(_('Warning!'), _('There is no section in\
this Page.'))
lst = []
s_ids = {}
for l in lst0:
s_ids[l[1]] = l[0]
lst.append(l[1])
lst.sort()
val = None
def toint(x):
try:
return int(x)
except:
return 1
lst = map(lambda x: map(toint, x.split('.')), lst)
result = []
current = ['0']
current2 = []
for l in lst:
for pos in range(len(l)):
if pos >= len(current):
current.append('1')
continue
if (pos == len(l) - 1) or (pos >= len(current2)) or \
(toint(l[pos]) > toint(current2[pos])):
current[pos] = str(toint(current[pos]) + 1)
current = current[:pos + 1]
if pos == len(l) - 1:
break
key = ('.'.join([str(x) for x in l]))
id = s_ids[key]
val = ('.'.join([str(x) for x in current[:]]), id)
if val:
result.append(val)
current2 = l
for rs in result:
wiki_pool.write(cr, uid, [rs[1]], {'section': rs[0]})
return {'type': 'ir.actions.act_window_close'}
wiki_make_index()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Create Index Form view -->
<record id="view_wiki_make_index" model="ir.ui.view">
<field name="name">Create Index</field>
<field name="model">wiki.make.index</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Create Menu" version="7.0">
<separator string="Menu Information"/>
<label string="Want to create a Index on Selected Pages ? "/>
<footer>
<button name="wiki_do_index" string="Create Index" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<!-- Create Index Action -->
<record id="action_view_wiki_make_index" model="ir.actions.act_window">
<field name="name">Create Index</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">wiki.make.index</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<!-- Create Index Action Window -->
<act_window id="action_view_wiki_make_index_values"
key2="client_action_multi" name="Create Index"
res_model="wiki.make.index" src_model="wiki.wiki"
view_mode="form" target="new" view_type="form" />
</data>
</openerp>

View File

@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 osv import osv
class wiki_wiki_page_open(osv.osv_memory):
""" wizard Open Page """
_name = "wiki.wiki.page.open"
_description = "wiz open page"
def open_wiki_page(self, cr, uid, ids, context=None):
""" Opens Wiki Page of Group
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param ids: List of open wiki pages IDs
@return: dictionay of open wiki window on give group id
"""
if context is None:
context = {}
group_ids = context.get('active_ids', [])
for group in self.pool.get('wiki.groups').browse(cr, uid, group_ids,
context=context):
value = {
'domain': "[('group_id','=',%d)]" % (group.id),
'name': 'Wiki Page',
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'wiki.wiki',
'view_id': False,
'type': 'ir.actions.act_window',
}
if group.method == 'page':
value['res_id'] = group.home.id
elif group.method == 'list':
value['view_type'] = 'form'
value['view_mode'] = 'tree,form'
elif group.method == 'tree':
view_id = self.pool.get('ir.ui.view').\
search(cr, uid, [('name', '=',
'wiki.wiki.tree.children')])
value['view_id'] = view_id
value['domain'] = [('group_id', '=', group.id), ('parent_id', '=',
False)]
value['view_type'] = 'tree'
return value
wiki_wiki_page_open()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Open Page Form view -->
<record id="view_wiki_wiki_page_open" model="ir.ui.view">
<field name="name">Open Page</field>
<field name="model">wiki.wiki.page.open</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Open Page" version="7.0">
<label string="Want to open a wiki page? "/>
<footer>
<button name="open_wiki_page" string="Open Wiki Page" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<!-- Open Page Action -->
<record id="action_view_wiki_wiki_page_open" model="ir.actions.act_window">
<field name="name">Open Page</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">wiki.wiki.page.open</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>