[IMP]: base_setup: Removed logo field from company setup wizard as we have a new...
[odoo/odoo.git] / addons / base_setup / todo.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
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/>.
19 #
20 ##############################################################################
21 from operator import itemgetter
22
23 from osv import osv, fields
24 import netsvc
25 import tools
26
27 class base_setup_company(osv.osv_memory):
28     """
29     """
30     _name = 'base.setup.company'
31     _inherit = 'res.config'
32     logger = netsvc.Logger()
33
34     def _get_all(self, cr, uid, model, context=None):
35         models = self.pool.get(model)
36         all_model_ids = models.search(cr, uid, [])
37
38         output = [(False, '')]
39         output.extend(
40             sorted([(o.id, o.name)
41                     for o in models.browse(cr, uid, all_model_ids,
42                                            context=context)],
43                    key=itemgetter(1)))
44         return output
45
46     def _get_all_states(self, cr, uid, context=None):
47         return self._get_all(
48             cr, uid, 'res.country.state', context=context)
49     def _get_all_countries(self, cr, uid, context=None):
50         return self._get_all(cr, uid, 'res.country', context=context)
51
52     def _show_company_data(self, cr, uid, context=None):
53         # We only want to show the default company data in demo mode, otherwise users tend to forget
54         # to fill in the real company data in their production databases
55         return self.pool.get('ir.model.data').get_object(cr, uid, 'base', 'module_meta_information').demo
56
57
58     def default_get(self, cr, uid, fields_list=None, context=None):
59         """ get default company if any, and the various other fields
60         from the company's fields
61         """
62         defaults = super(base_setup_company, self)\
63               .default_get(cr, uid, fields_list=fields_list, context=context)
64         companies = self.pool.get('res.company')
65         company_id = companies.search(cr, uid, [], limit=1, order="id")
66         if not company_id or 'company_id' not in fields_list:
67             return defaults
68         company = companies.browse(cr, uid, company_id[0], context=context)
69         defaults['company_id'] = company.id
70
71         if not self._show_company_data(cr, uid, context=context):
72             return defaults
73
74         defaults['currency'] = company.currency_id.id
75         for field in ['name','rml_header1','rml_footer1','rml_footer2']:
76             defaults[field] = company[field]
77
78         if company.partner_id.address:
79             address = company.partner_id.address[0]
80             for field in ['street','street2','zip','city','email','phone']:
81                 defaults[field] = address[field]
82             for field in ['country_id','state_id']:
83                 if address[field]:
84                     defaults[field] = address[field].id
85
86         return defaults
87
88     _columns = {
89         'company_id':fields.many2one('res.company', 'Company'),
90         'name':fields.char('Company Name', size=64, required=True),
91         'street':fields.char('Street', size=128),
92         'street2':fields.char('Street 2', size=128),
93         'zip':fields.char('Zip Code', size=24),
94         'city':fields.char('City', size=128),
95         'state_id':fields.selection(_get_all_states, 'Fed. State'),
96         'country_id':fields.selection(_get_all_countries, 'Country'),
97         'email':fields.char('E-mail', size=64),
98         'phone':fields.char('Phone', size=64),
99         'currency':fields.many2one('res.currency', 'Currency', required=True),
100         'rml_header1':fields.char('Report Header', size=200,
101             help='''This sentence will appear at the top right corner of your reports.
102 We suggest you to put a slogan here:
103 "Open Source Business Solutions".'''),
104         'rml_footer1':fields.char('Report Footer 1', size=200,
105             help='''This sentence will appear at the bottom of your reports.
106 We suggest you to write legal sentences here:
107 Web: http://openerp.com - Fax: +32.81.73.35.01 - Fortis Bank: 126-2013269-07'''),
108         'rml_footer2':fields.char('Report Footer 2', size=200,
109             help='''This sentence will appear at the bottom of your reports.
110 We suggest you to put bank information here:
111 IBAN: BE74 1262 0121 6907 - SWIFT: CPDF BE71 - VAT: BE0477.472.701'''),
112         'account_no':fields.char('Bank Account No', size=64),
113         'website': fields.char('Company Website', size=64, help="Example: http://openerp.com"),
114     }
115
116     def execute(self, cr, uid, ids, context=None):
117         assert len(ids) == 1, "We should only get one object from the form"
118         payload = self.browse(cr, uid, ids[0], context=context)
119         if not getattr(payload, 'company_id', None):
120             raise ValueError('Case where no default main company is setup '
121                              'not handled yet')
122         company = payload.company_id
123         company.write({
124             'name':payload.name,
125             'rml_header1':payload.rml_header1,
126             'rml_footer1':payload.rml_footer1,
127             'rml_footer2':payload.rml_footer2,
128             'currency_id':payload.currency.id,
129             'account_no':payload.account_no,
130         })
131
132         company.partner_id.write({
133             'name':payload.name,
134             'website':payload.website,
135         })
136
137         address_data = {
138             'name':payload.name,
139             'street':payload.street,
140             'street2':payload.street2,
141             'zip':payload.zip,
142             'city':payload.city,
143             'email':payload.email,
144             'phone':payload.phone,
145             'country_id':int(payload.country_id),
146             'state_id':int(payload.state_id),
147         }
148
149         if company.partner_id.address:
150             company.partner_id.address[0].write(
151                 address_data)
152         else:
153             self.pool.get('res.partner.address').create(cr, uid,
154                     dict(address_data,
155                          partner_id=int(company.partner_id)),
156                     context=context)
157 base_setup_company()
158
159 class res_currency(osv.osv):
160     _inherit = 'res.currency'
161
162     def name_get(self, cr, uid, ids, context=None):
163         if context is None:
164             context = {}
165 #        We can use the following line,if we want to restrict this name_get for company setup only
166 #        But, its better to show currencies as name(Code).
167         if not len(ids):
168             return []
169         if isinstance(ids, (int, long)):
170             ids = [ids]
171         reads = self.read(cr, uid, ids, ['name','symbol'], context, load='_classic_write')
172         return [(x['id'], tools.ustr(x['name']) + (x['symbol'] and (' (' + tools.ustr(x['symbol']) + ')') or '')) for x in reads]
173
174 res_currency()
175
176 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: