[CLEANING] cleaned the account asset invoice
[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-2010 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
24 class account_invoice(osv.osv):
25
26     _inherit = 'account.invoice'
27     def line_get_convert(self, cr, uid, x, part, date, context=None):
28         res = super(account_invoice, self).line_get_convert(cr, uid, x, part, date, context=context)
29         res['asset_id'] = x.get('asset_id', False)
30         return res
31
32 account_invoice()
33
34 class account_invoice_line(osv.osv):
35
36     _inherit = 'account.invoice.line'
37     _columns = {
38         'asset_category_id': fields.many2one('account.asset.category', 'Asset Category'),
39     }
40
41     def move_line_get_item(self, cr, uid, line, context=None):
42         asset_obj = self.pool.get('account.asset.asset')
43         res = super(account_invoice_line, self).move_line_get_item(cr, uid, line, context=context)
44         if line.invoice_id and line.invoice_id.type not in ('out_invoice', 'out_refund') and line.asset_category_id:
45                 vals = {
46                     'name': line.product_id and (line.name + ": " + line.product_id.name) or line.name,
47                     'category_id': line.asset_category_id.id,
48                     'purchase_value': line.price_subtotal,
49                     'period_id': line.invoice_id.period_id.id,
50                     'partner_id': line.invoice_id.partner_id.id,
51                     'company_id': line.invoice_id.company_id.id,
52                     'currency_id': line.invoice_id.currency_id.id,
53                 }
54                 asset_id = asset_obj.create(cr, uid, vals, context=context)
55                 if line.asset_category_id.open_asset:
56                     asset_obj.validate(cr, uid, [asset_id], context=context)
57         return res
58
59 account_invoice_line()
60
61 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: