~jgrandguillaume-c2c/openobject-addons/multi-company-cost-price

« back to all changes in this revision

Viewing changes to account_tax_include/invoice_tax_incl.py

  • Committer: Joël Grand-Guillaume
  • Date: 2010-04-08 09:00:10 UTC
  • mfrom: (2533.3.664)
  • Revision ID: joel.grandguillaume@camptocamp.com-20100408090010-c0pqjan341s18bxs
[MRG] Merge from last trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
2
##############################################################################
3
 
#    
 
3
#
4
4
#    OpenERP, Open Source Management Solution
5
5
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6
6
#
15
15
#    GNU Affero General Public License for more details.
16
16
#
17
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/>.     
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
19
#
20
20
##############################################################################
21
21
 
24
24
from osv import fields, osv
25
25
import ir
26
26
from tools import config
 
27
import decimal_precision as dp
27
28
 
28
29
class account_invoice(osv.osv):
29
30
    _inherit = "account.invoice"
36
37
    _defaults = {
37
38
        'price_type': lambda *a: 'tax_excluded',
38
39
    }
 
40
 
 
41
    def refund(self, cr, uid, ids, date=None, period_id=None, description=None):
 
42
        map_old_new = {}
 
43
        refund_ids = []
 
44
        for old_inv_id in ids:
 
45
            new_id = super(account_invoice,self).refund(cr, uid, ids, date=date, period_id=period_id, description=description)
 
46
            refund_ids += new_id
 
47
            map_old_new[old_inv_id] = new_id[0]
 
48
 
 
49
        for old_inv_id in map_old_new.keys():
 
50
            old_inv_record = self.read(cr, uid, [old_inv_id], ['price_type'])[0]['price_type']
 
51
            self.write(cr, uid, [map_old_new[old_inv_id]], {'price_type' : old_inv_record})
 
52
        return refund_ids
 
53
 
39
54
account_invoice()
40
55
 
41
56
class account_invoice_line(osv.osv):
70
85
                else:
71
86
                    res[line.id]['price_subtotal'] = cur and cur_obj.round(cr, uid, cur, res_init[line.id]) or res_init[line.id]
72
87
                    for tax in tax_obj.compute_inv(cr, uid, product_taxes, res_init[line.id]/line.quantity, line.quantity):
73
 
                        res[line.id]['price_subtotal'] = res[line.id]['price_subtotal'] - round(tax['amount'], int(config['price_accuracy']))
 
88
                        res[line.id]['price_subtotal'] = res[line.id]['price_subtotal'] - round(tax['amount'], self.pool.get('decimal.precision').precision_get(cr, uid, 'Account'))
74
89
            else:
75
90
                res[line.id]['price_subtotal'] = cur and cur_obj.round(cr, uid, cur, res_init[line.id]) or res_init[line.id]
76
91
 
85
100
                    res[line.id]['price_subtotal'] = res[line.id]['price_subtotal'] - tax['amount']
86
101
                    res[line.id]['data'].append( tax)
87
102
 
88
 
        res[line.id]['price_subtotal']= round(res[line.id]['price_subtotal'], int(config['price_accuracy']))
89
 
        res[line.id]['price_subtotal_incl']= round(res[line.id]['price_subtotal_incl'], int(config['price_accuracy']))
 
103
            res[line.id]['price_subtotal']= round(res[line.id]['price_subtotal'], self.pool.get('decimal.precision').precision_get(cr, uid, 'Account'))
 
104
            res[line.id]['price_subtotal_incl']= round(res[line.id]['price_subtotal_incl'], self.pool.get('decimal.precision').precision_get(cr, uid, 'Account'))
90
105
        return res
91
106
 
92
107
    def _price_unit_default(self, cr, uid, context=None):
142
157
        else:
143
158
            return super(account_invoice_line, self).product_id_change_unit_price_inv(cr, uid, tax_id, price_unit, qty, address_invoice_id, product, partner_id, context=context)
144
159
 
145
 
    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, context=None):
 
160
    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):
146
161
        # note: will call product_id_change_unit_price_inv with context...
147
162
 
148
 
        # Temporary trap, for bad context that came from koo: 
 
163
        # Temporary trap, for bad context that came from koo:
149
164
        # if isinstance(context, str):
150
165
        #       print "str context:", context
151
166
 
152
167
        ctx = (context and context.copy()) or {}
153
168
        ctx.update({'price_type': ctx.get('price_type','tax_excluded')})
154
 
        return 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, context=ctx)
 
169
        return 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=currency_id, context=ctx)
155
170
account_invoice_line()
156
171
 
157
172
class account_invoice_tax(osv.osv):
166
181
        cur_obj = self.pool.get('res.currency')
167
182
        cur = inv.currency_id
168
183
        company_currency = inv.company_id.currency_id.id
169
 
        
 
184
 
170
185
        for line in inv.invoice_line:
171
186
            data = self.pool.get('account.invoice.line')._amount_line2(cr, uid, [line.id], [], [], context)[line.id]
172
187
            for tax in data['data']:
204
219
            t['amount'] = cur_obj.round(cr, uid, cur, t['amount'])
205
220
            t['base_amount'] = cur_obj.round(cr, uid, cur, t['base_amount'])
206
221
            t['tax_amount'] = cur_obj.round(cr, uid, cur, t['tax_amount'])
207
 
        
 
222
 
208
223
        return tax_grouped
209
224
account_invoice_tax()
210
225