1
# -*- encoding: utf-8 -*-
2
########################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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.
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.
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/>.
21
########################################################################
22
from datetime import datetime
23
from dateutil.relativedelta import relativedelta
25
from openerp import netsvc
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
32
class purchase_requisition(osv.Model):
33
_inherit = "purchase.requisition"
35
def _get_requisition(self, cr, uid, ids, context=None):
37
for line in self.pool.get('purchase.requisition.line').browse(cr, uid, ids, context=context):
38
result[line.requisition_id.id] = True
41
def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
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,
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']
62
'amount_total': fields.function(_amount_all, digits_compute= dp.get_precision('Account'), string='Total',
64
'purchase.requisition.line': (_get_requisition, None, 10),
65
}, multi="sums",help="The total amount"),
68
class purchase_requisition_line(osv.Model):
69
_inherit = "purchase.requisition.line"
71
def _amount_line(self, cr, uid, ids, prop, arg, context=None):
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'])
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')),