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 ?'),
80
'name': lambda *a: 'Unifield setup',
81
'delivery_process': lambda *a: 'complex',
82
'allocation_setup': lambda *a: 'mixed',
83
'sale_price': lambda *a: 0.00,
84
'field_orders_ok': lambda *a: True,
85
'lang_id': lambda *a: 'en_MF',
86
'unallocated_ok': lambda *a: False,
87
'fixed_asset_ok': lambda *a: False,
88
'payroll_ok': lambda *a: True,
92
(_check_uniqueness, _non_uniqueness_msg, ['id'])
95
def get_config(self, cr, uid):
97
Return the current config or create a new one
99
setup_ids = self.search(cr, uid, [])
101
setup_id = self.create(cr, uid, {})
103
setup_id = setup_ids[0]
106
raise osv.except_osv(_('Error'), _('No configuration found !'))
108
return self.browse(cr, uid, setup_id)
110
def write(self, cr, uid, ids, vals, context=None):
112
On write, update the list_price = Field Price of Product according to the sale_price of the configurator
114
if isinstance(ids, (int, long)):
116
if vals.get('sale_price', 0.0) or vals.get('sale_price') == 0.0:
117
percentage = vals.get('sale_price', 0.0)
118
cr.execute("UPDATE product_template SET list_price = standard_price * %s", ((1 + (percentage/100.00)),))
119
return super(unifield_setup_configuration, self).write(cr, uid, ids, vals, context=context)
122
unifield_setup_configuration()
124
class res_config_view(osv.osv_memory):
125
_name = 'res.config.view'
126
_inherit = 'res.config.view'
134
class res_config(osv.osv_memory):
135
_inherit = 'res.config'
137
def _next(self, cr, uid, context=None):
138
res = super(res_config, self)._next(cr, uid, context=context)
139
if isinstance(res, dict) and res.get('res_model') == 'restrictive.country.setup' and not res.get('res_id'):
140
wiz_id = self.pool.get('restrictive.country.setup').create(cr, uid, {}, context=context)
141
res['res_id'] = wiz_id
142
res['active_id'] = wiz_id
147
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: