1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
22 from osv import osv, fields
24 class account_invoice(osv.osv):
26 _inherit = 'account.invoice'
27 def action_number(self, cr, uid, ids, *args):
28 result = super(account_invoice, self).action_number(cr, uid, ids, *args)
29 for inv in self.browse(cr, uid, ids):
30 self.pool.get('account.invoice.line').asset_create(cr, uid, inv.invoice_line)
33 def line_get_convert(self, cr, uid, x, part, date, context=None):
34 res = super(account_invoice, self).line_get_convert(cr, uid, x, part, date, context=context)
35 res['asset_id'] = x.get('asset_id', False)
40 class account_invoice_line(osv.osv):
42 _inherit = 'account.invoice.line'
44 'asset_category_id': fields.many2one('account.asset.category', 'Asset Category'),
46 def asset_create(self, cr, uid, lines, context=None):
47 context = context or {}
48 asset_obj = self.pool.get('account.asset.asset')
50 if line.asset_category_id:
53 'code': line.invoice_id.number or False,
54 'category_id': line.asset_category_id.id,
55 'purchase_value': line.price_subtotal,
56 'period_id': line.invoice_id.period_id.id,
57 'partner_id': line.invoice_id.partner_id.id,
58 'company_id': line.invoice_id.company_id.id,
59 'currency_id': line.invoice_id.currency_id.id,
60 'purchase_date' : line.invoice_id.date_invoice,
62 changed_vals = asset_obj.onchange_category_id(cr, uid, [], vals['category_id'], context=context)
63 vals.update(changed_vals['value'])
64 asset_id = asset_obj.create(cr, uid, vals, context=context)
65 if line.asset_category_id.open_asset:
66 asset_obj.validate(cr, uid, [asset_id], context=context)
69 account_invoice_line()
71 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: