1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 TeMPO consulting, MSF
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
##############################################################################
23
from osv import fields
25
from tools.translate import _
32
# Class to save all configuration value
33
class unifield_setup_configuration(osv.osv):
34
_name = 'unifield.setup.configuration'
38
Load setup_data.xml before self
40
if hasattr(super(unifield_setup_configuration, self), 'init'):
41
super(unifield_setup_configuration, self).init(cr)
43
mod_obj = self.pool.get('ir.module.module')
44
logging.getLogger('init').info('HOOK: module unifield_setup: loading setup_data.xml')
45
pathname = path.join('unifield_setup', 'setup_data.xml')
46
file = tools.file_open(pathname)
47
tools.convert_xml_import(cr, 'unifield_setup', file, {}, mode='init', noupdate=False)
49
def _check_uniqueness(self, cr, uid, ids, context=None):
51
Limit the creation of one and only one instance configuration
53
setup_ids = self.pool.get('unifield.setup.configuration').search(cr, uid, [], context=context)
54
if len(setup_ids) > 1:
59
def _non_uniqueness_msg(self, cr, uid, ids, context=None):
60
return _('An instance of Unifield setup is already running.')
63
'name': fields.char(size=64, string='Name'),
64
'delivery_process': fields.selection([('simple', 'Simple OUT'), ('complex', 'PICK/PACK/SHIP')], string='Delivery process'),
65
'allocation_setup': fields.selection([('allocated', 'Allocated'),
66
('unallocated', 'Unallocated'),
67
('mixed', 'Mixed')], string='Allocated stocks'),
68
'unallocated_ok': fields.boolean(string='System uses the unallocated stocks ?'),
69
'fixed_asset_ok': fields.boolean(string='System manages fixed asset ?'),
70
'sale_price': fields.float(digits=(16,2), string='Fields price percentage',
71
help='This percentage will be applied on field price from product form view.'),
72
'restrict_country_ids': fields.many2many('res.country', 'restrictive_countries', 'wizard_id', 'country_id',
73
string='Restrictive countries'),
74
'field_orders_ok': fields.boolean(string='Activate the Field Orders feature ?'),
75
'lang_id': fields.char(size=5, string='Default language'),
76
'payroll_ok': fields.boolean(string='System manages payrolls ?'),
77
'import_commitments': fields.boolean(string='Manage commitments corresponding to international order through specific import ?'),
81
'name': lambda *a: 'Unifield setup',
82
'delivery_process': lambda *a: 'complex',
83
'allocation_setup': lambda *a: 'mixed',
84
'sale_price': lambda *a: 0.00,
85
'field_orders_ok': lambda *a: True,
86
'lang_id': lambda *a: False,
87
'unallocated_ok': lambda *a: False,
88
'fixed_asset_ok': lambda *a: False,
89
'payroll_ok': lambda *a: True,
90
'import_commitments': lambda *a: True,
94
(_check_uniqueness, _non_uniqueness_msg, ['id'])
97
def get_config(self, cr, uid):
99
Return the current config or create a new one
101
setup_ids = self.search(cr, uid, [])
103
setup_id = self.create(cr, uid, {})
105
setup_id = setup_ids[0]
108
raise osv.except_osv(_('Error'), _('No configuration found !'))
110
return self.browse(cr, uid, setup_id)
112
def write(self, cr, uid, ids, vals, context=None):
114
On write, update the list_price = Field Price of Product according to the sale_price of the configurator
116
if isinstance(ids, (int, long)):
118
if vals.get('sale_price', 0.0) or vals.get('sale_price') == 0.0:
119
percentage = vals.get('sale_price', 0.0)
120
cr.execute("UPDATE product_template SET list_price = standard_price * %s", ((1 + (percentage/100.00)),))
121
return super(unifield_setup_configuration, self).write(cr, uid, ids, vals, context=context)
124
unifield_setup_configuration()
126
class res_config_view(osv.osv_memory):
127
_name = 'res.config.view'
128
_inherit = 'res.config.view'
136
class res_config(osv.osv_memory):
137
_inherit = 'res.config'
139
def _next(self, cr, uid, context=None):
140
res = super(res_config, self)._next(cr, uid, context=context)
141
if isinstance(res, dict) and res.get('res_model') == 'restrictive.country.setup' and not res.get('res_id'):
142
wiz_id = self.pool.get('restrictive.country.setup').create(cr, uid, {}, context=context)
143
res['res_id'] = wiz_id
144
res['active_id'] = wiz_id
149
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: