1
##############################################################################
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
6
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsability of assessing all potential
8
# consequences resulting from its eventual inadequacies and bugs
9
# End users who are looking for a ready-to-use solution with commercial
10
# garantees and support are strongly adviced to contract a Free Software
13
# This program is Free Software; you can redistribute it and/or
14
# modify it under the terms of the GNU General Public License
15
# as published by the Free Software Foundation; either version 2
16
# of the License, or (at your option) any later version.
18
# This program is distributed in the hope that it will be useful,
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
# GNU General Public License for more details.
23
# You should have received a copy of the GNU General Public License
24
# along with this program; if not, write to the Free Software
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27
##############################################################################
29
from osv import osv, fields
31
# class library_editor_supplier(osv.osv):
32
# _name = "library.editor.supplier"
33
# _description = "Suppliers associated to an editor"
36
# 'name': fields.many2one('res.partner', 'Editor', readonly= True),
37
# 'supplier_ids' : fields.many2many('res.partner','editor_supplier_rel','editor_id','supplier_id', 'Suppliers',readonly= True),
41
# create or replace view library_editor_supplier as (
42
# select editor as id, editor as name from product_product group by editor
45
# library_editor_supplier()
47
class library_editor_supplier(osv.osv):
48
_name = "library.editor.supplier"
49
_description = "many2many view for editor relations"
52
'name': fields.many2one('res.partner', 'Editor'),
53
'supplier_id' : fields.many2one('res.partner', 'Supplier'),
59
create or replace view library_editor_supplier as (
61
case when min(ps.id) is null then - min(pp.id) else min(ps.id) end as id,
62
case when pp.editor is null then 0 else pp.editor end as name,
63
case when ps.name is null then 0 else ps.name end as supplier_id
65
product_supplierinfo ps full outer join product_product pp on (ps.product_id = pp.product_tmpl_id)
67
((pp.editor is not null) or (ps.name is not null))
68
group by pp.editor, ps.name
72
def create(self, cr, user, vals, context={}):
73
if not (vals['name'] and vals['supplier_id']) : raise osv.except_osv("Error","Please provide ..")
74
# search for books of these editor not already linked with this supplier :
75
select = 'select product_tmpl_id from product_product where editor = %s and id not in (select product_id from product_supplierinfo where name = %s)'%(vals['name'],vals['supplier_id'])
78
raise osv.except_osv("Error","No book to apply this relation")
80
sup_info = self.pool.get('product.supplierinfo')
82
for book_id in cr.fetchall():
83
tmp_id = sup_info.create(cr,user,{'name': vals['supplier_id'], 'product_id': book_id[0]},context)
84
last_id = last_id < tmp_id and last_id or tmp_id
88
def unlink(self, cr, uid, ids, context={}):
90
relations = self.browse(cr,uid,ids)
92
if not (rel.name and rel.supplier_id) : continue
93
# search for the equivalent ids in product_supplierinfo (unpack the group)
94
cr.execute("select si.id from product_supplierinfo si join product_product pp on (si.product_id = pp.product_tmpl_id ) where pp.editor = %s and si.name = %s" %(rel.name.id,rel.supplier_id.id) )
95
ids = [x[0] for x in cr.fetchall()]
96
self.pool.get('product.supplierinfo').unlink(cr,uid,ids,context)
99
# cr.execute('select name, supplier_id from library_editor_supplier where id in ('+','.join(map(str,ids))+')' )
102
def write(self, cr, user, ids, vals, context={}):
103
raise osv.except_osv("Warning","Only creation and suppression are allowed in this form.")
105
library_editor_supplier()