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 ##############################################################################
27 def _get_default_journal_selection(self, cr, uid, context):
28 pool = pooler.get_pool(cr.dbname)
29 obj = pool.get('account.journal')
30 ids = obj.search(cr, uid, [('type', '=', 'cash')])
31 res = obj.read(cr, uid, ids, ['id', 'name'], context)
32 res = [(r['id'], r['name']) for r in res]
33 res.insert(0, ('', ''))
36 default_journal_form = '''<?xml version="1.0"?>
37 <form string="Select default journals">
38 <field name="default_journal" />
40 <field name="default_journal_rebate" />
42 <field name="default_journal_gift" />
46 default_journal_fields = {
47 'default_journal': {'string': 'Default journal', 'type': 'selection',
48 'selection': _get_default_journal_selection,
50 'default_journal_rebate': {'string': 'Default rebate journal', 'type': 'selection',
51 'selection': _get_default_journal_selection,
53 'default_journal_gift': {'string': 'Default gift journal', 'type': 'selection',
54 'selection': _get_default_journal_selection,
59 class wizard_default_journal(wizard.interface):
61 def _set_default_journal(self, cr, uid, data, context):
63 def _update_default_journal_config(journal_type, journal_code, journal_descr, journal_codes, data):
64 default_journal_id = data.get('form', {}).get(journal_type) or None
65 dico = dict(name=journal_descr, code=journal_code, journal_id=default_journal_id)
66 if default_journal_id:
67 if journal_code in journal_codes:
68 ids = [obj.id for obj in objs if obj.code == journal_code]
69 pos_config_journal.write(cr, uid, ids, dico, context)
71 pos_config_journal.create(cr, uid, dico, context)
73 ids = [obj.id for obj in objs if obj.code == journal_code]
74 pos_config_journal.write(cr, uid, ids, dico, context)
76 pool = pooler.get_pool(cr.dbname)
77 pos_config_journal = pool.get('pos.config.journal')
78 ids = pos_config_journal.search(cr, uid, [])
79 objs = pos_config_journal.browse(cr, uid, ids)
80 journal_codes = [str(obj.code) for obj in objs]
82 _update_default_journal_config('default_journal', 'DEFAULT', 'Default journal', journal_codes, data)
83 _update_default_journal_config('default_journal_rebate', 'REBATE', 'Default rebate journal', journal_codes, data)
84 _update_default_journal_config('default_journal_gift', 'GIFT', 'Default gift journal', journal_codes, data)
88 def _get_defaults(self, cr, uid, data, context):
89 pool = pooler.get_pool(cr.dbname)
90 pos_config_journal = pool.get('pos.config.journal')
91 ids = pos_config_journal.search(cr, uid, [])
92 objs = pos_config_journal.browse(cr, uid, ids)
95 journal_codes[obj.code] = int(obj.journal_id.id)
98 form['default_journal'] = journal_codes.get('DEFAULT') or False
99 form['default_journal_rebate'] = journal_codes.get('REBATE') or False
100 form['default_journal_gift'] = journal_codes.get('GIFT') or False
106 'actions': [_get_defaults],
109 'arch': default_journal_form,
110 'fields': default_journal_fields,
113 ('set_default_journal', 'Define default journals')
117 'set_default_journal': {
118 'actions': [_set_default_journal],
126 wizard_default_journal('pos.config.journal')
128 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: