[IMP] french translations
[odoo/odoo.git] / addons / account_analytic_default / account_analytic_default.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution   
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
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.
12 #
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.
17 #
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/>.
20 #
21 ##############################################################################
22
23 ##############################################################################
24 #
25 # Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
26 #
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
32 # Service Company
33 #
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.
38 #
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.
43 #
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.
47 #
48 ##############################################################################
49
50 from osv import fields,osv
51 from osv import orm
52 import time
53
54 class account_analytic_default(osv.osv):
55     _name = 'account.analytic.default'
56     _description = 'Analytic Distributions'
57     _rec_name = 'analytic_id'
58     _order = 'sequence'
59     _columns = {
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'),
68     }
69     def account_get(self, cr, uid, product_id=None, partner_id=None, user_id=None, date=None, context={}):
70         domain = []
71         if product_id:
72             domain += ['|',('product_id','=',product_id)]
73         domain += [('product_id','=',False)]
74         if partner_id:
75             domain += ['|',('partner_id','=',partner_id)]
76         domain += [('partner_id','=',False)]
77         if user_id:
78             domain += ['|',('user_id','=',uid)]
79         domain += [('user_id','=',False)]
80         if date:
81             domain += ['|',('date_start','<=',date),('date_start','=',False)]
82             domain += ['|',('date_stop','>=',date),('date_stop','=',False)]
83         best_index = -1
84         res = False
85         for rec in self.browse(cr, uid, self.search(cr, uid, domain, context=context), context=context):
86             index = 0
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
92             if index>best_index:
93                 res = rec
94                 best_index = index
95         return res
96 account_analytic_default()
97
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)
104         if rec:
105             res_prod['value'].update({'account_analytic_id':rec.analytic_id.id})
106         return res_prod
107 account_invoice_line()
108
109 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: