~unifield-team/unifield-wm/us-671-homere

« back to all changes in this revision

Viewing changes to sourcing/product_supplierinfo.py

UF-359 [ADD] Account override module integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (C) 2014 TeMPO Consulting, MSF
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 osv import fields
23
 
from osv import osv
24
 
 
25
 
from tools.translate import _
26
 
 
27
 
 
28
 
class product_supplierinfo(osv.osv):
29
 
    """
30
 
    override name_get to display name of the related supplier
31
 
 
32
 
    override create to be able to create a new supplierinfo from sourcing view
33
 
    """
34
 
    _name = 'product.supplierinfo'
35
 
    _inherit = 'product.supplierinfo'
36
 
 
37
 
    def _get_false(self, cr, uid, ids, field_name, arg, context=None):
38
 
        '''
39
 
        return false for each id
40
 
        '''
41
 
        if isinstance(ids, (long, int)):
42
 
            ids = [ids]
43
 
 
44
 
        result = {}
45
 
        for l_id in ids:
46
 
            result[l_id] = []
47
 
        return result
48
 
 
49
 
    def _get_product_ids(self, cr, uid, obj, name, args, context=None):
50
 
        '''
51
 
        from the product.template id returns the corresponding product.product
52
 
        '''
53
 
        if not args:
54
 
            return []
55
 
        if args[0][1] != '=':
56
 
            raise osv.except_osv(
57
 
                _('Error !'),
58
 
                _('Filter not implemented'),
59
 
            )
60
 
        # product id of sourcing line
61
 
        productId = args[0][2]
62
 
        # gather product template id for that product
63
 
        templateId = self.pool.get('product.product').browse(cr, uid, productId, context=context).product_tmpl_id.id
64
 
        # search filter on product_id of supplierinfo
65
 
        return [('product_id', '=', templateId)]
66
 
 
67
 
    _columns = {
68
 
        'product_product_ids': fields.function(
69
 
            _get_false,
70
 
            fnct_search=_get_product_ids,
71
 
            method=True,
72
 
            type='one2many',
73
 
            relation='product.product',
74
 
            string="Products",
75
 
        ),
76
 
    }
77
 
 
78
 
    def name_get(self, cr, uid, ids, context=None):
79
 
        '''
80
 
        product_supplierinfo
81
 
        display the name of the product instead of the id of supplierinfo
82
 
        '''
83
 
        if not ids:
84
 
            return []
85
 
 
86
 
        result = []
87
 
        for supinfo in self.browse(cr, uid, ids, context=context):
88
 
            supplier = supinfo.name
89
 
            result.append((supinfo.id, supplier.name_get(context=context)[0][1]))
90
 
 
91
 
        return result
92
 
 
93
 
    def create(self, cr, uid, values, context=None):
94
 
        '''
95
 
        product_supplierinfo
96
 
        inject product_id in newly created supplierinfo
97
 
        '''
98
 
        if not values:
99
 
            values = {}
100
 
        if context and 'sourcing-product_id' in context:
101
 
            productId = context['sourcing-product_id']
102
 
            product = self.pool.get('product.product').browse(cr, uid, productId, context=context)
103
 
            values.update({'product_id': product.product_tmpl_id.id})
104
 
 
105
 
        return super(product_supplierinfo, self).create(cr, uid, values, context)
106
 
 
107
 
product_supplierinfo()
108
 
 
109
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: