1 # -*- encoding: utf-8 -*-
3 ##############################################################################
5 # Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
7 # WARNING: This program as such is intended to be used by professional
8 # programmers who take the whole responsability of assessing all potential
9 # consequences resulting from its eventual inadequacies and bugs
10 # End users who are looking for a ready-to-use solution with commercial
11 # garantees and support are strongly adviced to contract a Free Software
14 # This program is Free Software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ##############################################################################
30 from osv import fields,osv
34 class account_analytic_default(osv.osv):
35 _name = 'account.analytic.default'
36 _description = 'Analytic Distributions'
37 _rec_name = 'analytic_id'
40 'sequence': fields.integer('Sequence'),
41 'analytic_id': fields.many2one('account.analytic.account', 'Analytic Account'),
42 'product_id': fields.many2one('product.product', 'Product', ondelete='cascade'),
43 'partner_id': fields.many2one('res.partner', 'Partner', ondelete='cascade'),
44 'user_id': fields.many2one('res.users', 'User', ondelete='cascade'),
45 'company_id': fields.many2one('res.company', 'Company', ondelete='cascade'),
46 'date_start': fields.date('Start Date'),
47 'date_stop': fields.date('End Date'),
49 def account_get(self, cr, uid, product_id=None, partner_id=None, user_id=None, date=None, context={}):
52 domain += ['|',('product_id','=',product_id)]
53 domain += [('product_id','=',False)]
55 domain += ['|',('partner_id','=',partner_id)]
56 domain += [('partner_id','=',False)]
58 domain += ['|',('user_id','=',uid)]
59 domain += [('user_id','=',False)]
61 domain += ['|',('date_start','<=',date),('date_start','=',False)]
62 domain += ['|',('date_stop','>=',date),('date_stop','=',False)]
65 for rec in self.browse(cr, uid, self.search(cr, uid, domain, context=context), context=context):
67 if rec.product_id: index+=1
68 if rec.partner_id: index+=1
69 if rec.user_id: index+=1
70 if rec.date_start: index+=1
71 if rec.date_stop: index+=1
76 account_analytic_default()
78 class account_invoice_line(osv.osv):
79 _inherit = 'account.invoice.line'
80 _description = 'account invoice line'
81 def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, price_unit=False, address_invoice_id=False, context={}):
82 res_prod = super(account_invoice_line,self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, price_unit, address_invoice_id, context)
83 rec = self.pool.get('account.analytic.default').account_get(cr, uid, product, partner_id, uid, time.strftime('%Y-%m-%d'), context)
85 res_prod['value'].update({'account_analytic_id':rec.analytic_id.id})
87 account_invoice_line()