1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2008 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 ##############################################################################
25 from osv import fields
27 from tools.translate import _
29 class account_analytic_line(osv.osv):
30 _name = 'account.analytic.line'
31 _description = 'Analytic lines'
33 'name' : fields.char('Description', size=256, required=True),
34 'date' : fields.date('Date', required=True),
35 'amount' : fields.float('Amount', required=True),
36 'unit_amount' : fields.float('Quantity'),
37 'product_uom_id' : fields.many2one('product.uom', 'UoM'),
38 'product_id' : fields.many2one('product.product', 'Product'),
39 'account_id' : fields.many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='cascade', select=True),
40 'general_account_id' : fields.many2one('account.account', 'General Account', required=True, ondelete='cascade'),
41 'move_id' : fields.many2one('account.move.line', 'Move Line', ondelete='cascade', select=True),
42 'journal_id' : fields.many2one('account.analytic.journal', 'Analytic Journal', required=True, ondelete='cascade', select=True),
43 'code' : fields.char('Code', size=8),
44 'user_id' : fields.many2one('res.users', 'User',),
45 'ref': fields.char('Ref.', size=32),
48 'date': lambda *a: time.strftime('%Y-%m-%d'),
51 def _check_company(self, cr, uid, ids):
52 lines = self.browse(cr, uid, ids)
54 if l.move_id and not l.account_id.company_id.id == l.move_id.account_id.company_id.id:
58 (_check_company, 'You can not create analytic line that is not in the same company than the account line', ['account_id'])
61 def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount,
62 unit=False, context=None):
63 uom_obj = self.pool.get('product.uom')
64 product_obj = self.pool.get('product.product')
65 if unit_amount and prod_id:
66 prod = product_obj.browse(cr, uid, prod_id)
67 a = prod.product_tmpl_id.property_account_expense.id
69 a = prod.categ_id.property_account_expense_categ.id
71 raise osv.except_osv(_('Error !'),
72 _('There is no expense account define ' \
73 'for this product: "%s" (id:%d)') % \
74 (prod.name, prod.id,))
75 amount = unit_amount * uom_obj._compute_price(cr, uid,
76 prod.uom_id.id, prod.standard_price, unit)
78 'amount': - round(amount, 2),
79 'general_account_id': a,
83 def view_header_get(self, cr, user, view_id, view_type, context):
84 if context.get('account_id', False):
85 cr.execute('select name from account_analytic_account where id=%d', (context['account_id'],))
87 res = _('Entries: ')+ (res[0] or '')
91 account_analytic_line()
94 class timesheet_invoice(osv.osv):
95 _name = "report.hr.timesheet.invoice.journal"
96 _description = "Analytic account costs and revenues"
99 'name': fields.date('Month', readonly=True),
100 'account_id':fields.many2one('account.analytic.account', 'Analytic Account', readonly=True, select=True),
101 'journal_id': fields.many2one('account.analytic.journal', 'Journal', readonly=True),
102 'quantity': fields.float('Quantities', readonly=True),
103 'cost': fields.float('Credit', readonly=True),
104 'revenue': fields.float('Debit', readonly=True)
106 _order = 'name desc, account_id'
109 create or replace view report_hr_timesheet_invoice_journal as (
112 date_trunc('month', l.date)::date as name,
114 CASE WHEN l.amount>0 THEN 0 ELSE l.amount
118 CASE WHEN l.amount>0 THEN l.amount ELSE 0
121 sum(l.unit_amount* COALESCE(u.factor, 1)) as quantity,
124 from account_analytic_line l
125 LEFT OUTER join product_uom u on (u.id=l.product_uom_id)
127 date_trunc('month', l.date),
133 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: