1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 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 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 General Public License for more details.
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/>.
21
##############################################################################
25
from osv import fields
26
from tools import config
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'
35
def onchange_tax(self, cr, uid, ids, lines, label, amount=False, base=False, other=False, total=False, context={}):
38
tax_amount += l[2]['active'] and l[2]['amount'] or 0
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}}
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}}
50
def onchange_partner_id(self, cr, uid, ids, partner_id, context=None):
52
return {'value': {'tax_vat': False, 'property_account_position': False}}
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}}
58
wizard_account_entry_tax_info()
60
#----------------------------------------------------------
61
# Account Tax Parameters
62
#----------------------------------------------------------
63
class account_tax_parameters(osv.osv):
64
_name = "account.tax.parameters"
65
_description = "Account Tax Parameters"
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),
85
('tax_parameters_company_uniq', 'unique (company_id)', 'The tax parameters of the must be unique per company !')
88
account_tax_parameters()
90
#----------------------------------------------------------
92
#----------------------------------------------------------
93
class account_tax_meta(osv.osv):
94
_name = "account.tax.meta"
95
_description = "Account Tax Meta"
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'),
117
#----------------------------------------------------------
119
#----------------------------------------------------------
120
class account_tax_model(osv.osv):
121
_name = "account.tax.model"
122
_description = "Account Tax Model"
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]
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'),
139
'active': lambda *a: True,
144
#----------------------------------------------------------
146
#----------------------------------------------------------
147
class account_tax_fiscal(osv.osv):
148
_name = "account.tax.fiscal"
149
_description = "Account Tax Fiscal"
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]
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),
169
'active': lambda *a: True,
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']
180
#----------------------------------------------------------
182
#----------------------------------------------------------
183
class account_tax_ietu(osv.osv):
184
_name = "account.tax.ietu"
185
_description = "Account Tax IETU"
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),
197
'active': lambda *a: True,
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']
208
#----------------------------------------------------------
210
#----------------------------------------------------------
211
class account_tax_ietu_concept(osv.osv):
212
_name = "account.tax.ietu.concept"
213
_description = "Tax IETU Concept"
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]
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),
226
account_tax_ietu_concept()
228
#----------------------------------------------------------
229
# Account Bank Entries
230
#----------------------------------------------------------
231
class account_bank_entries(osv.osv):
232
_name = "account.bank.entries"
233
_description = "Account Bank Entries"
235
def __compute(self, cr, uid, ids, field_names, arg, context={}):
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"""
245
for res in cr.dictfetchall():
246
result[res['id']] = res
249
res[id] = result[id]['amount']
252
def _get_partner(self, cr, uid, ids, field_name, arg, context={}):
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
258
def _get_vat(self, cr, uid, ids, prop, unknow_none, context=None):
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
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'),
272
_order = 'date,bank_move_id'
274
account_bank_entries()
277
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: