[IMP] optimized account invoice and removed ยต file
[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
24
25 class account_invoice(osv.osv):
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 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=None):
39         asset_obj = self.pool.get('account.asset.asset')
40         res = super(account_invoice_line, self).move_line_get_item(cr, uid, line, context=context)
41         if line.invoice_id and line.invoice_id.type not in ('out_invoice', 'out_refund') and line.asset_category_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                     'period_id': line.invoice_id.period_id.id,
47                     'partner_id': line.invoice_id.partner_id.id,
48                     'company_id': line.invoice_id.company_id.id,
49                     'currency_id': line.invoice_id.currency_id.id,
50                 }
51                 asset_id = asset_obj.create(cr, uid, vals, context=context)
52                 if line.asset_category_id.open_asset:
53                     asset_obj.validate(cr, uid, [asset_id], context=context)
54         return res
55
56 account_invoice_line()
57
58 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
59