|
@ -2,7 +2,8 @@ |
|
|
############################################################################## |
|
|
############################################################################## |
|
|
# |
|
|
# |
|
|
# This module uses OpenERP, Open Source Management Solution Framework. |
|
|
# This module uses OpenERP, Open Source Management Solution Framework. |
|
|
# Copyright (C) 2012-Today Serpent Consulting Services (<http://www.serpentcs.com>) |
|
|
|
|
|
|
|
|
# Copyright (C): |
|
|
|
|
|
# 2012-Today Serpent Consulting Services (<http://www.serpentcs.com>) |
|
|
# |
|
|
# |
|
|
# This program is free software: you can redistribute it and/or modify |
|
|
# This program is free software: you can redistribute it and/or modify |
|
|
# it under the terms of the GNU General Public License as published by |
|
|
# it under the terms of the GNU General Public License as published by |
|
@ -19,80 +20,165 @@ |
|
|
# |
|
|
# |
|
|
############################################################################## |
|
|
############################################################################## |
|
|
|
|
|
|
|
|
from openerp.osv import orm, fields |
|
|
|
|
|
|
|
|
from openerp.osv import orm |
|
|
import openerp.tools as tools |
|
|
import openerp.tools as tools |
|
|
from lxml import etree |
|
|
from lxml import etree |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class mass_editing_wizard(orm.TransientModel): |
|
|
class mass_editing_wizard(orm.TransientModel): |
|
|
_name = 'mass.editing.wizard' |
|
|
_name = 'mass.editing.wizard' |
|
|
|
|
|
|
|
|
_columns = { |
|
|
_columns = { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): |
|
|
|
|
|
result = super(mass_editing_wizard, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu) |
|
|
|
|
|
|
|
|
def fields_view_get( |
|
|
|
|
|
self, cr, uid, view_id=None, view_type='form', context=None, |
|
|
|
|
|
toolbar=False, submenu=False): |
|
|
|
|
|
result = super(mass_editing_wizard, self).fields_view_get( |
|
|
|
|
|
cr, uid, view_id, view_type, context, toolbar, submenu) |
|
|
if context.get('mass_editing_object'): |
|
|
if context.get('mass_editing_object'): |
|
|
mass_object = self.pool.get('mass.object') |
|
|
mass_object = self.pool.get('mass.object') |
|
|
editing_data = mass_object.browse(cr, uid, context.get('mass_editing_object'), context) |
|
|
|
|
|
|
|
|
editing_data = mass_object.browse( |
|
|
|
|
|
cr, uid, context.get('mass_editing_object'), context) |
|
|
all_fields = {} |
|
|
all_fields = {} |
|
|
xml_form = etree.Element('form', {'string': tools.ustr(editing_data.name), 'version':'7.0'}) |
|
|
|
|
|
|
|
|
xml_form = etree.Element('form', { |
|
|
|
|
|
'string': tools.ustr(editing_data.name), 'version': '7.0'}) |
|
|
xml_group = etree.SubElement(xml_form, 'group', {'colspan': '4'}) |
|
|
xml_group = etree.SubElement(xml_form, 'group', {'colspan': '4'}) |
|
|
etree.SubElement(xml_group, 'label', {'string': '', 'colspan': '2'}) |
|
|
|
|
|
|
|
|
etree.SubElement(xml_group, 'label', { |
|
|
|
|
|
'string': '', 'colspan': '2'}) |
|
|
xml_group = etree.SubElement(xml_form, 'group', {'colspan': '4'}) |
|
|
xml_group = etree.SubElement(xml_form, 'group', {'colspan': '4'}) |
|
|
model_obj = self.pool.get(context.get('active_model')) |
|
|
model_obj = self.pool.get(context.get('active_model')) |
|
|
field_info = model_obj.fields_get(cr, uid, [], context) |
|
|
field_info = model_obj.fields_get(cr, uid, [], context) |
|
|
for field in editing_data.field_ids: |
|
|
for field in editing_data.field_ids: |
|
|
if field.ttype == "many2many": |
|
|
if field.ttype == "many2many": |
|
|
all_fields[field.name] = field_info[field.name] |
|
|
all_fields[field.name] = field_info[field.name] |
|
|
all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove_m2m', 'Remove'), ('add', 'Add')]} |
|
|
|
|
|
xml_group = etree.SubElement(xml_group, 'group', {'colspan': '4'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'separator', {'string': field_info[field.name]['string'], 'colspan': '2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': "selection__" + field.name, 'colspan': '2', 'nolabel':'1'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': field.name, 'colspan':'4', 'nolabel':'1', 'attrs':"{'invisible':[('selection__" + field.name + "','=','remove_m2m')]}"}) |
|
|
|
|
|
|
|
|
all_fields["selection__" + field.name] = { |
|
|
|
|
|
'type': 'selection', |
|
|
|
|
|
'string': field_info[field.name]['string'], |
|
|
|
|
|
'selection': [ |
|
|
|
|
|
('set', 'Set'), ('remove_m2m', 'Remove'), |
|
|
|
|
|
('add', 'Add')]} |
|
|
|
|
|
xml_group = etree.SubElement(xml_group, 'group', { |
|
|
|
|
|
'colspan': '4'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'separator', { |
|
|
|
|
|
'string': field_info[field.name]['string'], |
|
|
|
|
|
'colspan': '2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': "selection__" + field.name, |
|
|
|
|
|
'colspan': '2', 'nolabel': '1'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': field.name, 'colspan': '4', 'nolabel': '1', |
|
|
|
|
|
'attrs': ( |
|
|
|
|
|
"{'invisible':[('selection__" |
|
|
|
|
|
+ field.name + "','=','remove_m2m')]}")}) |
|
|
elif field.ttype == "one2many": |
|
|
elif field.ttype == "one2many": |
|
|
all_fields["selection__" + field.name] = {'type':'selection', |
|
|
|
|
|
'string': field_info[field.name]['string'], |
|
|
|
|
|
'selection':[('set', 'Set'), |
|
|
|
|
|
('remove', 'Remove')]} |
|
|
|
|
|
all_fields[field.name] = {'type':field.ttype, |
|
|
|
|
|
'string': field.field_description, |
|
|
|
|
|
'relation': field.relation} |
|
|
|
|
|
etree.SubElement(xml_group, 'field', |
|
|
|
|
|
{'name': "selection__" + field.name, 'colspan':'2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', |
|
|
|
|
|
{'name': field.name, 'colspan':'4', 'nolabel':'1', |
|
|
|
|
|
'attrs':"{'invisible':[('selection__" + field.name + "','=','remove_o2m')]}"}) |
|
|
|
|
|
|
|
|
all_fields["selection__" + field.name] = { |
|
|
|
|
|
'type': 'selection', |
|
|
|
|
|
'string': field_info[field.name]['string'], |
|
|
|
|
|
'selection': [('set', 'Set'), ('remove', 'Remove')]} |
|
|
|
|
|
all_fields[field.name] = { |
|
|
|
|
|
'type': field.ttype, 'string': field.field_description, |
|
|
|
|
|
'relation': field.relation} |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': "selection__" + field.name, 'colspan': '2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': field.name, 'colspan': '4', 'nolabel': '1', |
|
|
|
|
|
'attrs': ( |
|
|
|
|
|
"{'invisible':[('selection__" |
|
|
|
|
|
+ field.name + "','=','remove_o2m')]}")}) |
|
|
elif field.ttype == "many2one": |
|
|
elif field.ttype == "many2one": |
|
|
all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]} |
|
|
|
|
|
all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'relation': field.relation} |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': "selection__" + field.name, 'colspan':'2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': field.name, 'nolabel':'1', 'colspan':'2', 'attrs':"{'invisible':[('selection__" + field.name + "','=','remove')]}"}) |
|
|
|
|
|
|
|
|
all_fields["selection__" + field.name] = { |
|
|
|
|
|
'type': 'selection', |
|
|
|
|
|
'string': field_info[field.name]['string'], |
|
|
|
|
|
'selection': [('set', 'Set'), ('remove', 'Remove')]} |
|
|
|
|
|
all_fields[field.name] = { |
|
|
|
|
|
'type': field.ttype, 'string': field.field_description, |
|
|
|
|
|
'relation': field.relation} |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': "selection__" + field.name, 'colspan': '2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': field.name, 'nolabel': '1', 'colspan': '2', |
|
|
|
|
|
'attrs': ( |
|
|
|
|
|
"{'invisible':[('selection__" |
|
|
|
|
|
+ field.name + "','=','remove')]}")}) |
|
|
elif field.ttype == "char": |
|
|
elif field.ttype == "char": |
|
|
all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]} |
|
|
|
|
|
all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'size': field.size or 256} |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': "selection__" + field.name, 'colspan':'2', 'colspan':'2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': field.name, 'nolabel':'1', 'attrs':"{'invisible':[('selection__" + field.name + "','=','remove')]}", 'colspan':'2'}) |
|
|
|
|
|
|
|
|
all_fields["selection__" + field.name] = { |
|
|
|
|
|
'type': 'selection', |
|
|
|
|
|
'string': field_info[field.name]['string'], |
|
|
|
|
|
'selection': [('set', 'Set'), ('remove', 'Remove')]} |
|
|
|
|
|
all_fields[field.name] = { |
|
|
|
|
|
'type': field.ttype, 'string': field.field_description, |
|
|
|
|
|
'size': field.size or 256} |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': "selection__" + field.name, |
|
|
|
|
|
'colspan': '2', |
|
|
|
|
|
'colspan': '2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': field.name, 'nolabel': '1', |
|
|
|
|
|
'attrs': ( |
|
|
|
|
|
"{'invisible':[('selection__" |
|
|
|
|
|
+ field.name + "','=','remove')]}"), |
|
|
|
|
|
'colspan': '2'}) |
|
|
elif field.ttype == 'selection': |
|
|
elif field.ttype == 'selection': |
|
|
all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]} |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': "selection__" + field.name, 'colspan':'2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': field.name, 'nolabel':'1', 'colspan':'2', 'attrs':"{'invisible':[('selection__" + field.name + "','=','remove')]}"}) |
|
|
|
|
|
all_fields[field.name] = {'type':field.ttype, 'string': field.field_description, 'selection': field_info[field.name]['selection']} |
|
|
|
|
|
|
|
|
all_fields["selection__" + field.name] = { |
|
|
|
|
|
'type': 'selection', |
|
|
|
|
|
'string': field_info[field.name]['string'], |
|
|
|
|
|
'selection': [('set', 'Set'), ('remove', 'Remove')]} |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': "selection__" + field.name, 'colspan': '2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': field.name, 'nolabel': '1', 'colspan': '2', |
|
|
|
|
|
'attrs': ( |
|
|
|
|
|
"{'invisible':[('selection__" |
|
|
|
|
|
+ field.name + "','=','remove')]}")}) |
|
|
|
|
|
all_fields[field.name] = { |
|
|
|
|
|
'type': field.ttype, |
|
|
|
|
|
'string': field.field_description, |
|
|
|
|
|
'selection': field_info[field.name]['selection']} |
|
|
else: |
|
|
else: |
|
|
all_fields[field.name] = {'type':field.ttype, 'string': field.field_description} |
|
|
|
|
|
all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]} |
|
|
|
|
|
|
|
|
all_fields[field.name] = { |
|
|
|
|
|
'type': field.ttype, 'string': field.field_description} |
|
|
|
|
|
all_fields["selection__" + field.name] = { |
|
|
|
|
|
'type': 'selection', |
|
|
|
|
|
'string': field_info[field.name]['string'], |
|
|
|
|
|
'selection': [('set', 'Set'), ('remove', 'Remove')]} |
|
|
if field.ttype == 'text': |
|
|
if field.ttype == 'text': |
|
|
xml_group = etree.SubElement(xml_group, 'group', {'colspan': '6'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'separator', {'string': all_fields[field.name]['string'], 'colspan': '2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': "selection__" + field.name, 'colspan': '2', 'nolabel':'1'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': field.name, 'colspan':'4', 'nolabel':'1', 'attrs':"{'invisible':[('selection__" + field.name + "','=','remove')]}"}) |
|
|
|
|
|
|
|
|
xml_group = etree.SubElement(xml_group, 'group', { |
|
|
|
|
|
'colspan': '6'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'separator', { |
|
|
|
|
|
'string': all_fields[field.name]['string'], |
|
|
|
|
|
'colspan': '2'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': "selection__" + field.name, |
|
|
|
|
|
'colspan': '2', 'nolabel': '1'}) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': field.name, 'colspan': '4', 'nolabel': '1', |
|
|
|
|
|
'attrs': ( |
|
|
|
|
|
"{'invisible':[('selection__" |
|
|
|
|
|
+ field.name + "','=','remove')]}")}) |
|
|
else: |
|
|
else: |
|
|
all_fields["selection__" + field.name] = {'type':'selection', 'string': field_info[field.name]['string'], 'selection':[('set', 'Set'), ('remove', 'Remove')]} |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': "selection__" + field.name, 'colspan': '2', }) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', {'name': field.name, 'nolabel':'1', 'attrs':"{'invisible':[('selection__" + field.name + "','=','remove')]}", 'colspan': '2', }) |
|
|
|
|
|
etree.SubElement(xml_form, 'separator', {'string' : '', 'colspan': '4'}) |
|
|
|
|
|
|
|
|
all_fields["selection__" + field.name] = { |
|
|
|
|
|
'type': 'selection', |
|
|
|
|
|
'string': field_info[field.name]['string'], |
|
|
|
|
|
'selection': [( |
|
|
|
|
|
'set', 'Set'), ('remove', 'Remove')]} |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': "selection__" + field.name, |
|
|
|
|
|
'colspan': '2', }) |
|
|
|
|
|
etree.SubElement(xml_group, 'field', { |
|
|
|
|
|
'name': field.name, 'nolabel': '1', |
|
|
|
|
|
'attrs': ( |
|
|
|
|
|
"{'invisible':[('selection__" |
|
|
|
|
|
+ field.name + "','=','remove')]}"), |
|
|
|
|
|
'colspan': '2', }) |
|
|
|
|
|
etree.SubElement( |
|
|
|
|
|
xml_form, 'separator', {'string': '', 'colspan': '4'}) |
|
|
xml_group3 = etree.SubElement(xml_form, 'footer', {}) |
|
|
xml_group3 = etree.SubElement(xml_form, 'footer', {}) |
|
|
etree.SubElement(xml_group3, 'button', {'string' :'Close', 'icon': "gtk-close", 'special' :'cancel'}) |
|
|
|
|
|
etree.SubElement(xml_group3, 'button', {'string' :'Apply', 'icon': "gtk-execute", 'type' :'object', 'name':"action_apply"}) |
|
|
|
|
|
|
|
|
etree.SubElement(xml_group3, 'button', { |
|
|
|
|
|
'string': 'Close', 'icon': "gtk-close", 'special': 'cancel'}) |
|
|
|
|
|
etree.SubElement(xml_group3, 'button', { |
|
|
|
|
|
'string': 'Apply', 'icon': "gtk-execute", |
|
|
|
|
|
'type': 'object', 'name': "action_apply"}) |
|
|
root = xml_form.getroottree() |
|
|
root = xml_form.getroottree() |
|
|
result['arch'] = etree.tostring(root) |
|
|
result['arch'] = etree.tostring(root) |
|
|
result['fields'] = all_fields |
|
|
result['fields'] = all_fields |
|
@ -102,7 +188,7 @@ class mass_editing_wizard(orm.TransientModel): |
|
|
if context.get('active_model') and context.get('active_ids'): |
|
|
if context.get('active_model') and context.get('active_ids'): |
|
|
model_obj = self.pool.get(context.get('active_model')) |
|
|
model_obj = self.pool.get(context.get('active_model')) |
|
|
dict = {} |
|
|
dict = {} |
|
|
for key , val in vals.items(): |
|
|
|
|
|
|
|
|
for key, val in vals.items(): |
|
|
if key.startswith('selection__'): |
|
|
if key.startswith('selection__'): |
|
|
split_key = key.split('__', 1)[1] |
|
|
split_key = key.split('__', 1)[1] |
|
|
if val == 'set': |
|
|
if val == 'set': |
|
@ -110,19 +196,22 @@ class mass_editing_wizard(orm.TransientModel): |
|
|
elif val == 'remove': |
|
|
elif val == 'remove': |
|
|
dict.update({split_key: False}) |
|
|
dict.update({split_key: False}) |
|
|
elif val == 'remove_m2m': |
|
|
elif val == 'remove_m2m': |
|
|
dict.update({split_key: [(3, id) for id in vals.get(split_key, False)[0][2]]}) |
|
|
|
|
|
|
|
|
dict.update({split_key: [ |
|
|
|
|
|
(3, id) for id in vals.get( |
|
|
|
|
|
split_key, False)[0][2]]}) |
|
|
elif val == 'add': |
|
|
elif val == 'add': |
|
|
m2m_list = [] |
|
|
m2m_list = [] |
|
|
for m2m_id in vals.get(split_key, False)[0][2]: |
|
|
for m2m_id in vals.get(split_key, False)[0][2]: |
|
|
m2m_list.append((4, m2m_id)) |
|
|
m2m_list.append((4, m2m_id)) |
|
|
dict.update({split_key: m2m_list}) |
|
|
dict.update({split_key: m2m_list}) |
|
|
if dict: |
|
|
if dict: |
|
|
model_obj.write(cr, uid, context.get('active_ids'), dict, context) |
|
|
|
|
|
|
|
|
model_obj.write( |
|
|
|
|
|
cr, uid, context.get('active_ids'), dict, context) |
|
|
result = super(mass_editing_wizard, self).create(cr, uid, {}, context) |
|
|
result = super(mass_editing_wizard, self).create(cr, uid, {}, context) |
|
|
return result |
|
|
return result |
|
|
|
|
|
|
|
|
def action_apply(self, cr, uid, ids, context=None): |
|
|
def action_apply(self, cr, uid, ids, context=None): |
|
|
return {'type': 'ir.actions.act_window_close'} |
|
|
|
|
|
|
|
|
return {'type': 'ir.actions.act_window_close'} |
|
|
|
|
|
|
|
|
mass_editing_wizard() |
|
|
mass_editing_wizard() |
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |