~akretion-team/openerp-connector-ecommerce/openerp-connector-ecommerce-add-fiscal-position-support

« back to all changes in this revision

Viewing changes to product_links/product_links.py

  • Committer: Guewen Baconnier
  • Date: 2014-01-14 09:26:01 UTC
  • Revision ID: guewen.baconnier@camptocamp.com-20140114092601-66t1v1o45931k3t2
[DEL] remove e-commerce-addons modules, just keep connector_ecommerce

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    Author: Guewen Baconnier
5
 
#    Copyright 2011-2013 Camptocamp SA
6
 
#
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.
11
 
#
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.
16
 
#
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/>.
19
 
#
20
 
##############################################################################
21
 
 
22
 
from openerp.osv import orm, fields
23
 
 
24
 
 
25
 
class product_link(orm.Model):
26
 
    _name = 'product.link'
27
 
    _rec_name = 'linked_product_id'
28
 
 
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')]
34
 
 
35
 
    def _get_link_type_selection(self, cr, uid, context=None):
36
 
        return self.get_link_type_selection(cr, uid, context=context)
37
 
 
38
 
    _columns = {
39
 
        'product_id': fields.many2one(
40
 
            'product.product',
41
 
            'Source product',
42
 
            required=True,
43
 
            ondelete='cascade'),
44
 
        'linked_product_id': fields.many2one(
45
 
            'product.product',
46
 
            'Linked product',
47
 
            required=True,
48
 
            ondelete='cascade'),
49
 
        'type': fields.selection(
50
 
            _get_link_type_selection,
51
 
            string='Link type',
52
 
            required=True),
53
 
        'is_active': fields.boolean('Active'),
54
 
    }
55
 
 
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):
60
 
        if context is None:
61
 
            context = {}
62
 
        return context.get('product_id', False)
63
 
 
64
 
    _defaults = {
65
 
        'is_active': True,
66
 
        'product_id': _get_default_product_id,
67
 
    }
68
 
 
69
 
 
70
 
class product(orm.Model):
71
 
    _inherit = 'product.product'
72
 
 
73
 
    _columns = {
74
 
        'product_link_ids': fields.one2many(
75
 
            'product.link',
76
 
            'product_id',
77
 
            string='Product links'),
78
 
        }