1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
21 from operator import itemgetter
23 from osv import osv, fields
27 class base_setup_company(osv.osv_memory):
30 _name = 'base.setup.company'
31 _inherit = 'res.config'
32 logger = netsvc.Logger()
34 def _get_all(self, cr, uid, model, context=None):
35 models = self.pool.get(model)
36 all_model_ids = models.search(cr, uid, [])
38 output = [(False, '')]
40 sorted([(o.id, o.name)
41 for o in models.browse(cr, uid, all_model_ids,
46 def _get_all_states(self, cr, uid, context=None):
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 def _get_all_currencies(self, cr, uid, context=None):
52 return self._get_all(cr, uid, 'res.currency', context=context)
54 def default_get(self, cr, uid, fields_list=None, context=None):
55 """ get default company if any, and the various other fields
56 from the company's fields
58 defaults = super(base_setup_company, self)\
59 .default_get(cr, uid, fields_list=fields_list, context=context)
61 companies = self.pool.get('res.company')
62 company_id = companies.search(cr, uid, [], limit=1, order="id")
63 if not company_id or 'company_id' not in fields_list:
65 company = companies.browse(cr, uid, company_id[0])
67 defaults['company_id'] = company.id
68 defaults['currency'] = company.currency_id.id
69 for field in ['name','logo','rml_header1','rml_footer1','rml_footer2']:
70 defaults[field] = company[field]
72 if company.partner_id.address:
73 address = company.partner_id.address[0]
74 for field in ['street','street2','zip','city','email','phone']:
75 defaults[field] = address[field]
76 for field in ['country_id','state_id']:
78 defaults[field] = address[field].id
83 'company_id':fields.many2one('res.company', 'Company'),
84 'name':fields.char('Company Name', size=64, required=True),
85 'street':fields.char('Street', size=128),
86 'street2':fields.char('Street 2', size=128),
87 'zip':fields.char('Zip Code', size=24),
88 'city':fields.char('City', size=128),
89 'state_id':fields.selection(_get_all_states, 'States'),
90 'country_id':fields.selection(_get_all_countries, 'Countries'),
91 'email':fields.char('E-mail', size=64),
92 'phone':fields.char('Phone', size=64),
93 'currency':fields.selection(_get_all_currencies, 'Currency', required=True),
94 'rml_header1':fields.char('Report Header', size=200,
95 help='''This sentence will appear at the top right corner of your reports.
96 We suggest you to put a slogan here:
97 "Open Source Business Solutions".'''),
98 'rml_footer1':fields.char('Report Footer 1', size=200,
99 help='''This sentence will appear at the bottom of your reports.
100 We suggest you to write legal sentences here:
101 Web: http://openerp.com - Fax: +32.81.73.35.01 - Fortis Bank: 126-2013269-07'''),
102 'rml_footer2':fields.char('Report Footer 2', size=200,
103 help='''This sentence will appear at the bottom of your reports.
104 We suggest you to put bank information here:
105 IBAN: BE74 1262 0121 6907 - SWIFT: CPDF BE71 - VAT: BE0477.472.701'''),
106 'logo':fields.binary('Logo'),
109 def execute(self, cr, uid, ids, context=None):
110 assert len(ids) == 1, "We should only get one object from the form"
111 payload = self.browse(cr, uid, ids[0], context=context)
112 if not getattr(payload, 'company_id', None):
113 raise ValueError('Case where no default main company is setup '
116 company = payload.company_id
119 'rml_header1':payload.rml_header1,
120 'rml_footer1':payload.rml_footer1,
121 'rml_footer2':payload.rml_footer2,
125 company.partner_id.write({
131 'street':payload.street,
132 'street2':payload.street2,
135 'email':payload.email,
136 'phone':payload.phone,
137 'country_id':int(payload.country_id),
138 'state_id':int(payload.state_id),
141 if company.partner_id.address:
142 company.partner_id.address[0].write(
145 self.pool.get('res.partner.address').create(cr, uid,
147 partner_id=int(company.partner_id)),
152 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: