~openbias/bias-trunk/bias-public-trunk

« back to all changes in this revision

Viewing changes to bias_tax_model/tax_model.py

  • Committer: Jose Patricio
  • Date: 2011-10-19 03:16:40 UTC
  • Revision ID: josepato@bias.com.mx-20111019031640-05zd7r5lxwx084qu
el push inicial

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-2009 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 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 General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
 
 
24
from osv import osv
 
25
from osv import fields
 
26
from tools import config
 
27
 
 
28
#----------------------------------------------------------
 
29
# wizard_account_entry_tax_info
 
30
#----------------------------------------------------------
 
31
class wizard_account_entry_tax_info(osv.osv):
 
32
    _name = 'wizard.account.entry_tax_info'
 
33
    _description = 'wizard_account_entry_tax_info'
 
34
    
 
35
    def onchange_tax(self, cr, uid, ids, lines, label, amount=False, base=False, other=False, total=False, context={}):
 
36
        tax_amount = 0
 
37
        for l in lines:
 
38
            tax_amount += l[2]['active'] and l[2]['amount'] or 0
 
39
        if label == 'ietu':
 
40
            return {'value': {label: tax_amount}}
 
41
        dif_amount = amount - (base + tax_amount)
 
42
        dif_total = total + base + tax_amount + other
 
43
        return {'value': {label: tax_amount, 'dif_amount': dif_amount, 'dif_total':dif_total}}
 
44
 
 
45
    def onchange_amount(self, cr, uid, ids, base, tax, amount, other, total, context={}):
 
46
        dif_amount = amount - (base + tax)
 
47
        dif_total = total + base + tax + other
 
48
        return {'value': {'dif_amount': dif_amount, 'dif_total':dif_total}}
 
49
 
 
50
    def onchange_partner_id(self, cr, uid, ids, partner_id, context=None):
 
51
        if not partner_id:
 
52
            return {'value': {'tax_vat': False, 'property_account_position': False}}
 
53
        else:
 
54
            vat = self.pool.get('res.partner').browse(cr, uid, partner_id).vat
 
55
            fiscal = self.pool.get('res.partner').browse(cr, uid, partner_id).property_account_position.id
 
56
        return {'value': {'tax_vat': vat, 'property_account_position.id': fiscal}}
 
57
 
 
58
wizard_account_entry_tax_info()
 
59
 
 
60
#----------------------------------------------------------
 
61
# Account Tax Parameters
 
62
#----------------------------------------------------------
 
63
class account_tax_parameters(osv.osv):
 
64
    _name = "account.tax.parameters"
 
65
    _description = "Account Tax Parameters"
 
66
 
 
67
    _columns = {
 
68
        'name': fields.char('Name', size=64, required=True),
 
69
        'third_party_type_ids': fields.one2many('third.party.type', 'tax_parameters_id', 'Third Party Type'),
 
70
        'third_party_operation_ids': fields.one2many('third.party.operation', 'tax_parameters_id', 'Third Party Operation'),
 
71
        'account_tax_ietu_ids': fields.one2many('account.tax.ietu.concept', 'tax_parameters_id', 'IETU Concept'),
 
72
        'tax_model': fields.one2many('account.tax.model', 'tax_parameters_id', 'Tax Model'),
 
73
        'amount': fields.many2many('account.account.type', 'account_amount_parameters_rel','parameter_id','account_type_id', 'Amount Accounts Types'),
 
74
        'base': fields.many2many('account.account.type', 'account_base_parameters_rel','parameter_id','account_type_id', 'Base Accounts Types'),
 
75
        'total': fields.many2many('account.account.type', 'account_total_parameters_rel','parameter_id','account_type_id', 'Total Accounts Types'),
 
76
        'ietu': fields.many2many('account.account.type', 'account_ietu_parameters_rel','parameter_id','account_type_id', 'IETU Accounts Types'),
 
77
        'tax': fields.many2many('account.account.type', 'account_tax_parameters_rel','parameter_id','account_type_id', 'Tax Accounts'),
 
78
        'other': fields.many2many('account.account.type', 'account_other_parameters_rel','parameter_id','account_id', 'Other Accounts'),
 
79
        'company_id': fields.many2one('res.company', 'Company', required=True),
 
80
    }
 
81
 
 
82
    _defaults = {
 
83
    }
 
84
    _sql_constraints = [
 
85
        ('tax_parameters_company_uniq', 'unique (company_id)', 'The tax parameters of the must be unique per company !')
 
86
    ]
 
87
 
 
88
account_tax_parameters()
 
89
 
 
90
#----------------------------------------------------------
 
91
# Meta Data
 
92
#----------------------------------------------------------
 
93
class account_tax_meta(osv.osv):
 
94
    _name = "account.tax.meta"
 
95
    _description = "Account Tax Meta"
 
96
 
 
97
    _columns = {
 
98
        'serial': fields.char('Serial', size=32),
 
99
        'folio': fields.char('Sequence', size=32),
 
100
        'state': fields.char('State', size=32),
 
101
        'reference': fields.char('Reference', size=64),
 
102
        'move_id': fields.many2one('account.move', 'Entry'),
 
103
        'partner_id': fields.many2one('res.partner', 'Partner'),
 
104
        'third_party_type': fields.char('Third Party Type', size=8),
 
105
        'ietu_concept': fields.char('IETU Concept', size=8),
 
106
        'amount': fields.float('Amount'),
 
107
        'base': fields.float('Base'),
 
108
        'ietu': fields.float('IETU'),
 
109
        'other': fields.float('Other'),
 
110
        'tax': fields.float('tax'),
 
111
        'total': fields.float('Total'),
 
112
        'diot': fields.boolean('DIOT'),
 
113
    }
 
114
 
 
115
account_tax_meta()
 
116
 
 
117
#----------------------------------------------------------
 
118
# Account Tax Model
 
119
#----------------------------------------------------------
 
120
class account_tax_model(osv.osv):
 
121
    _name = "account.tax.model"
 
122
    _description = "Account Tax Model"
 
123
 
 
124
    def _tax_get(self, cr, uid, context={}):
 
125
        obj = self.pool.get('account.account')
 
126
        type_id = self.pool.get('account.account.type').search(cr, uid, [('code','=','tax')])[0]
 
127
        ids = obj.search(cr, uid, [('user_type','=',type_id)])
 
128
        res = obj.read(cr, uid, ids, ['code','name'])
 
129
        return [(r['code'], r['code']+'-'+r['name']) for r in res]
 
130
 
 
131
    _columns = {
 
132
        'tax_parameters_id': fields.many2one('account.tax.parameters', 'Tax Parameter', required=True),
 
133
        'tax': fields.selection(_tax_get, 'Tax', size=32, required=True ),
 
134
        'xfer': fields.selection(_tax_get, 'Tranfer', size=32, required=True ),
 
135
        'active': fields.boolean('Active'),
 
136
    }
 
137
 
 
138
    _defaults = {
 
139
        'active': lambda *a: True,
 
140
    }
 
141
 
 
142
account_tax_model()
 
143
 
 
144
#----------------------------------------------------------
 
145
# Account Fiscal Tax
 
146
#----------------------------------------------------------
 
147
class account_tax_fiscal(osv.osv):
 
148
    _name = "account.tax.fiscal"
 
149
    _description = "Account Tax Fiscal"
 
150
 
 
151
    def _tax_get(self, cr, uid, context={}):
 
152
        obj = self.pool.get('account.account')
 
153
        type_id = self.pool.get('account.account.type').search(cr, uid, [('code','=','tax')])[0]
 
154
        ids = obj.search(cr, uid, [('user_type','=',type_id)])
 
155
        res = obj.read(cr, uid, ids, ['code','name'])
 
156
        return [(r['code'], r['code']+'-'+r['name']) for r in res]
 
157
 
 
158
    _columns = {
 
159
        'move_id': fields.many2one('account.move', 'Entry', required=True),
 
160
        'line_id': fields.many2one('account.move.line', 'Line', required=False),
 
161
        'tax': fields.selection(_tax_get, 'Tax', size=32, required=False ),
 
162
        'xfer': fields.selection(_tax_get, 'Xfer', size=32, required=False ),
 
163
        'amount': fields.float('Amount', required=False),
 
164
        'active': fields.boolean('Active'),
 
165
        'name': fields.char('Name', size=64, required=True),
 
166
    }
 
167
 
 
168
    _defaults = {
 
169
        'active': lambda *a: True,
 
170
    }
 
171
 
 
172
    def default_get(self, cr, uid, fields, context={}):
 
173
        data = super(account_tax_fiscal, self).default_get(cr, uid, fields, context)
 
174
        if 'move_id' in fields and 'move_id' in context:
 
175
            data['move_id'] = context['move_id']
 
176
        return data
 
177
 
 
178
account_tax_fiscal()
 
179
 
 
180
#----------------------------------------------------------
 
181
# Account Tax IETU
 
182
#----------------------------------------------------------
 
183
class account_tax_ietu(osv.osv):
 
184
    _name = "account.tax.ietu"
 
185
    _description = "Account Tax IETU"
 
186
 
 
187
    _columns = {
 
188
        'move_id': fields.many2one('account.move', 'Entry', required=True),
 
189
        'line_id': fields.many2one('account.move.line', 'Line', required=True),
 
190
        'account_id': fields.many2one('account.account', 'Account', required=True),
 
191
        'amount': fields.float('Amount', required=False),
 
192
        'active': fields.boolean('Active'),
 
193
        'name': fields.char('Name', size=64, required=True),
 
194
    }
 
195
 
 
196
    _defaults = {
 
197
        'active': lambda *a: True,
 
198
    }
 
199
 
 
200
    def default_get(self, cr, uid, fields, context={}):
 
201
        data = super(account_tax_ietu, self).default_get(cr, uid, fields, context)
 
202
        if 'move_id' in fields and 'move_id' in context:
 
203
            data['move_id'] = context['move_id']
 
204
        return data
 
205
 
 
206
account_tax_ietu()
 
207
 
 
208
#----------------------------------------------------------
 
209
# IETU Concept
 
210
#----------------------------------------------------------
 
211
class account_tax_ietu_concept(osv.osv):
 
212
    _name = "account.tax.ietu.concept"
 
213
    _description = "Tax IETU Concept"
 
214
 
 
215
    def _tax_get(self, cr, uid, context={}):
 
216
        ids = self.search(cr, uid, [])
 
217
        res = self.read(cr, uid, ids, ['code','name'])
 
218
        return [(r['code'], r['code']+'-'+r['name']) for r in res]
 
219
 
 
220
    _columns = {
 
221
        'tax_parameters_id': fields.many2one('account.tax.parameters', 'Tax Parameter', required=True),
 
222
        'name': fields.char('Name', size=64, required=True),
 
223
        'code': fields.char('Code', size=8, required=True),
 
224
    }
 
225
 
 
226
account_tax_ietu_concept()
 
227
 
 
228
#----------------------------------------------------------
 
229
# Account Bank Entries
 
230
#----------------------------------------------------------
 
231
class account_bank_entries(osv.osv):
 
232
    _name = "account.bank.entries"
 
233
    _description = "Account Bank Entries"
 
234
 
 
235
    def __compute(self, cr, uid, ids, field_names, arg, context={}):
 
236
        result = {}
 
237
        query = """SELECT b.id, SUM(l.debit) - SUM(l.credit) AS amount
 
238
                FROM account_bank_entries b
 
239
                LEFT JOIN account_move m ON (b.bank_move_id = m.id)
 
240
                LEFT JOIN account_move_line l ON (l.move_id = m.id) 
 
241
                LEFT JOIN account_account a ON (l.account_id = a.id) 
 
242
                LEFT JOIN account_account_type t ON (a.user_type = t.id) 
 
243
                WHERE t.code = 'cash' AND b.id IN ("""+",".join(map(str, ids))+""") GROUP BY b.id"""
 
244
        cr.execute(query)
 
245
        for res in cr.dictfetchall():
 
246
            result[res['id']] = res
 
247
        res = {}
 
248
        for id in ids:
 
249
            res[id] = result[id]['amount']
 
250
        return res
 
251
 
 
252
    def _get_partner(self, cr, uid, ids, field_name, arg, context={}):
 
253
        result = {}
 
254
        for rec in self.browse(cr, uid, ids, context):
 
255
            result[rec.id] = rec.bank_move_id.line_id and rec.bank_move_id.line_id[0].partner_id.id
 
256
        return result
 
257
 
 
258
    def _get_vat(self, cr, uid, ids, prop, unknow_none, context=None):
 
259
        result = {}
 
260
        for rec in self.browse(cr, uid, ids, context):
 
261
            result[rec.id] = rec.bank_move_id.line_id and rec.bank_move_id.line_id[0].partner_id.vat
 
262
        return result
 
263
 
 
264
    _columns = {
 
265
        'name': fields.char('Line Name', size=32, required=True),
 
266
        'bank_move_id': fields.many2one('account.move', 'Bank Entry', required=True, select=True),
 
267
        'date': fields.date('Date', required=True),
 
268
        'amount': fields.function(__compute, digits=(16, 2), method=True, string='Amount'),
 
269
        'partner_id': fields.function(_get_partner, method=True, type='many2one', relation='res.partner', string='Partner'),
 
270
        'vat': fields.function(_get_vat, method=True, type="char", string='VAT'),
 
271
    }
 
272
    _order = 'date,bank_move_id'
 
273
 
 
274
account_bank_entries()
 
275
 
 
276
 
 
277
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
278