~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to invoice_discount/model/invoice.py

  • Committer: Luis Torres
  • Date: 2014-09-22 22:17:09 UTC
  • mto: (543.7.593 addons-vauxoo-7)
  • mto: This revision was merged to the branch mainline in revision 880.
  • Revision ID: luis_t@vauxoo.com-20140922221709-wkawz75yp0eifpy6
[ADD][invoice_discount]Were added fields to get in the lines of invoice the amount without discount and the amount of discount

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
###########################################################################
 
3
#    Module Writen to OpenERP, Open Source Management Solution
 
4
#
 
5
#    Copyright (c) 2010 Vauxoo - http://www.vauxoo.com/
 
6
#    All Rights Reserved.
 
7
#    info Vauxoo (info@vauxoo.com)
 
8
############################################################################
 
9
#    Coded by: Luis Torres (luis_t@vauxoo.com)
 
10
############################################################################
 
11
#
 
12
#    This program is free software: you can redistribute it and/or modify
 
13
#    it under the terms of the GNU Affero General Public License as
 
14
#    published by the Free Software Foundation, either version 3 of the
 
15
#    License, or (at your option) any later version.
 
16
#
 
17
#    This program is distributed in the hope that it will be useful,
 
18
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
#    GNU Affero General Public License for more details.
 
21
#
 
22
#    You should have received a copy of the GNU Affero General Public License
 
23
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
24
#
 
25
##############################################################################
 
26
'''
 
27
File to add functionalitity in account.invoice.line to get the amount without
 
28
discount and the value of the discount
 
29
'''
 
30
from openerp.osv import osv, fields
 
31
 
 
32
 
 
33
class account_invoice_line(osv.osv):
 
34
    '''
 
35
    Inherit from account.invoice.line to get by line the amount without
 
36
    discount and the amount of this
 
37
    '''
 
38
    _inherit = 'account.invoice.line'
 
39
 
 
40
    def _get_subtotal_without_discount(self, cr, uid, ids, args, fields,
 
41
                                       context=None):
 
42
        '''
 
43
        Method to get the subtotal of the amount without discount
 
44
        @param self: The object pointer.
 
45
        @param cr: A database cursor
 
46
        @param uid: ID of the user currently logged in
 
47
        @param ids: list of ids for which name should be read
 
48
        @param field_name: field that call the method
 
49
        @param arg: Extra arguments
 
50
        @param context: A standard dictionary
 
51
        @return : Dict with values
 
52
        '''
 
53
        context = context or {}
 
54
        res = {}
 
55
        for line in self.browse(cr, uid, ids, context=context):
 
56
            res[line.id] = (line.quantity * line.price_unit)
 
57
        return res
 
58
 
 
59
    def _get_discount(self, cr, uid, ids, args, fields, context=None):
 
60
        '''
 
61
        Method to get the amount of discount, is used subtraction by rounding
 
62
        @param self: The object pointer.
 
63
        @param cr: A database cursor
 
64
        @param uid: ID of the user currently logged in
 
65
        @param ids: list of ids for which name should be read
 
66
        @param field_name: field that call the method
 
67
        @param arg: Extra arguments
 
68
        @param context: A standard dictionary
 
69
        @return : Dict with values
 
70
        '''
 
71
        context = context or {}
 
72
        res = {}
 
73
        for line in self.browse(cr, uid, ids, context=context):
 
74
            res[line.id] = line.discount * line.subtotal_wo_discount / 100
 
75
        return res
 
76
 
 
77
    _columns= {
 
78
        'subtotal_wo_discount': fields.function(_get_subtotal_without_discount,
 
79
                                                string='SubTotal',
 
80
                                                store=True, type='float'),
 
81
        'discount_amount':fields.function(_get_discount, string='Discount',
 
82
                                          store=False, type='float'),
 
83
        }