1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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
##############################################################################
23
from osv import fields
26
from tools.translate import _
28
class res_partner(osv.osv):
29
_inherit = "res.partner"
31
'related_cost_ids': fields.one2many('res.partner.related.cost.line', 'product_id', 'Related Cost'),
36
class res_partner_category(osv.osv):
37
_inherit = 'res.partner.category'
39
'related_cost_ids': fields.one2many('res.partner.related.cost.line', 'product_id', 'Related Cost'),
42
res_partner_category()
45
class res_partner_related_cost(osv.osv):### ADD a name constrain !!!!!!
47
_name = 'res.partner.related.cost'
49
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100):
55
ids = self.search(cr, user, [('code', '=ilike', name+"%")]+args, limit=limit)
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)
63
ids = self.search(cr, user, args, context=context, limit=limit)
64
return self.name_get(cr, user, ids, context=context)
66
def name_get(self, cr, uid, ids, context=None):
69
reads = self.read(cr, uid, ids, ['name', 'code'], context=context)
74
name = record['code'] + ' '+name
75
res.append((record['id'], name))
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),
86
'active': lambda *args: 1
89
res_partner_related_cost()
91
class res_partner_related_cost_line(osv.osv):
92
_name = 'res.partner.related.cost.line'
94
def _get_factor(self, cr, uid, ids, fields, arg, context=None):
96
for product in self.browse(cr, uid, ids, context=context):
97
result[product.id] = product.relaed_cost_id.factor or False
100
def _get_extra(self, cr, uid, ids, fields, arg, context=None):
102
for product in self.browse(cr, uid, ids, context=context):
103
result[product.id] = product.relaed_cost_id.extra_cost or False
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),
114
'active': lambda *args: 1
116
res_partner_related_cost_line()