[FIX] account_asset: Corrected field name and coding conventions.
[odoo/odoo.git] / addons / account_asset / account_asset_invoice.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
19 #
20 ##############################################################################
21
22 from osv import osv, fields
23 import time
24
25 class account_invoice(osv.osv):
26     _inherit = 'account.invoice'
27     def line_get_convert(self, cr, uid, x, part, date, context={}):
28         res = super(account_invoice, self).line_get_convert(cr, uid, x, part, date, context)
29         res['asset_id'] = x.get('asset_id', False)
30         return res
31 account_invoice()
32
33 class account_invoice_line(osv.osv):
34     _inherit = 'account.invoice.line'
35     _columns = {
36         'asset_category_id': fields.many2one('account.asset.category', 'Asset Category'),
37     }
38     def move_line_get_item(self, cr, uid, line, context={}):
39         asset_obj = self.pool.get('account.asset.asset')
40         res = super(account_invoice_line, self).move_line_get_item(cr, uid, line, context)
41         if line.asset_category_id and line.asset_category_id.id:
42             vals = {
43                 'name': line.product_id and (line.name + ": " + line.product_id.name) or line.name,
44                 'category_id': line.asset_category_id.id,
45                 'purchase_value': line.price_subtotal
46             }
47             asset_id = asset_obj.create(cr, uid, vals, context=context)
48             if line.asset_category_id.asset_normal:
49                 asset_obj.validate(cr, uid, [asset_id], context=context)
50         return res
51 account_invoice_line()
52
53 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
54