2
# -*- coding: utf-8 -*-
3
##############################################################################
5
# OpenERP, Open Source Management Solution
6
# Copyright (C) 2011 TeMPO Consulting, MSF. All Rights Reserved
7
# Developer: Olivier DOSSMANN
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU Affero General Public License as
11
# published by the Free Software Foundation, either version 3 of the
12
# License, or (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU Affero General Public License for more details.
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
25
from osv import fields
26
from tools.translate import _
27
from tools import flatten
29
class account_mcdb(osv.osv):
30
_name = 'account.mcdb'
33
'description': fields.char("Query name", required=False, readonly=False, size=255),
34
'journal_ids': fields.many2many(obj='account.journal', rel='account_journal_mcdb', id1='mcdb_id', id2='journal_id', string="Journal Code"),
35
'instance_ids': fields.many2many('msf.instance', 'instance_mcdb', 'mcdb_id', 'instance_id', string="Proprietary instance"),
36
'analytic_journal_ids': fields.many2many(obj='account.analytic.journal', rel='account_analytic_journal_mcdb', id1='mcdb_id', id2='analytic_journal_id', string="Analytic journal code"),
37
'abs_id': fields.many2one('account.bank.statement', string="Register name"), # Change into many2many ?
38
'posting_date_from': fields.date('First posting date'),
39
'posting_date_to': fields.date('Ending posting date'),
40
'document_date_from': fields.date('First document date'),
41
'document_date_to': fields.date('Ending document date'),
42
'document_code': fields.char(string='Sequence number', size=255),
43
'document_state': fields.selection([('posted', 'Posted'), ('draft', 'Unposted')], string="Document Status"),
44
'period_ids': fields.many2many(obj='account.period', rel="account_period_mcdb", id1="mcdb_id", id2="period_id", string="Accounting Period"),
45
'account_ids': fields.many2many(obj='account.account', rel='account_account_mcdb', id1='mcdb_id', id2='account_id', string="Account Code"),
46
'partner_id': fields.many2one('res.partner', string="Partner"),
47
'employee_id': fields.many2one('hr.employee', string="Employee"),
48
'transfer_journal_id': fields.many2one('account.journal', string="Journal"),
49
'reconciled': fields.selection([('reconciled', 'Reconciled'), ('unreconciled', 'NOT reconciled')], string='Reconciled?'),
50
'functional_currency_id': fields.many2one('res.currency', string="Functional currency", readonly=True),
51
'amount_func_from': fields.float('Begin amount in functional currency'),
52
'amount_func_to': fields.float('Ending amount in functional currency'),
53
'booking_currency_id': fields.many2one('res.currency', string="Booking currency"),
54
'amount_book_from': fields.float('Begin amount in booking currency'),
55
'amount_book_to': fields.float('Ending amount in booking currency'),
56
'currency_choice': fields.selection([('booking', 'Booking'), ('functional', 'Functional')], string="Currency type"),
57
'currency_id': fields.many2one('res.currency', string="Currency"),
58
'amount_from': fields.float('Begin amount in given currency type'),
59
'amount_to': fields.float('Ending amount in given currency type'),
60
'account_type_ids': fields.many2many(obj='account.account.type', rel='account_account_type_mcdb', id1='mcdb_id', id2='account_type_id',
61
string="Account type"),
62
'reconcile_id': fields.many2one('account.move.reconcile', string="Reconcile Reference"),
63
'ref': fields.char(string='Reference', size=255),
64
'name': fields.char(string='Description', size=255),
65
'rev_account_ids': fields.boolean('Exclude account selection'),
66
'model': fields.selection([('account.move.line', 'Journal Items'), ('account.analytic.line', 'Analytic Journal Items')], string="Type"),
67
'display_in_output_currency': fields.many2one('res.currency', string='Display in output currency'),
68
'fx_table_id': fields.many2one('res.currency.table', string="FX Table"),
69
'analytic_account_cc_ids': fields.many2many(obj='account.analytic.account', rel="account_analytic_cc_mcdb", id1="mcdb_id", id2="analytic_account_id",
70
string="Cost Center"),
71
'rev_analytic_account_cc_ids': fields.boolean('Exclude Cost Center selection'),
72
'analytic_account_fp_ids': fields.many2many(obj='account.analytic.account', rel="account_analytic_fp_mcdb", id1="mcdb_id", id2="analytic_account_id",
73
string="Funding Pool"),
74
'rev_analytic_account_fp_ids': fields.boolean('Exclude Funding Pool selection'),
75
'analytic_account_f1_ids': fields.many2many(obj='account.analytic.account', rel="account_analytic_f1_mcdb", id1="mcdb_id", id2="analytic_account_id",
77
'rev_analytic_account_f1_ids': fields.boolean('Exclude free 1 selection'),
78
'analytic_account_f2_ids': fields.many2many(obj='account.analytic.account', rel="account_analytic_f2_mcdb", id1="mcdb_id", id2="analytic_account_id",
80
'rev_analytic_account_f2_ids': fields.boolean('Exclude free 2 selection'),
81
'reallocated': fields.selection([('reallocated', 'Reallocated'), ('unreallocated', 'NOT reallocated')], string='Reallocated?'),
82
'reversed': fields.selection([('reversed', 'Reversed'), ('notreversed', 'NOT reversed')], string='Reversed?'),
83
'rev_journal_ids': fields.boolean('Exclude journal selection'),
84
'rev_period_ids': fields.boolean('Exclude period selection'),
85
'rev_account_type_ids': fields.boolean('Exclude account type selection'),
86
'rev_analytic_journal_ids': fields.boolean('Exclude analytic journal selection'),
87
'rev_instance_ids': fields.boolean('Exclude instance selection'),
88
'analytic_axis': fields.selection([('fp', 'Funding Pool'), ('f1', 'Free 1'), ('f2', 'Free 2')], string='Display'),
89
'rev_analytic_account_dest_ids': fields.boolean('Exclude Destination selection'),
90
'analytic_account_dest_ids': fields.many2many(obj='account.analytic.account', rel="account_analytic_dest_mcdb", id1="mcdb_id", id2="analytic_account_id",
91
string="Destination"),
92
'display_journal': fields.boolean('Display journals?'),
93
'display_period': fields.boolean('Display periods?'),
94
'display_instance': fields.boolean('Display instances?'),
95
'display_account': fields.boolean('Display accounts?'),
96
'display_analytic_account': fields.boolean('Display analytic accounts?'),
97
'display_type': fields.boolean('Display account types?'),
98
'display_analytic_period': fields.boolean('Display analytic periods?'),
99
'display_analytic_journal': fields.boolean('Display analytic journals?'),
100
'display_funding_pool': fields.boolean('Display funding pools?'),
101
'display_cost_center': fields.boolean('Display cost centers?'),
102
'display_destination': fields.boolean('Display destinations?'),
103
'display_free1': fields.boolean('Display Free 1?'),
104
'display_free2': fields.boolean('Display Free 2?'),
105
'user': fields.many2one('res.users', "User"),
109
'model': lambda self, cr, uid, c: c.get('from', 'account.move.line'),
110
'functional_currency_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.currency_id.id,
111
'currency_choice': lambda *a: 'booking',
112
'analytic_axis': lambda *a: 'fp',
113
'display_journal': lambda *a: False,
114
'display_period': lambda *a: False,
115
'display_instance': lambda *a: False,
116
'display_account': lambda *a: False,
117
'display_analytic_account': lambda *a: False,
118
'display_type': lambda *a: False,
119
'display_analytic_period': lambda *a: False,
120
'display_analytic_journal': lambda *a: False,
121
'display_funding_pool': lambda *a: False,
122
'display_cost_center': lambda *a: False,
123
'display_destination': lambda *a: False,
124
'user': lambda self, cr, uid, c: uid or False,
127
def onchange_currency_choice(self, cr, uid, ids, choice, func_curr=False, mnt_from=0.0, mnt_to=0.0, context=None):
129
Permit to give default company currency if 'functional' has been choosen.
130
Delete all currency and amount fields (to not disturb normal mechanism)
133
if isinstance(ids, (int, long)):
137
# Prepare some values
140
for field in ['amount_book_from', 'amount_book_to', 'amount_func_from', 'amount_func_to', 'booking_currency_id']:
143
if choice == 'functional':
144
vals.update({'currency_id': func_curr or False})
145
elif choice == 'booking':
146
vals.update({'currency_id': False})
147
# Update amounts 'from' and 'to'.
148
update_from = self.onchange_amount(cr, uid, ids, choice, mnt_from, 'from', context=context)
149
update_to = self.onchange_amount(cr, uid, ids, choice, mnt_to, 'to', context=context)
151
vals.update(update_from.get('value'))
153
vals.update(update_to.get('value'))
154
return {'value': vals}
156
def onchange_currency(self, cr, uid, ids, choice, currency, context=None):
158
Fill in right field regarding choice and currency
160
# Prepare some values
166
if choice == 'functional':
167
vals['functional_currency_id'] = currency
168
elif choice == 'booking':
169
vals['booking_currency_id'] = currency
170
return {'value': vals}
172
def onchange_amount(self, cr, uid, ids, choice, amount, amount_type=None, context=None):
174
Fill in right amount field regarding choice
176
# Prepare some values
183
if choice == 'functional':
184
if amount_type == 'from':
185
vals['amount_func_from'] = amount
186
elif amount_type == 'to':
187
vals ['amount_func_to'] = amount
188
elif choice == 'booking':
189
if amount_type == 'from':
190
vals['amount_book_from'] = amount
191
elif amount_type == 'to':
192
vals['amount_book_to'] = amount
193
return {'value': vals}
195
def onchange_fx_table(self, cr, uid, ids, fx_table_id, context=None):
197
Update output currency domain in order to show right currencies attached to given fx table
204
res.update({'value': {'display_in_output_currency' : False}})
207
def onchange_analytic_axis(self, cr, uid, ids, analytic_axis, context=None):
209
Clean up Cost Center / Destination / Funding Pool / Free 1 and Free 2 frames
212
if not analytic_axis:
214
vals.update({'analytic_account_fp_ids': False, 'analytic_account_cc_ids': False, 'analytic_account_dest_ids': False, 'analytic_account_f1_ids': False, 'analytic_account_f2_ids': False})
215
return {'value': vals}
217
def button_validate(self, cr, uid, ids, context=None):
219
Validate current forms and give result
224
if isinstance(ids, (int, long)):
226
# Prepare some values
228
wiz = self.browse(cr, uid, [ids[0]], context=context)[0]
229
res_model = wiz and wiz.model or False
231
# Prepare domain values
232
# First MANY2MANY fields
233
m2m_fields = [('period_ids', 'period_id'), ('journal_ids', 'journal_id'), ('analytic_journal_ids', 'journal_id'),
234
('analytic_account_fp_ids', 'account_id'), ('analytic_account_cc_ids', 'cost_center_id'),
235
('analytic_account_f1_ids', 'account_id'), ('analytic_account_f2_ids', 'account_id'), ('analytic_account_dest_ids', 'destination_id'),
236
('instance_ids', 'instance_id')]
237
if res_model == 'account.analytic.line':
238
m2m_fields.append(('account_ids', 'general_account_id'))
239
m2m_fields.append(('account_type_ids', 'general_account_id.user_type'))
241
m2m_fields.append(('account_ids', 'account_id'))
242
m2m_fields.append(('account_type_ids', 'account_id.user_type'))
243
for m2m in m2m_fields:
244
if getattr(wiz, m2m[0]):
247
# account_ids with reversal
248
if m2m[0] == 'account_ids' and wiz.rev_account_ids:
250
# analytic_account_fp_ids with reversal
251
if m2m[0] == 'analytic_account_fp_ids' and wiz.rev_analytic_account_fp_ids:
253
# analytic_account_cc_ids with reversal
254
if m2m[0] == 'analytic_account_cc_ids' and wiz.rev_analytic_account_cc_ids:
256
# analytic_account_f1_ids with reversal
257
if m2m[0] == 'analytic_account_f1_ids' and wiz.rev_analytic_account_f1_ids:
259
# analytic_account_f2_ids with reversal
260
if m2m[0] == 'analytic_account_f2_ids' and wiz.rev_analytic_account_f2_ids:
262
# analytic_account_dest_ids with reversal
263
if m2m[0] == 'analytic_account_dest_ids' and wiz.rev_analytic_account_dest_ids:
265
# period_ids with reversal
266
if m2m[0] == 'period_ids' and wiz.rev_period_ids:
268
# journal_ids with reversal
269
if m2m[0] == 'journal_ids' and wiz.rev_journal_ids:
271
# account_type_ids with reversal
272
if m2m[0] == 'account_type_ids' and wiz.rev_account_type_ids:
274
# analytic_journal_ids with reversal
275
if m2m[0] == 'analytic_journal_ids' and wiz.rev_analytic_journal_ids:
277
# instance_ids with reversal
278
if m2m[0] == 'instance_ids' and wiz.rev_instance_ids:
280
# Search if a view account is given
281
if m2m[0] in ['account_ids', 'analytic_account_fp_ids', 'analytic_account_cc_ids', 'analytic_account_f1_ids', 'analytic_account_f2_ids']:
283
account_obj = 'account.account'
284
if m2m[0] in ['analytic_account_fp_ids', 'analytic_account_cc_ids', 'analytic_account_f1_ids', 'analytic_account_f2_ids']:
285
account_obj = 'account.analytic.account'
286
for account in getattr(wiz, m2m[0]):
287
if account.type == 'view':
288
search_ids = self.pool.get(account_obj).search(cr, uid, [('id', 'child_of', [account.id])])
289
account_ids.append(search_ids)
291
# Add default account_ids from wizard
292
account_ids.append([x.id for x in getattr(wiz, m2m[0])])
293
# Convert list in a readable list for openerp
294
account_ids = flatten(account_ids)
295
# Create domain and NEXT element (otherwise this give a bad domain)
296
domain.append((m2m[1], operator, tuple(account_ids)))
298
domain.append((m2m[1], operator, tuple([x.id for x in getattr(wiz, m2m[0])])))
299
# Then MANY2ONE fields
300
for m2o in [('abs_id', 'statement_id'), ('partner_id', 'partner_id'), ('employee_id', 'employee_id'),
301
('transfer_journal_id', 'transfer_journal_id'), ('booking_currency_id', 'currency_id'), ('reconcile_id', 'reconcile_id')]:
302
if getattr(wiz, m2o[0]):
303
domain.append((m2o[1], '=', getattr(wiz, m2o[0]).id))
304
# Finally others fields
306
for ll in [('ref', 'ref'), ('name', 'name')]:
307
if getattr(wiz, ll[0]):
308
domain.append((ll[1], 'ilike', '%%%s%%' % getattr(wiz, ll[0])))
309
# DOCUMENT CODE fields
310
if wiz.document_code and wiz.document_code != '':
311
document_code_field = 'move_id.name'
312
if res_model == 'account.analytic.line':
314
domain.append(('move_id.move_id.name', 'ilike', '%%%s%%' % wiz.document_code))
315
domain.append(('commitment_line_id.commit_id.name', 'ilike', '%%%s%%' % wiz.document_code))
317
domain.append((document_code_field, 'ilike', '%%%s%%' % wiz.document_code))
318
if wiz.document_state and wiz.document_state != '':
319
domain.append(('move_id.state', '=', wiz.document_state))
321
for sup in [('posting_date_from', 'date'), ('document_date_from', 'document_date')]:
322
if getattr(wiz, sup[0]):
323
domain.append((sup[1], '>=', getattr(wiz, sup[0])))
324
for inf in [('posting_date_to', 'date'), ('document_date_to', 'document_date')]:
325
if getattr(wiz, inf[0]):
326
domain.append((inf[1], '<=', getattr(wiz, inf[0])))
329
if wiz.reconciled == 'reconciled':
330
domain.append(('reconcile_id', '!=', False))
331
elif wiz.reconciled == 'unreconciled':
332
domain.append(('reconcile_id', '=', False))
335
domain.append(('reconcile_id', '=', wiz.reconcile_id.id))
336
domain.append(('reconcile_partial_id', '=', wiz.reconcile_id.id))
339
if wiz.reallocated == 'reallocated':
340
domain.append(('is_reallocated', '=', True))
341
elif wiz.reallocated == 'unreallocated':
342
domain.append(('is_reallocated', '=', False))
345
if wiz.reversed == 'reversed':
346
domain.append(('is_reversal', '=', True))
347
elif wiz.reversed == 'notreversed':
348
domain.append(('is_reversal', '=', False))
349
# ANALYTIC AXIS FIELD
350
if res_model == 'account.analytic.line':
351
if wiz.analytic_axis == 'fp':
352
context.update({'display_fp': True, 'categ': 'FUNDING'})
353
domain.append(('account_id.category', '=', 'FUNDING'))
354
elif wiz.analytic_axis == 'f1':
355
context.update({'categ': 'FREE1'})
356
domain.append(('account_id.category', '=', 'FREE1'))
357
elif wiz.analytic_axis == 'f2':
358
context.update({'categ': 'FREE2'})
359
domain.append(('account_id.category', '=', 'FREE2'))
361
raise osv.except_osv(_('Warning'), _('Display field is mandatory!'))
366
# NB: Amount problem has been resolved as this
367
#+ There is 4 possibilities for amounts:
368
#+ 1/ NO amount given: nothing to do
369
#+ 2/ amount FROM AND amount TO is given
370
#+ 3/ amount FROM is filled in but NOT amount TO
371
#+ 4/ amount TO is filled in but NOT amount FROM
373
#+ For each case, here is what domain should be look like:
374
#+ 1/ FROM is 0.0, TO is 0,0. Domain is []
375
#+ 2/ FROM is 400, TO is 600. Domain is
376
#+ ['|', '&', ('balance', '>=', -600), ('balance', '<=', -400), '&', ('balance', '>=', 400), ('balance', '<=', '600')]
377
#+ 3/ FROM is 400, TO is 0.0. Domain is ['|', ('balance', '<=', -400), ('balance', '>=', 400)]
378
#+ 4/ FROM is 0.0, TO is 600. Domain is ['&', ('balance', '>=', -600), ('balance', '<=', 600)]
380
# prepare tuples that would be processed
381
booking = ('amount_book_from', 'amount_book_to', 'amount_currency')
382
functional = ('amount_func_from', 'amount_func_to', 'balance')
383
for curr in [booking, functional]:
384
# Prepare some values
385
mnt_from = getattr(wiz, curr[0]) or False
386
mnt_to = getattr(wiz, curr[1]) or False
388
# specific behaviour for functional in analytic MCDB
389
if field == 'balance' and res_model == 'account.analytic.line':
391
abs_from = abs(mnt_from)
392
min_from = -1 * abs_from
395
# domain elements initialisation
397
if mnt_from and mnt_to:
398
domain_elements = ['|', '&', (field, '>=', min_to), (field, '<=', min_from), '&', (field, '>=', abs_from), (field, '<=', abs_to)]
400
domain_elements = ['|', (field, '<=', min_from), (field, '>=', abs_from)]
402
domain_elements = ['&', (field, '>=', min_to), (field, '<=', abs_to)]
403
# Add elements to domain which would be use for filtering
404
for el in domain_elements:
406
# Output currency display (with fx_table)
408
context.update({'fx_table_id': wiz.fx_table_id.id, 'currency_table_id': wiz.fx_table_id.id})
409
if wiz.display_in_output_currency:
410
context.update({'output_currency_id': wiz.display_in_output_currency.id})
411
# Return result in a search view
412
view = 'account_move_line_mcdb_search_result'
413
search_view = 'mcdb_view_account_move_line_filter'
414
name = _('Selector - G/L')
415
if res_model == 'account.analytic.line':
416
view = 'account_analytic_line_mcdb_search_result'
417
search_view = 'mcdb_view_account_analytic_line_filter'
418
name = _('Selector - Analytic')
419
view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_mcdb', view)
420
view_id = view_id and view_id[1] or False
421
search_view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_mcdb', search_view)
422
search_view_id = search_view_id and search_view_id[1] or False
424
context['target_filename_prefix'] = name
428
'type': 'ir.actions.act_window',
429
'res_model': res_model,
431
'view_mode': 'tree,form',
432
'view_id': [view_id],
433
'search_view_id': search_view_id,
440
def button_clear(self, cr, uid, ids, field=False, context=None):
442
Delete all fields from this object
447
if isinstance(ids, (int, long)):
453
wiz = self.browse(cr, uid, res_id)
454
res_model = wiz and wiz.model or False
455
if field and field in (self._columns and self._columns.keys()):
456
if self._columns[field]._type == 'many2many':
457
# Don't clear all other fields
459
# Clear this many2many field
460
self.write(cr, uid, ids, {field: [(6,0,[])]}, context=context)
461
# Clear all fields if necessary
463
res_id = self.create(cr, uid, {'model': res_model}, context=context)
469
# Prepare some values
472
if res_model == 'account.move.line':
473
name = _('Selector - G/L')
474
view_name = 'account_mcdb_form'
475
elif res_model == 'account.analytic.line':
476
name = _('Selector - Analytic')
477
view_name = 'account_mcdb_analytic_form'
478
if not view_name or not name:
479
raise osv.except_osv(_('Error'), _('Error: System does not know from where you come from.'))
481
view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_mcdb', view_name)
482
view_id = view_id and view_id[1] or False
485
'type': 'ir.actions.act_window',
486
'res_model': 'account.mcdb',
490
'view_id': [view_id],
495
def _button_add(self, cr, uid, ids, obj=False, field=False, args=None, context=None):
497
Search all elements of an object (obj) regarding criteria (args). Then return wizard and complete given field (field).
498
NB: We consider field is always a MANY2ONE field! (no sense to add all elements of another field...)
505
if isinstance(ids, (int, long)):
507
# Prepare some values
515
# Search all elements
516
element_ids = self.pool.get(obj).search(cr, uid, args)
518
self.write(cr, uid, ids, {field: [(6, 0, element_ids)]})
520
wiz = self.browse(cr, uid, res_id)
521
res_model = wiz and wiz.model or False
522
# Prepare some values
525
if res_model == 'account.move.line':
526
name = _('Selector - G/L')
527
view_name = 'account_mcdb_form'
528
elif res_model == 'account.analytic.line':
529
name = _('Selector - Analytic')
530
view_name = 'account_mcdb_analytic_form'
531
if not view_name or not name:
532
raise osv.except_osv(_('Error'), _('Error: System does not know from where you come from.'))
534
view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account_mcdb', view_name)
535
view_id = view_id and view_id[1] or False
538
'type': 'ir.actions.act_window',
539
'res_model': 'account.mcdb',
543
'view_id': [view_id],
548
def button_journal_clear(self, cr, uid, ids, context=None):
550
Delete journal_ids field content
555
if isinstance(ids, (int, long)):
557
# Return default behaviour with 'journal_ids' field
558
return self.button_clear(cr, uid, ids, field='journal_ids', context=context)
560
def button_journal_add(self, cr, uid, ids, context=None):
562
Add all journals in journal_ids field content
567
if isinstance(ids, (int, long)):
569
# Prepare some values
570
obj = 'account.journal'
572
field = 'journal_ids'
573
return self._button_add(cr, uid, ids, obj, field, args, context=context)
575
def button_period_clear(self, cr, uid, ids, context=None):
577
Delete period_ids field content
582
if isinstance(ids, (int, long)):
584
# Return default behaviour with 'period_ids' field
585
return self.button_clear(cr, uid, ids, field='period_ids', context=context)
587
def button_period_add(self, cr, uid, ids, context=None):
589
Add all periods in period_ids field content
594
if isinstance(ids, (int, long)):
596
# Prepare some values
597
obj = 'account.period'
600
return self._button_add(cr, uid, ids, obj, field, args, context=context)
602
def button_analytic_journal_clear(self, cr, uid, ids, context=None):
604
Delete analytic_journal_ids field content
609
if isinstance(ids, (int, long)):
611
# Return default behaviour with 'analytic_journal_ids' field
612
return self.button_clear(cr, uid, ids, field='analytic_journal_ids', context=context)
614
def button_analytic_journal_add(self, cr, uid, ids, context=None):
616
Add all Analytic journals in analytic_journal_ids field content
621
if isinstance(ids, (int, long)):
623
# Prepare some values
624
obj = 'account.analytic.journal'
626
field = 'analytic_journal_ids'
627
return self._button_add(cr, uid, ids, obj, field, args, context=context)
629
def button_account_clear(self, cr, uid, ids, context=None):
631
Delete account_ids field content
636
if isinstance(ids, (int, long)):
638
# Return default behaviour with 'account_ids' field
639
return self.button_clear(cr, uid, ids, field='account_ids', context=context)
641
def button_account_add(self, cr, uid, ids, context=None):
643
Add all Accounts in account_ids field content
648
if isinstance(ids, (int, long)):
650
# Prepare some values
651
obj = 'account.account'
652
args = [('parent_id', '!=', False)]
653
field = 'account_ids'
654
return self._button_add(cr, uid, ids, obj, field, args, context=context)
656
def button_account_type_clear(self, cr, uid, ids, context=None):
658
Delete account_type_ids field content
663
if isinstance(ids, (int, long)):
665
# Return default behaviour with 'account_type_ids' field
666
return self.button_clear(cr, uid, ids, field='account_type_ids', context=context)
668
def button_account_type_add(self, cr, uid, ids, context=None):
670
Add all Account Type in account_type_ids field content
675
if isinstance(ids, (int, long)):
677
# Prepare some values
678
obj = 'account.account.type'
680
field = 'account_type_ids'
681
return self._button_add(cr, uid, ids, obj, field, args, context=context)
683
def button_funding_pool_clear(self, cr, uid, ids, context=None):
685
Delete analytic_account_fp_ids field content
690
if isinstance(ids, (int, long)):
692
# Return default behaviour with 'analytic_account_fp_ids' field
693
return self.button_clear(cr, uid, ids, field='analytic_account_fp_ids', context=context)
695
def button_funding_pool_add(self, cr, uid, ids, context=None):
697
Add all Funding Pool in analytic_account_fp_ids field content
702
if isinstance(ids, (int, long)):
704
# Prepare some values
705
obj = 'account.analytic.account'
706
args = [('type', '!=', 'view'), ('category', '=', 'FUNDING')]
707
field = 'analytic_account_fp_ids'
708
return self._button_add(cr, uid, ids, obj, field, args, context=context)
710
def button_cost_center_clear(self, cr, uid, ids, context=None):
712
Delete analytic_account_cc_ids field content
717
if isinstance(ids, (int, long)):
719
# Return default behaviour with 'analytic_account_cc_ids' field
720
return self.button_clear(cr, uid, ids, field='analytic_account_cc_ids', context=context)
722
def button_cost_center_add(self, cr, uid, ids, context=None):
724
Add all Cost Center in analytic_account_cc_ids field content
729
if isinstance(ids, (int, long)):
731
# Prepare some values
732
obj = 'account.analytic.account'
733
args = [('type', '!=', 'view'), ('category', '=', 'OC')]
734
field = 'analytic_account_cc_ids'
735
return self._button_add(cr, uid, ids, obj, field, args, context=context)
737
def button_free_1_clear(self, cr, uid, ids, context=None):
739
Delete analytic_account_f1_ids field content
744
if isinstance(ids, (int, long)):
746
# Return default behaviour with 'analytic_account_f1_ids' field
747
return self.button_clear(cr, uid, ids, field='analytic_account_f1_ids', context=context)
749
def button_free_1_add(self, cr, uid, ids, context=None):
751
Add all Free 1 in analytic_account_f1_ids field content
756
if isinstance(ids, (int, long)):
758
# Prepare some values
759
obj = 'account.analytic.account'
760
args = [('type', '!=', 'view'), ('category', '=', 'FREE1')]
761
field = 'analytic_account_f1_ids'
762
return self._button_add(cr, uid, ids, obj, field, args, context=context)
764
def button_free_2_clear(self, cr, uid, ids, context=None):
766
Delete analytic_account_f2_ids field content
771
if isinstance(ids, (int, long)):
773
# Return default behaviour with 'analytic_account_f2_ids' field
774
return self.button_clear(cr, uid, ids, field='analytic_account_f2_ids', context=context)
776
def button_free_2_add(self, cr, uid, ids, context=None):
778
Add all Free 2 in analytic_account_f2_ids field content
783
if isinstance(ids, (int, long)):
785
# Prepare some values
786
obj = 'account.analytic.account'
787
args = [('type', '!=', 'view'), ('category', '=', 'FREE2')]
788
field = 'analytic_account_f2_ids'
789
return self._button_add(cr, uid, ids, obj, field, args, context=context)
791
def button_destination_clear(self, cr, uid, ids, context=None):
793
Delete analytic_account_dest_ids field content
798
if isinstance(ids, (int, long)):
800
# Return default behaviour with 'analytic_account_dest_ids' field
801
return self.button_clear(cr, uid, ids, field='analytic_account_dest_ids', context=context)
803
def button_destination_add(self, cr, uid, ids, context=None):
805
Add all Destination in analytic_account_dest_ids field content
810
if isinstance(ids, (int, long)):
812
# Prepare some values
813
obj = 'account.analytic.account'
814
args = [('type', '!=', 'view'), ('category', '=', 'DEST')]
815
field = 'analytic_account_dest_ids'
816
return self._button_add(cr, uid, ids, obj, field, args, context=context)
818
def button_instance_clear(self, cr, uid, ids, context=None):
820
Delete instance_ids field content
825
if isinstance(ids, (int, long)):
827
# Return default behaviour with 'period_ids' field
828
return self.button_clear(cr, uid, ids, field='instance_ids', context=context)
830
def button_instance_add(self, cr, uid, ids, context=None):
832
Add all instances in instance_ids field content
837
if isinstance(ids, (int, long)):
839
# Prepare some values
842
field = 'instance_ids'
843
return self._button_add(cr, uid, ids, obj, field, args, context=context)
845
def clean_up_search(self, cr, uid, ids, context=None):
847
Clean up objects that have no description.
851
to_clean = self.search(cr, uid, [('description', '=', False)])
852
self.unlink(cr, uid, to_clean)
856
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: