[add] base transformation of main company setup from base_setup wizard to in-memory res.config

bzr revid: xmo@tinyerp.com-20100121121311-wi8j7g9q5xu2ptzm
This commit is contained in:
Xavier Morel 2010-01-21 13:13:11 +01:00
parent 77818d1c02
commit 132e65a01c
5 changed files with 178 additions and 4 deletions

View File

@ -20,6 +20,7 @@
##############################################################################
import installer
import todo
import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -43,7 +43,8 @@
'init_xml': ['base_setup_data.xml'],
'update_xml': ['security/ir.model.access.csv',
'base_setup_wizard.xml',
'base_setup_installer.xml'],
'base_setup_installer.xml',
'base_setup_todo.xml',],
'demo_xml': ['base_setup_demo.xml'],
'installable': True,
'active': True,

View File

@ -1,17 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="action_wizard_setup" model="ir.actions.wizard">
<field name="name">Setup</field>
<field name="type">ir.actions.wizard</field>
<field name="wiz_name">base_setup.base_setup</field>
</record>
<record id="base.user_root" model="res.users">
<field name="action_id" ref="action_wizard_setup"/>
<field name="menu_id" ref="action_wizard_setup"/>
</record>
</data>
</openerp>

View File

@ -0,0 +1,62 @@
<openerp>
<data>
<record id="view_base_setup_company" model="ir.ui.view">
<field name="name">Setup company information</field>
<field name="model">base.setup.company</field>
<field name="type">form</field>
<field name="inherit_id" ref="base.res_config_view_base"/>
<field name="arch" type="xml">
<data>
<form position="attributes">
<attribute name="string">Main Company Setup</attribute>
</form>
<group string="res_config_contents" position="replace">
<image name="gtk-dialog-info"/>
<field name="company_id" invisible="1"/>
<separator string="Define Main Company" colspan="4"/>
<field name="name" colspan="4" required="True"/>
<newline/>
<field name="street"/>
<field name="street2"/>
<field name="zip"/>
<field name="city"/>
<field name="country_id"/>
<field name="state_id"/>
<field name="email"/>
<field name="phone"/>
<field name="currency"/>
<separator string="Report Information" colspan="4"/>
<field name="rml_header1" colspan="4"/>
<field name="rml_footer1" colspan="4"/>
<field name="rml_footer2" colspan="4"/>
<separator colspan="4"
string="Your Logo - Use a size of about 450x150 pixels."/>
<field colspan="4" name="logo" widget="image"
nolabel="True"/>
</group>
<xpath expr='//button[@name="action_skip"]' position='replace'/>
</data>
</field>
</record>
<record id="action_base_setup_company" model="ir.actions.act_window">
<field name="name">Setup company information</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">base.setup.company</field>
<field name="view_id" ref="view_base_setup_company"/>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="targer">new</field>
</record>
<record id="base_setup_company_todo" model="ir.actions.todo">
<field name="action_id" ref="action_base_setup_company"/>
<field name="sequence">1</field>
</record>
</data>
</openerp>

111
addons/base_setup/todo.py Normal file
View File

@ -0,0 +1,111 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from operator import itemgetter
from osv import osv, fields
import netsvc
import tools
class base_setup_company(osv.osv_memory):
"""
"""
_name = 'base.setup.company'
_inherit = 'res.config'
logger = netsvc.Logger()
def _get_all(self, cr, uid, model, context=None):
models = self.pool.get(model)
all_model_ids = models.search(cr, uid, [])
output = [(-1, None)]
output.extend(
sorted([(o.id, o.name)
for o in models.browse(cr, uid, all_model_ids,
context=context)],
key=itemgetter(1)))
return output
def _get_all_states(self, cr, uid, context=None):
return self._get_all(
cr, uid, 'res.country.state', context=context)
def _get_all_countries(self, cr, uid, context=None):
return self._get_all(cr, uid, 'res.country', context=context)
def _get_all_currencies(self, cr, uid, context=None):
return self._get_all(cr, uid, 'res.currency', context=context)
def default_get(self, cr, uid, fields_list=None, context=None):
""" get default company if any, and the various other fields
from the company's fields
"""
defaults = super(base_setup_company, self)\
.default_get(cr, uid, fields_list=fields_list, context=context)
companies = self.pool.get('res.company')
company_id = companies.search(cr, uid, [], limit=1, order="id")
if not company_id or 'company_id' in defaults: return defaults
company = companies.browse(cr, uid, company_id[0])
defaults['company_id'] = company.id
defaults['currency'] = company.currency_id.id
for field in ['name','logo','rml_header1','rml_footer1','rml_footer2']:
defaults[field] = company[field]
if company.partner_id.address:
address = company.partner_id.address[0]
for field in ['street','street2','zip','city','email','phone']:
defaults[field] = address[field]
for field in ['country_id','state_id']:
if address[field]:
defaults[field] = address[field].id
return defaults
_columns = {
'company_id':fields.many2one('res.company', 'Company'),
'name':fields.char('Company Name', size=64, required=True),
'street':fields.char('Street', size=128),
'street2':fields.char('Street 2', size=128),
'zip':fields.char('Zip Code', size=24),
'city':fields.char('City', size=128),
'state_id':fields.selection(_get_all_states, 'States'),
'country_id':fields.selection(_get_all_countries, 'Countries'),
'email':fields.char('E-mail', size=64),
'phone':fields.char('Phone', size=64),
'currency':fields.selection(_get_all_currencies, 'Currency', required=True),
'rml_header1':fields.char('Report Header', size=200,
help='''This sentence will appear at the top right corner of your reports.
We suggest you to put a slogan here:
"Open Source Business Solutions".'''),
'rml_footer1':fields.char('Report Footer 1', size=200,
help='''This sentence will appear at the bottom of your reports.
We suggest you to write legal sentences here:
Web: http://openerp.com - Fax: +32.81.73.35.01 - Fortis Bank: 126-2013269-07'''),
'rml_footer2':fields.char('Report Footer 2', size=200,
help='''This sentence will appear at the bottom of your reports.
We suggest you to put bank information here:
IBAN: BE74 1262 0121 6907 - SWIFT: CPDF BE71 - VAT: BE0477.472.701'''),
'logo':fields.binary('Logo'),
}
base_setup_company()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: