~sergio-incaser/openerp-spain/openerp-spain

« back to all changes in this revision

Viewing changes to l10n_es_account_asset/account_asset_invoice.py

  • Committer: Ana Juaristi
  • Date: 2012-03-09 16:21:34 UTC
  • mto: (275.1.25 6.0)
  • mto: This revision was merged to the branch mainline in revision 308.
  • Revision ID: ajuaristio@gmail.com-20120309162134-sjlzxy4afkkuvtpn
[ADD] l10n_es_account_asset, l10n_es_prev_tesoreria: Incluidos modulos prevision tesoreria y activos/amortizaciones.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 asset_product(osv.osv):
 
35
 
 
36
    _inherit = 'product.product'
 
37
    _columns = {
 
38
        'asset_category_id': fields.many2one('account.asset.category', 'Asset Category'),
 
39
    }
 
40
asset_product()
 
41
 
 
42
class account_invoice_line(osv.osv):
 
43
 
 
44
    _inherit = 'account.invoice.line'
 
45
    _columns = {
 
46
        'asset_category_id': fields.many2one('account.asset.category', 'Asset Category'),
 
47
    }
 
48
 
 
49
        
 
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                         
 
56
                vals = {
 
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,
 
73
                }
 
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)
 
77
        return res
 
78
                
 
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):
 
80
        value={}
 
81
        product_obj = self.pool.get('product.product')
 
82
        if 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)
 
84
            value = res['value']
 
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()
 
90
 
 
91
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: