1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 ASPerience SARL (<http://www.asperience.fr>). All Rights Reserved
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from osv import fields, osv
24
from tools import config
26
import decimal_precision as dp
29
class wizard_fusion(osv.osv_memory):
30
_name = "wizard.fusion"
31
_description = "wizard.fusion"
34
'name': fields.char('Name', size=64),
35
'partner_ids': fields.many2many('res.partner', "wizard_fusion_partner_rel", "wiz_id", "part_id"),
36
'partner_id': fields.many2one('res.partner','Partner Destination'),
37
'product_ids': fields.many2many('product.product', "wizard_fusion_product_rel", "wiz_id", "prod_id"),
38
'product_id': fields.many2one('product.product','Product Destination'),
39
'diff': fields.text('diff'),
42
def _get_partner_ids(self, cr, uid, context=None):
43
if context['active_model'] == 'res.partner':
44
return context['active_ids']
47
def _get_product_ids(self, cr, uid, context=None):
48
if context['active_model'] == 'product.product':
49
return context['active_ids']
52
def _get_name(self, cr, uid, context=None):
53
return context['active_model']
55
def _get_diff(self, cr, uid, context=None):
56
if len(context['active_ids']) >= 1:
57
obj = self.pool.get(context['active_model'])
58
read_objs = obj.read(cr,uid,context['active_ids'])
60
for key in sorted(read_objs[0].keys()):
62
value=read_objs[0][key]
63
for read_obj in read_objs[1:]:
64
if read_obj[key] != value:
67
diff += key.ljust(50)+" --> "+tools.ustr(value).ljust(50)
68
for read_obj in read_objs[1:]:
69
diff +="| "+tools.ustr(read_obj[key]).ljust(50)+"\n"
75
'partner_ids': _get_partner_ids,
76
'product_ids': _get_product_ids,
80
def fusion(self, cr, uid, ids, context=None):
81
for wizard in self.browse(cr,uid,ids,context):
83
obj_table = wizard.name.replace('.','_')
86
if wizard.name == "res.partner":
87
obj_ids = wizard.partner_ids
88
obj_id = wizard.partner_id
90
sql = " select b.relname as table,c.relname,d.attname as column \
91
from pg_constraint a \
92
join pg_class b on a.conrelid=b.oid \
93
join pg_class c on a.confrelid=c.oid \
94
join pg_attribute d on d.attnum = any(a.conkey) and b.oid=d.attrelid \
95
where c.relname = '"+obj_table+"'"
98
res = cr.dictfetchall()
100
if obj.id != obj_id.id:
102
if table['table'][-4:] == '_rel':
103
sql = "select b.relname as table,c.relname,d.attname as column \
104
from pg_constraint a \
105
join pg_class b on a.conrelid=b.oid \
106
join pg_class c on a.confrelid=c.oid \
107
join pg_attribute d on d.attnum = any(a.conkey) and b.oid=d.attrelid \
108
where b.relname = '%s'" % table['table']
110
res2 = cr.dictfetchall()
112
field1 = res2[0]['column']
113
field2 = res2[1]['column']
114
sql = """delete from %s where oid in (
117
where exists( select 1
119
where a.oid != b.oid and
123
)""" % (table['table'],table['table'],table['table'],field1,field1,field2,field2)
125
sql = """DELETE FROM %s WHERE %s = %s """%(table['table'], table['column'], obj.id)
126
if cr.execute(sql) != None:
127
log += "Erreur sur : "+str(sql)+","
129
sql = """UPDATE %s SET %s = %s WHERE %s = %s """%(table['table'], table['column'], obj_id.id,table['column'], obj.id)
130
if cr.execute(sql) != None:
131
log += "Erreur sur : "+str(sql)+","
133
obj.write({'active':False})
134
elif wizard.name == "product.product":
135
obj_ids = wizard.product_ids
136
obj_id = wizard.product_id
137
tmpl_id = wizard.product_id.product_tmpl_id
139
sql = " select b.relname as table,c.relname,d.attname as column \
140
from pg_constraint a \
141
join pg_class b on a.conrelid=b.oid \
142
join pg_class c on a.confrelid=c.oid \
143
join pg_attribute d on d.attnum = any(a.conkey) and b.oid=d.attrelid \
144
where c.relname = '"+"product_template"+"'"
147
res = cr.dictfetchall()
149
if obj.id != obj_id.id:
151
if table['table'] == 'product_product' and table['column'] == 'product_tmpl_id':
154
if table['table'][-4:] == '_rel':
155
sql = "select b.relname as table,c.relname,d.attname as column \
156
from pg_constraint a \
157
join pg_class b on a.conrelid=b.oid \
158
join pg_class c on a.confrelid=c.oid \
159
join pg_attribute d on d.attnum = any(a.conkey) and b.oid=d.attrelid \
160
where b.relname = '%s'" % table['table']
162
res2 = cr.dictfetchall()
164
field1 = res2[0]['column']
165
field2 = res2[1]['column']
166
sql = """delete from %s where oid in (
169
where exists( select 1
171
where a.oid != b.oid and
175
)""" % (table['table'],table['table'],table['table'],field1,field1,field2,field2)
177
sql = """DELETE FROM %s WHERE %s = %s """%(table['table'], table['column'], obj.id)
178
if cr.execute(sql) != None:
179
log += "Erreur sur : "+str(sql)+","
181
sql = """UPDATE %s SET %s = %s WHERE %s = %s """%(table['table'], table['column'], tmpl_id.id,table['column'], obj.product_tmpl_id.id)
182
if cr.execute(sql) != None:
183
log += "Erreur sur : "+str(sql)+","
186
sql = " select b.relname as table,c.relname,d.attname as column \
187
from pg_constraint a \
188
join pg_class b on a.conrelid=b.oid \
189
join pg_class c on a.confrelid=c.oid \
190
join pg_attribute d on d.attnum = any(a.conkey) and b.oid=d.attrelid \
191
where c.relname = '"+obj_table+"'"
194
res = cr.dictfetchall()
196
if obj.id != obj_id.id:
198
if table['table'][-4:] == '_rel':
199
sql = "select b.relname as table,c.relname,d.attname as column \
200
from pg_constraint a \
201
join pg_class b on a.conrelid=b.oid \
202
join pg_class c on a.confrelid=c.oid \
203
join pg_attribute d on d.attnum = any(a.conkey) and b.oid=d.attrelid \
204
where b.relname = '%s'" % table['table']
206
res2 = cr.dictfetchall()
208
field1 = res2[0]['column']
209
field2 = res2[1]['column']
210
sql = """delete from %s where oid in (
213
where exists( select 1
215
where a.oid != b.oid and
219
)""" % (table['table'],table['table'],table['table'],field1,field1,field2,field2)
221
sql = """DELETE FROM %s WHERE %s = %s """%(table['table'], table['column'], obj.id)
222
if cr.execute(sql) != None:
223
log += "Erreur sur : "+str(sql)+","
225
sql = """UPDATE %s SET %s = %s WHERE %s = %s """%(table['table'], table['column'], obj_id.id,table['column'], obj.id)
226
if cr.execute(sql) != None:
227
log += "Erreur sur : "+str(sql)+","
229
obj.write({'active':False})
230
self.log(cr,uid,wizard.id,log)
232
return {'type': 'ir.actions.act_window_close'}
235
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
b'\\ No newline at end of file'