~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to sale_tax_include/sale_tax_incl.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
5
#
 
6
# $Id: account.py 1005 2005-07-25 08:41:42Z nicoe $
 
7
#
 
8
# WARNING: This program as such is intended to be used by professional
 
9
# programmers who take the whole responsability of assessing all potential
 
10
# consequences resulting from its eventual inadequacies and bugs
 
11
# End users who are looking for a ready-to-use solution with commercial
 
12
# garantees and support are strongly adviced to contract a Free Software
 
13
# Service Company
 
14
#
 
15
# This program is Free Software; you can redistribute it and/or
 
16
# modify it under the terms of the GNU General Public License
 
17
# as published by the Free Software Foundation; either version 2
 
18
# of the License, or (at your option) any later version.
 
19
#
 
20
# This program is distributed in the hope that it will be useful,
 
21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
23
# GNU General Public License for more details.
 
24
#
 
25
# You should have received a copy of the GNU General Public License
 
26
# along with this program; if not, write to the Free Software
 
27
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
28
#
 
29
##############################################################################
 
30
 
 
31
import time
 
32
import netsvc
 
33
from osv import fields, osv
 
34
import ir
 
35
 
 
36
class sale_order(osv.osv):
 
37
        def _amount_untaxed(self, cr, uid, ids, prop, unknow_none,unknow_dict):
 
38
                ti = []
 
39
                for inv in self.read(cr, uid, ids, ['price_type']):
 
40
                        if inv['price_type']=='tax_included':
 
41
                                ti.append(inv['id'])
 
42
                id_set=",".join(map(str,ids))
 
43
                cr.execute("SELECT s.id,COALESCE(SUM(l.price_unit*l.product_uos_qty*(100.0-l.discount))/100.0,0)::decimal(16,2) AS amount FROM sale_order s LEFT OUTER JOIN sale_order_line l ON (s.id=l.order_id) WHERE s.id IN ("+id_set+") GROUP BY s.id ")
 
44
                res=dict(cr.fetchall())
 
45
                if len(ti):
 
46
                        tax = self._amount_tax(cr, uid, ti, prop, unknow_none,unknow_dict)
 
47
                        for id in ti:
 
48
                                res[id] = res[id] - tax.get(id,0.0)
 
49
                return res
 
50
 
 
51
        def _amount_tax(self, cr, uid, ids, field_name, arg, context):
 
52
                res = {}
 
53
                for order in self.browse(cr, uid, ids):
 
54
                        val = 0.0
 
55
                        for line in order.order_line:
 
56
                                for tax in line.tax_id:
 
57
                                        if order.price_type=='tax_included':
 
58
                                                ttt = self.pool.get('account.tax').compute_inv(cr, uid, [tax.id], line.price_unit * (1-(line.discount or 0)/100.0), line.product_uom_qty, order.partner_invoice_id.id)
 
59
                                        else:
 
60
                                                ttt = self.pool.get('account.tax').compute(cr, uid, [tax.id], line.price_unit * (1-(line.discount or 0)/100.0), line.product_uom_qty, order.partner_invoice_id.id)
 
61
                                        for c in ttt:
 
62
                                                val += round(c['amount'], 2)
 
63
                        res[order.id]=round(val,2)
 
64
                return res
 
65
        _inherit = "sale.order"
 
66
        _columns = {
 
67
                'price_type': fields.selection([
 
68
                        ('tax_included','Tax included'),
 
69
                        ('tax_excluded','Tax excluded')
 
70
                ], 'Price method', required=True),
 
71
                'amount_untaxed': fields.function(_amount_untaxed, method=True, string='Untaxed Amount'),
 
72
                'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'),
 
73
        }
 
74
        _defaults = {
 
75
                'price_type': lambda *a: 'tax_excluded',
 
76
        }
 
77
        def _inv_get(self, cr, uid, order, context={}):
 
78
                return {
 
79
                        'price_type': order.price_type
 
80
                }
 
81
sale_order()
 
82