2
# -*- encoding: utf-8 -*-
3
###########################################################################
4
# Module Writen to OpenERP, Open Source Management Solution
5
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
7
###############Credits######################################################
8
# Coded by: Humberto Arocha <hbto@vauxoo.com>
9
# Audited by: Nhomar Hernandez <nhomar@vauxoo.com>
10
#############################################################################
11
# This program is free software: you can redistribute it and/or modify
12
# it under the terms of the GNU Affero General Public License as published by
13
# the Free Software Foundation, either version 3 of the License, or
14
# (at your option) any later version.
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
# GNU Affero General Public License for more details.
21
# You should have received a copy of the GNU Affero General Public License
22
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
################################################################################
26
from osv import fields, osv
27
from tools.translate import _
29
class Partner(osv.osv):
30
_inherit = 'res.partner'
32
def _fnct_search_date(self, cr, uid, obj, name, args, context=None):
35
context = context or {}
37
ids = self.search(cr,uid,[],context=context)
39
return [('id', '=', 0)]
40
model = name=='sale_order_date' and 'sale_order' or 'account_invoice'
41
fieldname = name=='sale_order_date' and 'date_order' or 'date_invoice'
43
SELECT partner_id as id, '''+fieldname+'''
45
SELECT t2.partner_id, t2.'''+fieldname+'''
47
WHERE (t2.partner_id,t2.'''+fieldname+''') IN (
48
SELECT t1.partner_id,t1.'''+fieldname+'''
50
WHERE t1.partner_id = t2.partner_id
51
ORDER BY t1.'''+fieldname+'''
54
WHERE partner_id IN %s
55
AND '''+fieldname+'''%s\'%s\';'''
58
if arg[1] in ('=','>=','<=','>','<') and arg[2]:
59
cr.execute(query%(str(tuple(ids)),arg[1],arg[2]))
60
res += [i[0] for i in cr.fetchall()]
62
return [('id', '=', 0)]
63
return [('id', 'in', res)]
65
def _fnct_get_date(self, cr, uid, ids, fieldname, arg, context=None):
66
context = context or {}
67
res = {}.fromkeys(ids,None)
68
so_obj = self.pool.get('sale.order')
69
inv_obj = self.pool.get('account.invoice')
71
s_id = so_obj.search(cr, uid,
72
[('partner_id','=',id)],order='date_order asc',limit=1) or []
73
i_id = inv_obj.search(cr, uid,
74
#TODO: in the future set args for state in ['open','paid']
75
[('partner_id','=',id),('type','=','out_invoice')],
76
order='date_invoice asc',limit=1) or []
78
'sale_order_date' : s_id and \
79
so_obj.browse(cr,uid,s_id[0],context=context).date_order \
81
'invoice_date': i_id and \
82
inv_obj.browse(cr,uid,i_id[0],context=context).date_invoice \
87
'sale_order_date':fields.function(
91
string = 'First Sale Order',
93
fnct_search=_fnct_search_date,
95
'invoice_date':fields.function(
99
string = 'First Sale Invoice',
100
multi='sale_invoice',
101
fnct_search=_fnct_search_date,