1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# 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
32
class many2manysym(fields.many2many):
34
def get(self, cr, obj, ids, name, user=None, offset=0, context={}, values={}):
38
ids_s = ','.join(map(str,ids))
41
limit_str = self._limit is not None and ' limit %d' % self._limit or ''
43
for (self._id2, self._id1) in [(self._id2, self._id1), (self._id1, self._id2)]:
44
cr.execute('select '+self._id2+','+self._id1+' from '+self._rel+' where '+self._id1+' in ('+ids_s+')'+limit_str+' offset %d', (offset,))
45
for r in cr.fetchall():
46
res[r[1]].append(r[0])
50
class product_template(osv.osv):
51
_inherit = "product.template"
53
'name': fields.char('Name', size=256, required=True, select=True),
57
# Book variant of product
58
class product_product(osv.osv):
59
_name = "product.product"
60
_inherit = "product.product"
63
def name_get(self, cr, user, ids, context={}):
67
#name = self._product_partner_ref(cr, user, [d['id']], '', '', context)[d['id']]
68
#code = self._product_code(cr, user, [d['id']], '', '', context)[d['id']]
69
name = d.get('name','')
70
ean = d.get('ean13',False)
72
name = '[%s] %s' % (ean,name)
73
return (d['id'], name)
74
result = map(_name_get, self.read(cr, user, ids, ['name','ean13'], context))
77
def name_search(self, cr, user, name, args=[], operator='ilike', context={}, limit=80):
78
ids = self.search(cr, user, [('default_code','=',name)]+ args, limit=limit)
80
ids = self.search(cr, user, [('ean13','=',name)]+ args, limit=limit)
82
ids = self.search(cr, user, [('default_code',operator,name)]+ args, limit=limit)
83
ids += self.search(cr, user, [('name',operator,name)]+ args, limit=limit)
84
result = self.name_get(cr, user, ids, context)
87
def _tax_incl(self, cr, uid, ids, field_name, arg, context):
89
for product in self.browse(cr, uid, ids):
91
for c in self.pool.get('account.tax').compute(cr, uid, product.taxes_id, product.list_price, 1, False):
92
val += round(c['amount'], 2)
93
res[product.id]=round(val + product.list_price,2)
97
def _get_partner_code_name(self, cr, uid, ids, product_id, partner_id, context={}):
98
product = self.browse(cr, uid, [product_id], context)[0]
99
for supinfo in product.seller_ids:
100
if supinfo.name.id == partner_id:
101
return {'code': supinfo.product_code, 'name': supinfo.product_name}
102
return {'code' : product.default_code, 'name' : product.name}
104
def _product_code(self, cr, uid, ids, name, arg, context={}):
106
for p in self.browse(cr, uid, ids, context):
107
res[p.id] = self._get_partner_code_name(cr, uid, [], p.id, context.get('partner_id', None), context)['code']
112
'isbn': fields.char('Isbn code', size=64, unique=True),
113
'catalog_num': fields.char('Catalog number', size=64),
114
#'number': fields.char('Number', size=64, readonly=True), # ancien numero interne
115
'author_om_ids': fields.one2many('author.book.rel','product_id','Authors'),
116
'lang': fields.many2many('res.lang','lang_book_rel','product_id','lang_id', 'Language'),
117
'editor': fields.many2one('res.partner','Editor', change_default=True),
118
'code': fields.function(_product_code, method=True, type='char', string='Acronym'),
119
'catalog_num': fields.char('Catalog number', size=64),
120
'date_parution': fields.date('Release date'),
121
'creation_date': fields.datetime('Creation date', readonly=True),
122
'date_retour': fields.date('Return date'),
123
'tome' : fields.char('Tome', size=8),
124
'nbpage': fields.integer('Number of pages', size=8),
125
'rack': fields.many2one('library.rack','Rack', size=16),
126
'online': fields.boolean('Visible on website'),
127
'state': fields.selection([('draft', 'Not yet published'),('sellable','Available'),('end','Sold Out'),('obsolete','Printing w/o Date')], 'State'),
128
'link_ids': many2manysym('product.product','book_book_rel','product_id1','product_id2','Related Books'),
129
'back':fields.selection([('hard', 'Hardback'),('paper','Paperback')], 'Reliure'),
130
'collection': fields.many2one('library.collection','Collection'),
131
'pocket':fields.char('Pocket', size=32),
132
'num_pocket':fields.char('Collection Num.', size=32),
133
'num_edition':fields.integer('Num. edition'),
134
'format':fields.char('Format', size=128),
135
'price_cat': fields.many2one('library.price.category', "Price category"),
136
# 'categ_id': fields.many2one('product.category','Category', required=True, change_default=False),
140
'creation_date': lambda *a : time.strftime('%Y-%m-%d %H:%M:%S'),
141
'state': lambda *a : 'sellable',
142
'back': lambda *a : 'paper',
143
'procure_method': lambda *a: 'make_to_order',
144
'date_retour': lambda *a : str(int(time.strftime("%Y"))+1) + time.strftime("-%m-%d"),
148
('unique_ean13', 'unique(ean13)', 'The ean13 field must be unique across all the products'),
149
('code_uniq', 'unique (code)', 'The code of the product must be unique !')
153
class author_book_rel(osv.osv):
154
_name = "author.book.rel"
155
_rec_name = "author_id"
157
'author_id': fields.many2one('library.author','Author', ondelete='cascade'),
158
'product_id': fields.many2one('product.product','Book', ondelete='cascade')
163
class product_product_in(osv.osv):
164
_inherit = "product.product"
166
'author_ids': fields.many2many('library.author','author_book_rel','product_id','author_id','Authors'),
168
def copy(self, cr, uid, id, default=None,context={}):
171
default.update({ 'author_ids':[] })
172
return super(product_product_in, self).copy(cr, uid, id, default, context)
178
class library_author(osv.osv):
179
_inherit = 'library.author'
181
'book_ids': fields.many2many('product.product','author_book_rel','author_id','product_id','Books', select=1),
186
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: