~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to purchase_requisition_line_price_unit/model/purchase_requisition_line.py

  • Committer: Jose Morales
  • Date: 2014-07-28 20:00:11 UTC
  • mfrom: (543.7.551 7.0-addons-vauxoo)
  • Revision ID: jose@vauxoo.com-20140728200011-csytovehrzwp24lr
[FORWARD PORT] 7.0

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>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU Affero General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU Affero General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU Affero General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
########################################################################
 
22
from datetime import datetime
 
23
from dateutil.relativedelta import relativedelta
 
24
import time
 
25
from openerp import netsvc
 
26
 
 
27
from openerp.osv import fields, osv
 
28
from openerp.tools.translate import _
 
29
import openerp.addons.decimal_precision as dp
 
30
from openerp import tools
 
31
 
 
32
class purchase_requisition(osv.Model):
 
33
    _inherit = "purchase.requisition"
 
34
 
 
35
    def _get_requisition(self, cr, uid, ids, context=None):
 
36
        result = {}
 
37
        for line in self.pool.get('purchase.requisition.line').browse(cr, uid, ids, context=context):
 
38
            result[line.requisition_id.id] = True
 
39
        return result.keys()
 
40
 
 
41
    def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
 
42
        res = {}
 
43
        cur_obj=self.pool.get('res.currency')
 
44
        for requisition in self.browse(cr, uid, ids, context=context):
 
45
            res[requisition.id] = {
 
46
                'amount_untaxed': 0.0,
 
47
                'amount_tax': 0.0,
 
48
                'amount_total': 0.0,
 
49
            }
 
50
            val = val1 = 0.0
 
51
            cur = requisition.currency_id
 
52
            for line in requisition.line_ids:
 
53
               val1 += line.price_subtotal
 
54
               for c in self.pool.get('account.tax').compute_all(cr, uid, [], line.price_unit, line.product_qty, line.product_id)['taxes']:
 
55
                    val += c.get('amount', 0.0)
 
56
            #res[requisition.id]['amount_tax']=cur_obj.round(cr, uid, cur, val)
 
57
            amount_untaxed =cur_obj.round(cr, uid, cur, val1)
 
58
            res[requisition.id]['amount_total']= amount_untaxed # + res[requisition.id]['amount_tax']
 
59
        return res
 
60
    
 
61
    _columns = {
 
62
        'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Total',
 
63
            store={
 
64
                'purchase.requisition.line': (_get_requisition, None, 10),
 
65
            }, multi="sums",help="The total amount"),
 
66
    }
 
67
 
 
68
class purchase_requisition_line(osv.Model):
 
69
    _inherit = "purchase.requisition.line"
 
70
 
 
71
    def _amount_line(self, cr, uid, ids, prop, arg, context=None):
 
72
        res = {}
 
73
        cur_obj=self.pool.get('res.currency')
 
74
        tax_obj = self.pool.get('account.tax')
 
75
        for line in self.browse(cr, uid, ids, context=context):
 
76
            taxes = tax_obj.compute_all(cr, uid, [], line.price_unit, line.product_qty, line.product_id)
 
77
            #cur = line.requisition_id.pricelist_id.currency_id
 
78
            cur = line.requisition_id.currency_id
 
79
            res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])
 
80
        return res
 
81
 
 
82
    _columns = {
 
83
        'price_unit': fields.float('Unit Price', digits_compute= dp.get_precision('Product Price')),
 
84
        'price_subtotal': fields.function(_amount_line, string='Subtotal', digits_compute= dp.get_precision('Account')),
 
85
    }
 
86