1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# Author: Guewen Baconnier
5
# Copyright 2011-2013 Camptocamp SA
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (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 Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
22
from openerp.osv import orm, fields
25
class product_link(orm.Model):
26
_name = 'product.link'
27
_rec_name = 'linked_product_id'
29
def get_link_type_selection(self, cr, uid, context=None):
30
# selection can be inherited and extended
31
return [('cross_sell', 'Cross-Sell'),
32
('up_sell', 'Up-Sell'),
33
('related', 'Related')]
35
def _get_link_type_selection(self, cr, uid, context=None):
36
return self.get_link_type_selection(cr, uid, context=context)
39
'product_id': fields.many2one(
44
'linked_product_id': fields.many2one(
49
'type': fields.selection(
50
_get_link_type_selection,
53
'is_active': fields.boolean('Active'),
56
# It seems that it's not possible to set the default value of a field in
57
# a one2many via the context (it works well with a many2one though)
58
# So I have to set explicitly a default value
59
def _get_default_product_id(self, cr, uid, context=None):
62
return context.get('product_id', False)
66
'product_id': _get_default_product_id,
70
class product(orm.Model):
71
_inherit = 'product.product'
74
'product_link_ids': fields.one2many(
77
string='Product links'),