1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 Cubic ERP - Teradata SAC (<http://cubicerp.com>).
6
# (Modified by) Vauxoo - http://www.vauxoo.com/
7
# info Vauxoo (info@vauxoo.com)
8
# Modified by - juan@vauxoo.com
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU Affero General Public License as
11
# published by the Free Software Foundation, either version 3 of the
12
# License, or (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU Affero General Public License for more details.
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
24
from openerp.osv import osv, fields
27
class product_customs_rate(osv.Model):
29
def name_get(self, cr, uid, ids, context=None):
32
reads = self.read(cr, uid, ids, ['name', 'code'], context=context)
37
name = record['code']+': '+name
38
res.append((record['id'], name))
41
def name_search(self, cr, user, name, args=None, operator='ilike',
42
context=None, limit=100):
48
ids = self.search(cr, user, [(
49
'code', '=like', name+"%")]+args, limit=limit)
51
ids = self.search(cr, user, [(
52
'name', operator, name)] + args, limit=limit)
53
if not ids and len(name.split()) >= 2:
54
# Separating code and name of account for searching
55
operand1, operand2 = name.split(
56
': ', 1) # name can contain spaces e.g. OpenERP S.A.
57
ids = self.search(cr, user, [('code', operator, operand1), (
58
'name', operator, operand2)] + args, limit=limit)
60
ids = self.search(cr, user, args, context=context, limit=limit)
61
return self.name_get(cr, user, ids, context=context)
63
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
64
res = self.name_get(cr, uid, ids, context=context)
67
_name = 'product.customs.rate'
68
_description = 'Customs Rate'
70
'code': fields.char('Code', size=64),
71
'name': fields.char('Name', size=2048, required=True, translate=True,
73
'active': fields.boolean('Active'),
74
'complete_name': fields.function(_name_get_fnc, method=True,
75
type="char", string='Name'),
76
'parent_id': fields.many2one('product.customs.rate',
77
'Parent Customs Rate', select=True,
78
domain=[('type', '=', 'view')]),
79
'child_ids': fields.one2many('product.customs.rate', 'parent_id',
80
string='Child Customs Rate'),
81
'type': fields.selection([('view', 'View'), ('normal', 'Normal')],
82
'Customs Rate Type', required=True),
83
'tax_ids': fields.many2many('account.tax', 'product_customs_rate_tax',
84
'customs_rate_id', 'tax_id', 'Taxes')
93
def _check_recursion(self, cr, uid, ids, context=None):
96
cr.execute('select distinct parent_id\
97
from product_customs_rate where id IN %s', (
99
ids = filter(None, map(lambda x: x[0], cr.fetchall()))
106
(_check_recursion, 'Error !\
107
You can not create recursive Customs Rate.', [
111
def child_get(self, cr, uid, ids):