1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2012 OpenERP S.A. (<http://openerp.com>).
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 docutils.core import publish_string
30 from openerp import modules, pooler, release, tools, addons
31 from openerp.tools.parse_version import parse_version
32 from openerp.tools.translate import _
33 from openerp.osv import fields, osv, orm
35 _logger = logging.getLogger(__name__)
40 'res_model': 'base.module.upgrade',
42 'type': 'ir.actions.act_window',
46 class module_category(osv.osv):
47 _name = "ir.module.category"
48 _description = "Application"
50 def _module_nbr(self,cr,uid, ids, prop, unknow_none, context):
51 cr.execute('SELECT category_id, COUNT(*) \
52 FROM ir_module_module \
53 WHERE category_id IN %(ids)s \
54 OR category_id IN (SELECT id \
55 FROM ir_module_category \
56 WHERE parent_id IN %(ids)s) \
57 GROUP BY category_id', {'ids': tuple(ids)}
59 result = dict(cr.fetchall())
61 cr.execute('select id from ir_module_category where parent_id=%s', (id,))
62 result[id] = sum([result.get(c, 0) for (c,) in cr.fetchall()],
67 'name': fields.char("Name", size=128, required=True, translate=True, select=True),
68 'parent_id': fields.many2one('ir.module.category', 'Parent Application', select=True),
69 'child_ids': fields.one2many('ir.module.category', 'parent_id', 'Child Applications'),
70 'module_nr': fields.function(_module_nbr, string='Number of Modules', type='integer'),
71 'module_ids' : fields.one2many('ir.module.module', 'category_id', 'Modules'),
72 'description' : fields.text("Description", translate=True),
73 'sequence' : fields.integer('Sequence'),
74 'visible' : fields.boolean('Visible'),
75 'xml_id': fields.function(osv.osv.get_external_id, type='char', size=128, string="External ID"),
83 class module(osv.osv):
84 _name = "ir.module.module"
85 _rec_name = "shortdesc"
86 _description = "Module"
89 def get_module_info(cls, name):
92 info = modules.load_information_from_description_file(name)
93 info['version'] = release.major_version + '.' + info['version']
95 _logger.debug('Error when trying to fetch informations for '
96 'module %s', name, exc_info=True)
99 def _get_desc(self, cr, uid, ids, field_name=None, arg=None, context=None):
100 res = dict.fromkeys(ids, '')
101 for module in self.browse(cr, uid, ids, context=context):
102 overrides = dict(embed_stylesheet=False, doctitle_xform=False, output_encoding='unicode')
103 output = publish_string(source=module.description, writer_name='html', settings_overrides=overrides)
104 res[module.id] = output
107 def _get_latest_version(self, cr, uid, ids, field_name=None, arg=None, context=None):
108 res = dict.fromkeys(ids, '')
109 for m in self.browse(cr, uid, ids):
110 res[m.id] = self.get_module_info(m.name).get('version', '')
113 def _get_views(self, cr, uid, ids, field_name=None, arg=None, context=None):
115 model_data_obj = self.pool.get('ir.model.data')
116 view_obj = self.pool.get('ir.ui.view')
117 report_obj = self.pool.get('ir.actions.report.xml')
118 menu_obj = self.pool.get('ir.ui.menu')
121 if field_name is None or 'views_by_module' in field_name:
122 dmodels.append('ir.ui.view')
123 if field_name is None or 'reports_by_module' in field_name:
124 dmodels.append('ir.actions.report.xml')
125 if field_name is None or 'menus_by_module' in field_name:
126 dmodels.append('ir.ui.menu')
127 assert dmodels, "no models for %s" % field_name
129 for module_rec in self.browse(cr, uid, ids, context=context):
130 res[module_rec.id] = {
131 'menus_by_module': [],
132 'reports_by_module': [],
133 'views_by_module': []
136 # Skip uninstalled modules below, no data to find anyway.
137 if module_rec.state not in ('installed', 'to upgrade', 'to remove'):
140 # then, search and group ir.model.data records
141 imd_models = dict( [(m,[]) for m in dmodels])
142 imd_ids = model_data_obj.search(cr,uid,[('module','=', module_rec.name),
143 ('model','in',tuple(dmodels))])
145 for imd_res in model_data_obj.read(cr, uid, imd_ids, ['model', 'res_id'], context=context):
146 imd_models[imd_res['model']].append(imd_res['res_id'])
148 # For each one of the models, get the names of these ids.
149 # We use try except, because views or menus may not exist.
151 res_mod_dic = res[module_rec.id]
152 view_ids = imd_models.get('ir.ui.view', [])
153 for v in view_obj.browse(cr, uid, view_ids, context=context):
154 aa = v.inherit_id and '* INHERIT ' or ''
155 res_mod_dic['views_by_module'].append(aa + v.name + '('+v.type+')')
157 report_ids = imd_models.get('ir.actions.report.xml', [])
158 for rx in report_obj.browse(cr, uid, report_ids, context=context):
159 res_mod_dic['reports_by_module'].append(rx.name)
161 menu_ids = imd_models.get('ir.ui.menu', [])
162 for um in menu_obj.browse(cr, uid, menu_ids, context=context):
163 res_mod_dic['menus_by_module'].append(um.complete_name)
166 'Data not found for items of %s', module_rec.name)
167 except AttributeError, e:
169 'Data not found for items of %s %s', module_rec.name, str(e))
171 _logger.warning('Unknown error while fetching data of %s',
172 module_rec.name, exc_info=True)
173 for key, _ in res.iteritems():
174 for k, v in res[key].iteritems():
175 res[key][k] = "\n".join(sorted(v))
178 def _get_icon_image(self, cr, uid, ids, field_name=None, arg=None, context=None):
179 res = dict.fromkeys(ids, '')
180 for module in self.browse(cr, uid, ids, context=context):
181 path = addons.get_module_resource(module.name, 'static', 'src', 'img', 'icon.png')
183 image_file = tools.file_open(path, 'rb')
185 res[module.id] = image_file.read().encode('base64')
191 'name': fields.char("Technical Name", size=128, readonly=True, required=True, select=True),
192 'category_id': fields.many2one('ir.module.category', 'Category', readonly=True, select=True),
193 'shortdesc': fields.char('Module Name', size=64, readonly=True, translate=True),
194 'summary': fields.char('Summary', size=64, readonly=True, translate=True),
195 'description': fields.text("Description", readonly=True, translate=True),
196 'description_html': fields.function(_get_desc, string='Description HTML', type='html', method=True, readonly=True),
197 'author': fields.char("Author", size=128, readonly=True),
198 'maintainer': fields.char('Maintainer', size=128, readonly=True),
199 'contributors': fields.text('Contributors', readonly=True),
200 'website': fields.char("Website", size=256, readonly=True),
202 # attention: Incorrect field names !!
203 # installed_version refer the latest version (the one on disk)
204 # latest_version refer the installed version (the one in database)
205 # published_version refer the version available on the repository
206 'installed_version': fields.function(_get_latest_version,
207 string='Latest Version', type='char'),
208 'latest_version': fields.char('Installed Version', size=64, readonly=True),
209 'published_version': fields.char('Published Version', size=64, readonly=True),
211 'url': fields.char('URL', size=128, readonly=True),
212 'sequence': fields.integer('Sequence'),
213 'dependencies_id': fields.one2many('ir.module.module.dependency',
214 'module_id', 'Dependencies', readonly=True),
215 'auto_install': fields.boolean('Automatic Installation',
216 help='An auto-installable module is automatically installed by the '
217 'system when all its dependencies are satisfied. '
218 'If the module has no dependency, it is always installed.'),
219 'state': fields.selection([
220 ('uninstallable','Not Installable'),
221 ('uninstalled','Not Installed'),
222 ('installed','Installed'),
223 ('to upgrade','To be upgraded'),
224 ('to remove','To be removed'),
225 ('to install','To be installed')
226 ], string='State', readonly=True, select=True),
227 'demo': fields.boolean('Demo Data', readonly=True),
228 'license': fields.selection([
229 ('GPL-2', 'GPL Version 2'),
230 ('GPL-2 or any later version', 'GPL-2 or later version'),
231 ('GPL-3', 'GPL Version 3'),
232 ('GPL-3 or any later version', 'GPL-3 or later version'),
233 ('AGPL-3', 'Affero GPL-3'),
234 ('Other OSI approved licence', 'Other OSI Approved Licence'),
235 ('Other proprietary', 'Other Proprietary')
236 ], string='License', readonly=True),
237 'menus_by_module': fields.function(_get_views, string='Menus', type='text', multi="meta", store=True),
238 'reports_by_module': fields.function(_get_views, string='Reports', type='text', multi="meta", store=True),
239 'views_by_module': fields.function(_get_views, string='Views', type='text', multi="meta", store=True),
240 'certificate' : fields.char('Quality Certificate', size=64, readonly=True),
241 'application': fields.boolean('Application', readonly=True),
242 'icon': fields.char('Icon URL', size=128),
243 'icon_image': fields.function(_get_icon_image, string='Icon', type="binary"),
247 'state': 'uninstalled',
252 _order = 'sequence,name'
254 def _name_uniq_msg(self, cr, uid, ids, context=None):
255 return _('The name of the module must be unique !')
256 def _certificate_uniq_msg(self, cr, uid, ids, context=None):
257 return _('The certificate ID of the module must be unique !')
260 ('name_uniq', 'UNIQUE (name)',_name_uniq_msg ),
261 ('certificate_uniq', 'UNIQUE (certificate)',_certificate_uniq_msg )
264 def unlink(self, cr, uid, ids, context=None):
267 if isinstance(ids, (int, long)):
270 for mod in self.read(cr, uid, ids, ['state','name'], context):
271 if mod['state'] in ('installed', 'to upgrade', 'to remove', 'to install'):
272 raise orm.except_orm(_('Error'),
273 _('You try to remove a module that is installed or will be installed'))
274 mod_names.append(mod['name'])
275 #Removing the entry from ir_model_data
276 #ids_meta = self.pool.get('ir.model.data').search(cr, uid, [('name', '=', 'module_meta_information'), ('module', 'in', mod_names)])
279 # self.pool.get('ir.model.data').unlink(cr, uid, ids_meta, context)
281 return super(module, self).unlink(cr, uid, ids, context=context)
284 def _check_external_dependencies(terp):
285 depends = terp.get('external_dependencies')
288 for pydep in depends.get('python', []):
289 parts = pydep.split('.')
295 _, path, _ = imp.find_module(part, path and [path] or None)
297 raise ImportError('No module named %s' % (pydep,))
299 for binary in depends.get('bin', []):
300 if tools.find_in_path(binary) is None:
301 raise Exception('Unable to find %r in path' % (binary,))
304 def check_external_dependencies(cls, module_name, newstate='to install'):
305 terp = cls.get_module_info(module_name)
307 cls._check_external_dependencies(terp)
309 if newstate == 'to install':
310 msg = _('Unable to install module "%s" because an external dependency is not met: %s')
311 elif newstate == 'to upgrade':
312 msg = _('Unable to upgrade module "%s" because an external dependency is not met: %s')
314 msg = _('Unable to process module "%s" because an external dependency is not met: %s')
315 raise orm.except_orm(_('Error'), msg % (module_name, e.args[0]))
317 def state_update(self, cr, uid, ids, newstate, states_to_update, context=None, level=100):
319 raise orm.except_orm(_('Error'), _('Recursion error in modules dependencies !'))
321 for module in self.browse(cr, uid, ids, context=context):
323 for dep in module.dependencies_id:
324 if dep.state == 'unknown':
325 raise orm.except_orm(_('Error'), _("You try to install module '%s' that depends on module '%s'.\nBut the latter module is not available in your system.") % (module.name, dep.name,))
326 ids2 = self.search(cr, uid, [('name','=',dep.name)])
327 if dep.state != newstate:
328 mdemo = self.state_update(cr, uid, ids2, newstate, states_to_update, context, level-1,) or mdemo
330 od = self.browse(cr, uid, ids2)[0]
331 mdemo = od.demo or mdemo
333 self.check_external_dependencies(module.name, newstate)
334 if not module.dependencies_id:
336 if module.state in states_to_update:
337 self.write(cr, uid, [module.id], {'state': newstate, 'demo':mdemo})
341 def button_install(self, cr, uid, ids, context=None):
343 # Mark the given modules to be installed.
344 self.state_update(cr, uid, ids, 'to install', ['uninstalled'], context)
346 # Mark (recursively) the newly satisfied modules to also be installed:
348 # Select all auto-installable (but not yet installed) modules.
349 domain = [('state', '=', 'uninstalled'), ('auto_install', '=', True),]
350 uninstalled_ids = self.search(cr, uid, domain, context=context)
351 uninstalled_modules = self.browse(cr, uid, uninstalled_ids, context=context)
353 # Keep those with all their dependencies satisfied.
354 def all_depencies_satisfied(m):
355 return all(x.state in ('to install', 'installed', 'to upgrade') for x in m.dependencies_id)
356 to_install_modules = filter(all_depencies_satisfied, uninstalled_modules)
357 to_install_ids = map(lambda m: m.id, to_install_modules)
359 # Mark them to be installed.
361 self.button_install(cr, uid, to_install_ids, context=context)
362 return dict(ACTION_DICT, name=_('Install'))
364 def button_immediate_install(self, cr, uid, ids, context=None):
365 """ Installs the selected module(s) immediately and fully,
366 returns the next res.config action to execute
368 :param ids: identifiers of the modules to install
369 :returns: next res.config item to execute
370 :rtype: dict[str, object]
372 return self._button_immediate_function(cr, uid, ids, self.button_install, context=context)
374 def button_install_cancel(self, cr, uid, ids, context=None):
375 self.write(cr, uid, ids, {'state': 'uninstalled', 'demo':False})
378 def module_uninstall(self, cr, uid, ids, context=None):
379 """Perform the various steps required to uninstall a module completely
380 including the deletion of all database structures created by the module:
381 tables, columns, constraints, etc."""
382 ir_model_data = self.pool.get('ir.model.data')
383 ir_model_constraint = self.pool.get('ir.model.constraint')
384 modules_to_remove = [m.name for m in self.browse(cr, uid, ids, context)]
385 modules_to_remove_ids = [m.id for m in self.browse(cr, uid, ids, context)]
386 constraint_ids = ir_model_constraint.search(cr, uid, [('module', 'in', modules_to_remove_ids)])
387 ir_model_constraint._module_data_uninstall(cr, uid, constraint_ids, context)
388 ir_model_data._module_data_uninstall(cr, uid, modules_to_remove, context)
389 self.write(cr, uid, ids, {'state': 'uninstalled'})
392 def downstream_dependencies(self, cr, uid, ids, known_dep_ids=None,
393 exclude_states=['uninstalled','uninstallable','to remove'],
395 """Return the ids of all modules that directly or indirectly depend
396 on the given module `ids`, and that satisfy the `exclude_states`
398 if not ids: return []
399 known_dep_ids = set(known_dep_ids or [])
400 cr.execute('''SELECT DISTINCT m.id
402 ir_module_module_dependency d
404 ir_module_module m ON (d.module_id=m.id)
406 d.name IN (SELECT name from ir_module_module where id in %s) AND
407 m.state NOT IN %s AND
409 (tuple(ids),tuple(exclude_states), tuple(known_dep_ids or ids)))
410 new_dep_ids = set([m[0] for m in cr.fetchall()])
411 missing_mod_ids = new_dep_ids - known_dep_ids
412 known_dep_ids |= new_dep_ids
414 known_dep_ids |= set(self.downstream_dependencies(cr, uid, list(missing_mod_ids),
415 known_dep_ids, exclude_states,context))
416 return list(known_dep_ids)
418 def _button_immediate_function(self, cr, uid, ids, function, context=None):
419 function(cr, uid, ids, context=context)
422 _, pool = pooler.restart_pool(cr.dbname, update_module=True)
424 config = pool.get('res.config').next(cr, uid, [], context=context) or {}
425 if config.get('type') not in ('ir.actions.reload', 'ir.actions.act_window_close'):
428 # reload the client; open the first available root menu
429 menu_obj = self.pool.get('ir.ui.menu')
430 menu_ids = menu_obj.search(cr, uid, [('parent_id', '=', False)], context=context)
433 'type' : 'ir.actions.client',
435 'params' : {'menu_id' : menu_ids and menu_ids[0] or False}
438 def button_immediate_uninstall(self, cr, uid, ids, context=None):
440 Uninstall the selected module(s) immediately and fully,
441 returns the next res.config action to execute
443 return self._button_immediate_function(cr, uid, ids, self.button_uninstall, context=context)
445 def button_uninstall(self, cr, uid, ids, context=None):
446 if any(m.name == 'base' for m in self.browse(cr, uid, ids, context=context)):
447 raise orm.except_orm(_('Error'), _("The `base` module cannot be uninstalled"))
448 dep_ids = self.downstream_dependencies(cr, uid, ids, context=context)
449 self.write(cr, uid, ids + dep_ids, {'state': 'to remove'})
450 return dict(ACTION_DICT, name=_('Uninstall'))
452 def button_uninstall_cancel(self, cr, uid, ids, context=None):
453 self.write(cr, uid, ids, {'state': 'installed'})
456 def button_immediate_upgrade(self, cr, uid, ids, context=None):
458 Upgrade the selected module(s) immediately and fully,
459 return the next res.config action to execute
461 return self._button_immediate_function(cr, uid, ids, self.button_upgrade, context=context)
463 def button_upgrade(self, cr, uid, ids, context=None):
464 depobj = self.pool.get('ir.module.module.dependency')
465 todo = self.browse(cr, uid, ids, context=context)
466 self.update_list(cr, uid)
472 if mod.state not in ('installed','to upgrade'):
473 raise orm.except_orm(_('Error'),
474 _("Can not upgrade module '%s'. It is not installed.") % (mod.name,))
475 self.check_external_dependencies(mod.name, 'to upgrade')
476 iids = depobj.search(cr, uid, [('name', '=', mod.name)], context=context)
477 for dep in depobj.browse(cr, uid, iids, context=context):
478 if dep.module_id.state=='installed' and dep.module_id not in todo:
479 todo.append(dep.module_id)
481 ids = map(lambda x: x.id, todo)
482 self.write(cr, uid, ids, {'state':'to upgrade'}, context=context)
486 for dep in mod.dependencies_id:
487 if dep.state == 'unknown':
488 raise orm.except_orm(_('Error'), _('You try to upgrade a module that depends on the module: %s.\nBut this module is not available in your system.') % (dep.name,))
489 if dep.state == 'uninstalled':
490 ids2 = self.search(cr, uid, [('name','=',dep.name)])
491 to_install.extend(ids2)
493 self.button_install(cr, uid, to_install, context=context)
494 return dict(ACTION_DICT, name=_('Apply Schedule Upgrade'))
496 def button_upgrade_cancel(self, cr, uid, ids, context=None):
497 self.write(cr, uid, ids, {'state': 'installed'})
500 def button_update_translations(self, cr, uid, ids, context=None):
501 self.update_translations(cr, uid, ids)
505 def get_values_from_terp(terp):
507 'description': terp.get('description', ''),
508 'shortdesc': terp.get('name', ''),
509 'author': terp.get('author', 'Unknown'),
510 'maintainer': terp.get('maintainer', False),
511 'contributors': ', '.join(terp.get('contributors', [])) or False,
512 'website': terp.get('website', ''),
513 'license': terp.get('license', 'AGPL-3'),
514 'certificate': terp.get('certificate') or False,
515 'sequence': terp.get('sequence', 100),
516 'application': terp.get('application', False),
517 'auto_install': terp.get('auto_install', False),
518 'icon': terp.get('icon', False),
519 'summary': terp.get('summary', ''),
522 # update the list of available packages
523 def update_list(self, cr, uid, context=None):
524 res = [0, 0] # [update, add]
526 known_mods = self.browse(cr, uid, self.search(cr, uid, []))
527 known_mods_names = dict([(m.name, m) for m in known_mods])
529 # iterate through detected modules and update/create them in db
530 for mod_name in modules.get_modules():
531 mod = known_mods_names.get(mod_name)
532 terp = self.get_module_info(mod_name)
533 values = self.get_values_from_terp(terp)
538 old = getattr(mod, key)
539 updated = isinstance(values[key], basestring) and tools.ustr(values[key]) or values[key]
540 if not old == updated:
541 updated_values[key] = values[key]
542 if terp.get('installable', True) and mod.state == 'uninstallable':
543 updated_values['state'] = 'uninstalled'
544 if parse_version(terp.get('version', '')) > parse_version(mod.latest_version or ''):
547 self.write(cr, uid, mod.id, updated_values)
549 mod_path = modules.get_module_path(mod_name)
552 if not terp or not terp.get('installable', True):
554 id = self.create(cr, uid, dict(name=mod_name, state='uninstalled', **values))
555 mod = self.browse(cr, uid, id)
558 self._update_dependencies(cr, uid, mod, terp.get('depends', []))
559 self._update_category(cr, uid, mod, terp.get('category', 'Uncategorized'))
563 def download(self, cr, uid, ids, download=True, context=None):
565 for mod in self.browse(cr, uid, ids, context=context):
568 match = re.search('-([a-zA-Z0-9\._-]+)(\.zip)', mod.url, re.I)
571 version = match.group(1)
572 if parse_version(mod.installed_version or '0') >= parse_version(version):
577 zip_content = urllib.urlopen(mod.url).read()
578 fname = modules.get_module_path(str(mod.name)+'.zip', downloaded=True)
580 with open(fname, 'wb') as fp:
581 fp.write(zip_content)
583 _logger.exception('Error when trying to create module '
585 raise orm.except_orm(_('Error'), _('Can not create the module file:\n %s') % (fname,))
586 terp = self.get_module_info(mod.name)
587 self.write(cr, uid, mod.id, self.get_values_from_terp(terp))
588 cr.execute('DELETE FROM ir_module_module_dependency ' \
589 'WHERE module_id = %s', (mod.id,))
590 self._update_dependencies(cr, uid, mod, terp.get('depends',
592 self._update_category(cr, uid, mod, terp.get('category',
595 zimp = zipimport.zipimporter(fname)
596 zimp.load_module(mod.name)
599 def _update_dependencies(self, cr, uid, mod_browse, depends=None):
602 existing = set(x.name for x in mod_browse.dependencies_id)
603 needed = set(depends)
604 for dep in (needed - existing):
605 cr.execute('INSERT INTO ir_module_module_dependency (module_id, name) values (%s, %s)', (mod_browse.id, dep))
606 for dep in (existing - needed):
607 cr.execute('DELETE FROM ir_module_module_dependency WHERE module_id = %s and name = %s', (mod_browse.id, dep))
609 def _update_category(self, cr, uid, mod_browse, category='Uncategorized'):
610 current_category = mod_browse.category_id
611 current_category_path = []
612 while current_category:
613 current_category_path.insert(0, current_category.name)
614 current_category = current_category.parent_id
616 categs = category.split('/')
617 if categs != current_category_path:
621 cr.execute('SELECT id FROM ir_module_category WHERE name=%s AND parent_id=%s', (categs[0], p_id))
623 cr.execute('SELECT id FROM ir_module_category WHERE name=%s AND parent_id is NULL', (categs[0],))
626 cr.execute('INSERT INTO ir_module_category (name, parent_id) VALUES (%s, %s) RETURNING id', (categs[0], p_id))
627 c_id = cr.fetchone()[0]
632 self.write(cr, uid, [mod_browse.id], {'category_id': p_id})
634 def update_translations(self, cr, uid, ids, filter_lang=None, context=None):
638 pool = pooler.get_pool(cr.dbname)
639 lang_obj = pool.get('res.lang')
640 lang_ids = lang_obj.search(cr, uid, [('translatable', '=', True)])
641 filter_lang = [lang.code for lang in lang_obj.browse(cr, uid, lang_ids)]
642 elif not isinstance(filter_lang, (list, tuple)):
643 filter_lang = [filter_lang]
645 for mod in self.browse(cr, uid, ids):
646 if mod.state != 'installed':
648 modpath = modules.get_module_path(mod.name)
650 # unable to find the module. we skip
652 for lang in filter_lang:
653 iso_lang = tools.get_iso_codes(lang)
654 f = modules.get_module_resource(mod.name, 'i18n', iso_lang + '.po')
655 context2 = context and context.copy() or {}
656 if f and '_' in iso_lang:
657 iso_lang2 = iso_lang.split('_')[0]
658 f2 = modules.get_module_resource(mod.name, 'i18n', iso_lang2 + '.po')
660 _logger.info('module %s: loading base translation file %s for language %s', mod.name, iso_lang2, lang)
661 tools.trans_load(cr, f2, lang, verbose=False, context=context)
662 context2['overwrite'] = True
663 # Implementation notice: we must first search for the full name of
664 # the language derivative, like "en_UK", and then the generic,
666 if (not f) and '_' in iso_lang:
667 iso_lang = iso_lang.split('_')[0]
668 f = modules.get_module_resource(mod.name, 'i18n', iso_lang + '.po')
670 _logger.info('module %s: loading translation file (%s) for language %s', mod.name, iso_lang, lang)
671 tools.trans_load(cr, f, lang, verbose=False, context=context2)
672 elif iso_lang != 'en':
673 _logger.warning('module %s: no translation for language %s', mod.name, iso_lang)
675 def check(self, cr, uid, ids, context=None):
676 for mod in self.browse(cr, uid, ids, context=context):
677 if not mod.description:
678 _logger.warning('module %s: description is empty !', mod.name)
680 if not mod.certificate or not mod.certificate.isdigit():
681 _logger.info('module %s: no quality certificate', mod.name)
683 val = long(mod.certificate[2:]) % 97 == 29
685 _logger.critical('module %s: invalid quality certificate: %s', mod.name, mod.certificate)
686 raise osv.except_osv(_('Error'), _('Module %s: Invalid Quality Certificate') % (mod.name,))
688 class module_dependency(osv.osv):
689 _name = "ir.module.module.dependency"
690 _description = "Module dependency"
692 def _state(self, cr, uid, ids, name, args, context=None):
694 mod_obj = self.pool.get('ir.module.module')
695 for md in self.browse(cr, uid, ids):
696 ids = mod_obj.search(cr, uid, [('name', '=', md.name)])
698 result[md.id] = mod_obj.read(cr, uid, [ids[0]], ['state'])[0]['state']
700 result[md.id] = 'unknown'
704 # The dependency name
705 'name': fields.char('Name', size=128, select=True),
707 # The module that depends on it
708 'module_id': fields.many2one('ir.module.module', 'Module', select=True, ondelete='cascade'),
710 'state': fields.function(_state, type='selection', selection=[
711 ('uninstallable','Uninstallable'),
712 ('uninstalled','Not Installed'),
713 ('installed','Installed'),
714 ('to upgrade','To be upgraded'),
715 ('to remove','To be removed'),
716 ('to install','To be installed'),
717 ('unknown', 'Unknown'),
718 ], string='State', readonly=True, select=True),
721 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: