1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2012-Today Serpent Consulting Services (<http://www.serpentcs.com>)
6
# Copyright (C) 2010-Today OpenERP SA (<http://www.openerp.com>)
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>
21
##############################################################################
24
from osv import fields
25
from lxml import etree
28
class mass_editing_wizard(osv.osv_memory):
29
_name = 'mass.editing.wizard'
35
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
36
result = super(mass_editing_wizard, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar,submenu)
37
if context.get('mass_editing_object'):
38
mass_object = self.pool.get('mass.object')
39
editing_data = mass_object.browse(cr, uid, context.get('mass_editing_object'), context)
41
xml_form = etree.Element('form', {'string': tools.ustr(editing_data.name), 'version':'7.0'})
42
xml_group = etree.SubElement(xml_form, 'group', {'colspan': '4'})
43
etree.SubElement(xml_group, 'label', {'string': '','colspan': '2'})
44
xml_group = etree.SubElement(xml_form, 'group', {'colspan': '4'})
45
model_obj = self.pool.get(context.get('active_model'))
46
for field in editing_data.field_ids:
47
if field.ttype == "many2many":
48
field_info = model_obj.fields_get(cr, uid, [field.name], context)
49
all_fields[field.name] = field_info[field.name]
50
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove_m2m','Remove'),('add','Add')]}
51
xml_group = etree.SubElement(xml_group, 'group', {'colspan': '4'})
52
etree.SubElement(xml_group, 'separator', {'string': field_info[field.name]['string'],'colspan': '2'})
53
etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name,'colspan': '2','nolabel':'1'})
54
etree.SubElement(xml_group, 'field', {'name': field.name, 'colspan':'4', 'nolabel':'1', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove_m2m')]}"})
55
elif field.ttype == "many2one":
56
field_info = model_obj.fields_get(cr, uid, [field.name], context)
58
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove','Remove')]}
59
all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'relation': field.relation}
60
etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name, 'colspan':'2'})
61
etree.SubElement(xml_group, 'field', {'name': field.name,'nolabel':'1','colspan':'2', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}"})
62
elif field.ttype == "char":
63
field_info = model_obj.fields_get(cr, uid, [field.name], context)
64
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove','Remove')]}
65
all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'size': field.size or 256}
66
etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name,'colspan':'2', 'colspan':'2'})
67
etree.SubElement(xml_group, 'field', {'name': field.name,'nolabel':'1', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}", 'colspan':'2'})
68
elif field.ttype == 'selection':
69
field_info = model_obj.fields_get(cr, uid, [field.name], context)
70
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove','Remove')]}
71
field_info = model_obj.fields_get(cr, uid, [field.name], context)
72
etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name, 'colspan':'2'})
73
etree.SubElement(xml_group, 'field', {'name': field.name,'nolabel':'1','colspan':'2', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}"})
74
all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'selection': field_info[field.name]['selection']}
76
field_info = model_obj.fields_get(cr, uid, [field.name], context)
77
all_fields[field.name] = {'type':field.ttype, 'string': field.field_description}
78
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove','Remove')]}
79
if field.ttype == 'text':
80
xml_group = etree.SubElement(xml_group, 'group', {'colspan': '6'})
81
etree.SubElement(xml_group, 'separator', {'string': all_fields[field.name]['string'],'colspan': '2'})
82
etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name,'colspan': '2','nolabel':'1'})
83
etree.SubElement(xml_group, 'field', {'name': field.name, 'colspan':'4', 'nolabel':'1', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}"})
85
all_fields["selection_"+field.name] = {'type':'selection', 'string': field_info[field.name]['string'],'selection':[('set','Set'),('remove','Remove')]}
86
etree.SubElement(xml_group, 'field', {'name': "selection_"+field.name, 'colspan': '2',})
87
etree.SubElement(xml_group, 'field', {'name': field.name,'nolabel':'1', 'attrs':"{'invisible':[('selection_"+field.name+"','=','remove')]}",'colspan': '2',})
89
etree.SubElement(xml_form, 'separator', {'string' : '','colspan': '4'})
90
xml_group3 = etree.SubElement(xml_form, 'footer', {})
91
etree.SubElement(xml_group3, 'button', {'string' :'Close','icon': "gtk-close", 'special' :'cancel'})
92
etree.SubElement(xml_group3, 'button', {'string' :'Apply','icon': "gtk-execute", 'type' :'object','name':"action_apply"})
94
root = xml_form.getroottree()
95
result['arch'] = etree.tostring(root)
96
result['fields'] = all_fields
99
def create(self, cr, uid, vals, context=None):
100
if context.get('active_model') and context.get('active_ids'):
101
model_obj = self.pool.get(context.get('active_model'))
103
for key ,val in vals.items():
104
if key.startswith('selection_'):
105
split_key= key.split('_',1)[1]
107
dict.update({split_key: vals.get(split_key, False)})
108
elif val == 'remove':
109
dict.update({split_key: False})
110
elif val == 'remove_m2m':
111
dict.update({split_key: [(5,0,[])]})
114
for m2m_id in vals.get(split_key, False)[0][2]:
115
m2m_list.append((4, m2m_id))
116
dict.update({split_key: m2m_list})
118
model_obj.write(cr, uid, context.get('active_ids'), dict, context)
119
result = super(mass_editing_wizard, self).create(cr, uid, {}, context)
122
def action_apply(self, cr, uid, ids, context=None):
123
return {'type': 'ir.actions.act_window_close'}
125
mass_editing_wizard()
127
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: