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