1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 ##############################################################################
25 # Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
27 # WARNING: This program as such is intended to be used by professional
28 # programmers who take the whole responsability of assessing all potential
29 # consequences resulting from its eventual inadequacies and bugs
30 # End users who are looking for a ready-to-use solution with commercial
31 # garantees and support are strongly adviced to contract a Free Software
34 # This program is Free Software; you can redistribute it and/or
35 # modify it under the terms of the GNU General Public License
36 # as published by the Free Software Foundation; either version 2
37 # of the License, or (at your option) any later version.
39 # This program is distributed in the hope that it will be useful,
40 # but WITHOUT ANY WARRANTY; without even the implied warranty of
41 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 # GNU General Public License for more details.
44 # You should have received a copy of the GNU General Public License
45 # along with this program; if not, write to the Free Software
46 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
48 ##############################################################################
50 from osv import fields,osv
54 class account_analytic_default(osv.osv):
55 _name = 'account.analytic.default'
56 _description = 'Analytic Distributions'
57 _rec_name = 'analytic_id'
60 'sequence': fields.integer('Sequence'),
61 'analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'),
62 'product_id': fields.many2one('product.product', 'Product', ondelete='cascade'),
63 'partner_id': fields.many2one('res.partner', 'Partner', ondelete='cascade'),
64 'user_id': fields.many2one('res.users', 'User', ondelete='cascade'),
65 'company_id': fields.many2one('res.company', 'Company', ondelete='cascade'),
66 'date_start': fields.date('Start Date'),
67 'date_stop': fields.date('End Date'),
69 def account_get(self, cr, uid, product_id=None, partner_id=None, user_id=None, date=None, context={}):
72 domain += ['|',('product_id','=',product_id)]
73 domain += [('product_id','=',False)]
75 domain += ['|',('partner_id','=',partner_id)]
76 domain += [('partner_id','=',False)]
78 domain += ['|',('user_id','=',uid)]
79 domain += [('user_id','=',False)]
81 domain += ['|',('date_start','<=',date),('date_start','=',False)]
82 domain += ['|',('date_stop','>=',date),('date_stop','=',False)]
85 for rec in self.browse(cr, uid, self.search(cr, uid, domain, context=context), context=context):
87 if rec.product_id: index+=1
88 if rec.partner_id: index+=1
89 if rec.user_id: index+=1
90 if rec.date_start: index+=1
91 if rec.date_stop: index+=1
96 account_analytic_default()
98 class account_invoice_line(osv.osv):
99 _inherit = 'account.invoice.line'
100 _description = 'account invoice line'
101 def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition=False, price_unit=False, address_invoice_id=False, context={}):
102 res_prod = super(account_invoice_line,self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition, price_unit, address_invoice_id, context)
103 rec = self.pool.get('account.analytic.default').account_get(cr, uid, product, partner_id, uid, time.strftime('%Y-%m-%d'), context)
105 res_prod['value'].update({'account_analytic_id':rec.analytic_id.id})
107 account_invoice_line()
109 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: