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 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)
34
class asset_product(osv.osv):
36
_inherit = 'product.product'
38
'asset_category_id': fields.many2one('account.asset.category', 'Asset Category'),
42
class account_invoice_line(osv.osv):
44
_inherit = 'account.invoice.line'
46
'asset_category_id': fields.many2one('account.asset.category', 'Asset Category'),
50
def move_line_get_item(self, cr, uid, line, context=None):
51
asset_obj = self.pool.get('account.asset.asset')
52
res = super(account_invoice_line, self).move_line_get_item(cr, uid, line, context=context)
53
if line.invoice_id and line.invoice_id.type not in ('out_invoice', 'out_refund') and line.asset_category_id:
54
name1 = str(line.invoice_id.reference)
55
name2 = str(line.product_id) and (line.name + ": " + line.product_id.name) or line.name
57
'name': name1 + " " + name2,
58
'category_id': line.asset_category_id.id,
59
'purchase_value': line.price_subtotal,
60
'purchase_date' : line.invoice_id.date_invoice,
61
'deprec_start_date' : line.invoice_id.date_invoice,
62
'period_id': line.invoice_id.period_id.id,
63
'partner_id': line.invoice_id.partner_id.id,
64
'company_id': line.invoice_id.company_id.id,
65
'currency_id': line.invoice_id.currency_id.id,
66
'method': line.asset_category_id.method,
67
'method_number': line.asset_category_id.method_number,
68
'method_time': line.asset_category_id.method_time,
69
'method_period': line.asset_category_id.method_period,
70
'method_progress_factor': line.asset_category_id.method_progress_factor,
71
'method_end': line.asset_category_id.method_end,
72
'prorata': line.asset_category_id.prorata,
74
asset_id = asset_obj.create(cr, uid, vals, context=context)
75
if line.asset_category_id.open_asset:
76
asset_obj.validate(cr, uid, [asset_id], context=context)
79
def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, address_invoice_id=False, currency_id=False, context=None):
81
product_obj = self.pool.get('product.product')
83
res = super(account_invoice_line, self).product_id_change(cr, uid, ids, product, uom, qty, name, type, partner_id, fposition_id, price_unit, address_invoice_id, currency_id, context)
85
product_o = product_obj.browse(cr, uid, product)
86
if product_o.asset_category_id :
87
value.update ( {'asset_category_id': product_o.asset_category_id.id })
88
return {'value': value}
89
account_invoice_line()
91
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: