~openbias/bias-trunk/bias-public-trunk

« back to all changes in this revision

Viewing changes to bias_product_related_cost/partner.py

  • Committer: Jose Patricio
  • Date: 2011-10-19 03:16:40 UTC
  • Revision ID: josepato@bias.com.mx-20111019031640-05zd7r5lxwx084qu
el push inicial

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) 2004-2010 Tiny SPRL (<http://tiny.be>).
 
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 osv
 
23
from osv import fields
 
24
import urllib,re
 
25
import random, time
 
26
from tools.translate import _
 
27
 
 
28
class res_partner(osv.osv):
 
29
    _inherit = "res.partner"
 
30
    _columns = {
 
31
        'related_cost_ids': fields.one2many('res.partner.related.cost.line', 'product_id', 'Related Cost'),
 
32
    }
 
33
 
 
34
res_partner()
 
35
 
 
36
class res_partner_category(osv.osv):
 
37
    _inherit = 'res.partner.category'
 
38
    _columns = {
 
39
        'related_cost_ids': fields.one2many('res.partner.related.cost.line', 'product_id', 'Related Cost'),
 
40
    }
 
41
 
 
42
res_partner_category()
 
43
 
 
44
 
 
45
class res_partner_related_cost(osv.osv):### ADD a name constrain !!!!!!
 
46
    _order = 'name'
 
47
    _name = 'res.partner.related.cost'
 
48
 
 
49
    def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100):
 
50
        if not args:
 
51
            args = []
 
52
        args = args[:]
 
53
        ids = []
 
54
        if name:
 
55
            ids = self.search(cr, user, [('code', '=ilike', name+"%")]+args, limit=limit)
 
56
            if not ids:
 
57
                ids = self.search(cr, user, [('name', operator, name)]+ args, limit=limit)
 
58
            if not ids and len(name.split()) >= 2:
 
59
                #Separating code and name of account for searching
 
60
                operand1,operand2 = name.split(' ',1) #name can contain spaces e.g. OpenERP S.A.
 
61
                ids = self.search(cr, user, [('code', operator, operand1), ('name', operator, operand2)]+ args, limit=limit)
 
62
        else:
 
63
            ids = self.search(cr, user, args, context=context, limit=limit)
 
64
        return self.name_get(cr, user, ids, context=context)
 
65
 
 
66
    def name_get(self, cr, uid, ids, context=None):
 
67
        if not ids:
 
68
            return []
 
69
        reads = self.read(cr, uid, ids, ['name', 'code'], context=context)
 
70
        res = []
 
71
        for record in reads:
 
72
            name = record['name']
 
73
            if record['code']:
 
74
                name = record['code'] + ' '+name
 
75
            res.append((record['id'], name))
 
76
        return res
 
77
 
 
78
    _columns = {
 
79
        'factor': fields.float('Factor', digits=(14,4)),
 
80
        'extra_cost': fields.float('Extra Cost Price', digits=(14,4), help="Fixed cost added by product each time it is recived in the stock location."),
 
81
        'active': fields.boolean('Active'),
 
82
        'name': fields.char('Name', required=True, size=32),
 
83
        'code': fields.char('Code', required=True, size=16),
 
84
    }
 
85
    _defaults = {
 
86
        'active': lambda *args: 1
 
87
    }
 
88
 
 
89
res_partner_related_cost()
 
90
 
 
91
class res_partner_related_cost_line(osv.osv):
 
92
    _name = 'res.partner.related.cost.line'
 
93
 
 
94
    def _get_factor(self, cr, uid, ids, fields, arg, context=None):
 
95
        result = {}
 
96
        for product in self.browse(cr, uid, ids, context=context):
 
97
                result[product.id] = product.relaed_cost_id.factor or False
 
98
        return result
 
99
 
 
100
    def _get_extra(self, cr, uid, ids, fields, arg, context=None):
 
101
        result = {}
 
102
        for product in self.browse(cr, uid, ids, context=context):
 
103
                result[product.id] = product.relaed_cost_id.extra_cost or False
 
104
        return result
 
105
 
 
106
    _columns = {
 
107
        'factor': fields.function(_get_factor, method=True, type='float', digits=(14,4),  string='Factor'),
 
108
        'extra_cost': fields.function(_get_extra, method=True, type='float', digits=(14,4),  string='Extra Cost Price', help="Fixed cost added by product each time it is recived in the stock location."),
 
109
        'active': fields.boolean('Active'),
 
110
        'product_id': fields.many2one('res.partner', 'Product', required=True, select=True),
 
111
        'relaed_cost_id': fields.many2one('res.partner.related.cost', 'Related Cost', required=True, select=True),
 
112
    }
 
113
    _defaults = {
 
114
        'active': lambda *args: 1
 
115
    }
 
116
res_partner_related_cost_line()
 
117
 
 
118
 
 
119
 
 
120