[MERGE] from upstream
bzr revid: fva@openerp.com-20121228122804-c4t1z7x0zy2nyif0
This commit is contained in:
+20
-13
@@ -1,14 +1,21 @@
|
||||
.*
|
||||
*.egg-info
|
||||
*.orig
|
||||
*.vim
|
||||
.*.swp
|
||||
.bzrignore
|
||||
.idea
|
||||
.project
|
||||
.pydevproject
|
||||
.ropeproject
|
||||
.settings
|
||||
.DS_Store
|
||||
openerp/addons/*
|
||||
openerp/filestore*
|
||||
.Python
|
||||
*.pyc
|
||||
*.pyo
|
||||
bin/*
|
||||
build/
|
||||
RE:^bin/
|
||||
RE:^dist/
|
||||
RE:^include/
|
||||
|
||||
RE:^share/
|
||||
RE:^man/
|
||||
RE:^lib/
|
||||
|
||||
RE:^addons/\w+/doc/_build/
|
||||
include/
|
||||
lib/
|
||||
share/
|
||||
doc/_build/*
|
||||
win32/*.bat
|
||||
win32/meta.py
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
# Copyright (C) 2010, 2012 OpenERP s.a. (<http://openerp.com>).
|
||||
# Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
@@ -80,6 +80,7 @@ The kernel of OpenERP, needed for all installation.
|
||||
'res/res_bank_view.xml',
|
||||
'res/res_country_view.xml',
|
||||
'res/res_currency_view.xml',
|
||||
'res/wizard/change_password_wizard_view.xml',
|
||||
'res/res_users_view.xml',
|
||||
'res/res_partner_data.xml',
|
||||
'res/ir_property_view.xml',
|
||||
@@ -93,19 +94,17 @@ The kernel of OpenERP, needed for all installation.
|
||||
'res/res_partner_image_demo.xml',
|
||||
],
|
||||
'test': [
|
||||
'test/base_test.xml',
|
||||
'test/base_test.yml',
|
||||
'test/test_context.xml',
|
||||
'test/bug_lp541545.xml',
|
||||
'test/test_osv_expression.yml',
|
||||
'test/test_ir_rule.yml', # <-- These tests modify/add/delete ir_rules.
|
||||
# Commented because this takes some time.
|
||||
# This must be (un)commented with the corresponding import statement
|
||||
# in test/__init__.py.
|
||||
# 'test/test_ir_cron.yml', # <-- These tests perform a roolback.
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': True,
|
||||
'css': ['static/src/css/modules.css'],
|
||||
'js': [
|
||||
'static/src/js/apps.js',
|
||||
],
|
||||
}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -62,7 +62,7 @@
|
||||
<record id="main_company" model="res.company">
|
||||
<field name="name">Your Company</field>
|
||||
<field name="partner_id" ref="main_partner"/>
|
||||
<field name="rml_header1">Your Company Slogan</field>
|
||||
<field name="rml_header1">Your Company Tagline</field>
|
||||
<field name="currency_id" ref="base.EUR"/>
|
||||
</record>
|
||||
|
||||
@@ -89,6 +89,13 @@ Administrator</field>
|
||||
<record id="EUR" model="res.currency">
|
||||
<field name="company_id" ref="main_company"/>
|
||||
</record>
|
||||
|
||||
|
||||
<record id="ir_mail_server_localhost0" model="ir.mail_server">
|
||||
<field name="name">localhost</field>
|
||||
<field name="smtp_host">localhost</field>
|
||||
<field eval="25" name="smtp_port"/>
|
||||
<field eval="10" name="sequence"/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -510,14 +510,6 @@
|
||||
<field name="currency_id" ref="CRC"/>
|
||||
<field eval="time.strftime('%Y-01-01')" name="name"/>
|
||||
</record>
|
||||
|
||||
<record id="ir_mail_server_localhost0" model="ir.mail_server">
|
||||
<field name="name">localhost</field>
|
||||
<field name="smtp_host">localhost</field>
|
||||
<field eval="25" name="smtp_port"/>
|
||||
<field eval="10" name="sequence"/>
|
||||
</record>
|
||||
|
||||
<record id="MUR" model="res.currency">
|
||||
<field name="name">MUR</field>
|
||||
<field name="symbol">Rs</field>
|
||||
|
||||
+1232
-1017
File diff suppressed because it is too large
Load Diff
+1232
-1017
File diff suppressed because it is too large
Load Diff
+1245
-1027
File diff suppressed because it is too large
Load Diff
+1286
-1050
File diff suppressed because it is too large
Load Diff
+1108
-900
File diff suppressed because it is too large
Load Diff
+1292
-1056
File diff suppressed because it is too large
Load Diff
+1243
-1025
File diff suppressed because it is too large
Load Diff
+1294
-1055
File diff suppressed because it is too large
Load Diff
+1296
-1054
File diff suppressed because it is too large
Load Diff
+1248
-1024
File diff suppressed because it is too large
Load Diff
+1538
-1136
File diff suppressed because it is too large
Load Diff
+1284
-1048
File diff suppressed because it is too large
Load Diff
+1306
-1096
File diff suppressed because it is too large
Load Diff
+3247
-1274
File diff suppressed because it is too large
Load Diff
+1301
-1047
File diff suppressed because it is too large
Load Diff
+1295
-1056
File diff suppressed because it is too large
Load Diff
+1349
-1090
File diff suppressed because it is too large
Load Diff
+1369
-1242
File diff suppressed because it is too large
Load Diff
+1389
-1091
File diff suppressed because it is too large
Load Diff
+1232
-1017
File diff suppressed because it is too large
Load Diff
+1236
-1018
File diff suppressed because it is too large
Load Diff
+1325
-1087
File diff suppressed because it is too large
Load Diff
+1232
-1017
File diff suppressed because it is too large
Load Diff
+1284
-1048
File diff suppressed because it is too large
Load Diff
+1232
-1017
File diff suppressed because it is too large
Load Diff
+1303
-1061
File diff suppressed because it is too large
Load Diff
+1344
-1201
File diff suppressed because it is too large
Load Diff
+1294
-1055
File diff suppressed because it is too large
Load Diff
+1259
-1035
File diff suppressed because it is too large
Load Diff
+1283
-1047
File diff suppressed because it is too large
Load Diff
+1232
-1017
File diff suppressed because it is too large
Load Diff
+1302
-1071
File diff suppressed because it is too large
Load Diff
+2299
-1485
File diff suppressed because it is too large
Load Diff
+1247
-1026
File diff suppressed because it is too large
Load Diff
+1238
-1020
File diff suppressed because it is too large
Load Diff
+1245
-1024
File diff suppressed because it is too large
Load Diff
+1298
-1108
File diff suppressed because it is too large
Load Diff
+1337
-1078
File diff suppressed because it is too large
Load Diff
+1289
-1053
File diff suppressed because it is too large
Load Diff
+1252
-1028
File diff suppressed because it is too large
Load Diff
+1269
-1033
File diff suppressed because it is too large
Load Diff
+1264
-1025
File diff suppressed because it is too large
Load Diff
+1292
-1053
File diff suppressed because it is too large
Load Diff
+1238
-1020
File diff suppressed because it is too large
Load Diff
+1323
-1177
File diff suppressed because it is too large
Load Diff
+1287
-1051
File diff suppressed because it is too large
Load Diff
+1458
-1185
File diff suppressed because it is too large
Load Diff
+1236
-1018
File diff suppressed because it is too large
Load Diff
+1286
-1047
File diff suppressed because it is too large
Load Diff
+1320
-1076
File diff suppressed because it is too large
Load Diff
+1342
-1168
File diff suppressed because it is too large
Load Diff
+2477
-1227
File diff suppressed because it is too large
Load Diff
+1548
-1137
File diff suppressed because it is too large
Load Diff
+1293
-1054
File diff suppressed because it is too large
Load Diff
+1376
-1544
File diff suppressed because it is too large
Load Diff
+1232
-1017
File diff suppressed because it is too large
Load Diff
+1290
-1051
File diff suppressed because it is too large
Load Diff
+1346
-1087
File diff suppressed because it is too large
Load Diff
+1287
-1048
File diff suppressed because it is too large
Load Diff
+1235
-1017
File diff suppressed because it is too large
Load Diff
+1232
-1017
File diff suppressed because it is too large
Load Diff
+1296
-1054
File diff suppressed because it is too large
Load Diff
+1277
-1041
File diff suppressed because it is too large
Load Diff
+1232
-1017
File diff suppressed because it is too large
Load Diff
+1261
-1034
File diff suppressed because it is too large
Load Diff
+1361
-1134
File diff suppressed because it is too large
Load Diff
+1239
-1024
File diff suppressed because it is too large
Load Diff
+1275
-1042
File diff suppressed because it is too large
Load Diff
@@ -614,16 +614,6 @@ class actions_server(osv.osv):
|
||||
|
||||
if action.state == 'email':
|
||||
email_from = config['email_from']
|
||||
address = str(action.email)
|
||||
try:
|
||||
address = eval(str(action.email), cxt)
|
||||
except:
|
||||
pass
|
||||
|
||||
if not address:
|
||||
_logger.info('No partner email address specified, not sending any email.')
|
||||
continue
|
||||
|
||||
if not email_from:
|
||||
_logger.debug('--email-from command line option is not specified, using a fallback value instead.')
|
||||
if user.email:
|
||||
@@ -631,16 +621,27 @@ class actions_server(osv.osv):
|
||||
else:
|
||||
email_from = "%s@%s" % (user.login, gethostname())
|
||||
|
||||
try:
|
||||
address = eval(str(action.email), cxt)
|
||||
except Exception:
|
||||
address = str(action.email)
|
||||
|
||||
if not address:
|
||||
_logger.info('No partner email address specified, not sending any email.')
|
||||
continue
|
||||
|
||||
# handle single and multiple recipient addresses
|
||||
addresses = address if isinstance(address, (tuple, list)) else [address]
|
||||
subject = self.merge_message(cr, uid, action.subject, action, context)
|
||||
body = self.merge_message(cr, uid, action.message, action, context)
|
||||
|
||||
ir_mail_server = self.pool.get('ir.mail_server')
|
||||
msg = ir_mail_server.build_email(email_from, [address], subject, body)
|
||||
msg = ir_mail_server.build_email(email_from, addresses, subject, body)
|
||||
res_email = ir_mail_server.send_email(cr, uid, msg)
|
||||
if res_email:
|
||||
_logger.info('Email successfully sent to: %s', address)
|
||||
_logger.info('Email successfully sent to: %s', addresses)
|
||||
else:
|
||||
_logger.warning('Failed to send email to: %s', address)
|
||||
_logger.warning('Failed to send email to: %s', addresses)
|
||||
|
||||
if action.state == 'trigger':
|
||||
wf_service = netsvc.LocalService("workflow")
|
||||
|
||||
@@ -18,11 +18,164 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
import itertools
|
||||
|
||||
import hashlib
|
||||
import itertools
|
||||
import os
|
||||
import re
|
||||
|
||||
from openerp import tools
|
||||
from openerp.osv import fields,osv
|
||||
|
||||
class ir_attachment(osv.osv):
|
||||
"""Attachments are used to link binary files or url to any openerp document.
|
||||
|
||||
External attachment storage
|
||||
---------------------------
|
||||
|
||||
The 'data' function field (_data_get,data_set) is implemented using
|
||||
_file_read, _file_write and _file_delete which can be overridden to
|
||||
implement other storage engines, shuch methods should check for other
|
||||
location pseudo uri (example: hdfs://hadoppserver)
|
||||
|
||||
The default implementation is the file:dirname location that stores files
|
||||
on the local filesystem using name based on their sha1 hash
|
||||
"""
|
||||
def _name_get_resname(self, cr, uid, ids, object, method, context):
|
||||
data = {}
|
||||
for attachment in self.browse(cr, uid, ids, context=context):
|
||||
model_object = attachment.res_model
|
||||
res_id = attachment.res_id
|
||||
if model_object and res_id:
|
||||
model_pool = self.pool.get(model_object)
|
||||
res = model_pool.name_get(cr,uid,[res_id],context)
|
||||
res_name = res and res[0][1] or False
|
||||
if res_name:
|
||||
field = self._columns.get('res_name',False)
|
||||
if field and len(res_name) > field.size:
|
||||
res_name = res_name[:field.size-3] + '...'
|
||||
data[attachment.id] = res_name
|
||||
else:
|
||||
data[attachment.id] = False
|
||||
return data
|
||||
|
||||
# 'data' field implementation
|
||||
def _full_path(self, cr, uid, location, path):
|
||||
# location = 'file:filestore'
|
||||
assert location.startswith('file:'), "Unhandled filestore location %s" % location
|
||||
location = location[5:]
|
||||
|
||||
# sanitize location name and path
|
||||
location = re.sub('[.]','',location)
|
||||
location = location.strip('/\\')
|
||||
|
||||
path = re.sub('[.]','',path)
|
||||
path = path.strip('/\\')
|
||||
return os.path.join(tools.config['root_path'], location, cr.dbname, path)
|
||||
|
||||
def _file_read(self, cr, uid, location, fname, bin_size=False):
|
||||
full_path = self._full_path(cr, uid, location, fname)
|
||||
r = ''
|
||||
try:
|
||||
if bin_size:
|
||||
r = os.path.getsize(full_path)
|
||||
else:
|
||||
r = open(full_path).read().encode('base64')
|
||||
except IOError:
|
||||
_logger.error("_read_file reading %s",full_path)
|
||||
return r
|
||||
|
||||
def _file_write(self, cr, uid, location, value):
|
||||
bin_value = value.decode('base64')
|
||||
fname = hashlib.sha1(bin_value).hexdigest()
|
||||
# scatter files across 1024 dirs
|
||||
# we use '/' in the db (even on windows)
|
||||
fname = fname[:3] + '/' + fname
|
||||
full_path = self._full_path(cr, uid, location, fname)
|
||||
try:
|
||||
dirname = os.path.dirname(full_path)
|
||||
if not os.path.isdir(dirname):
|
||||
os.makedirs(dirname)
|
||||
open(full_path,'wb').write(bin_value)
|
||||
except IOError:
|
||||
_logger.error("_file_write writing %s",full_path)
|
||||
return fname
|
||||
|
||||
def _file_delete(self, cr, uid, location, fname):
|
||||
count = self.search(cr, 1, [('store_fname','=',fname)], count=True)
|
||||
if count <= 1:
|
||||
full_path = self._full_path(cr, uid, location, fname)
|
||||
try:
|
||||
os.unlink(full_path)
|
||||
except IOError:
|
||||
# Harmless and needed for race conditions
|
||||
_logger.error("_file_delete could not unlink %s",full_path)
|
||||
|
||||
def _data_get(self, cr, uid, ids, name, arg, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
result = {}
|
||||
location = self.pool.get('ir.config_parameter').get_param(cr, uid, 'ir_attachment.location')
|
||||
bin_size = context.get('bin_size')
|
||||
for attach in self.browse(cr, uid, ids, context=context):
|
||||
if location and attach.store_fname:
|
||||
result[attach.id] = self._file_read(cr, uid, location, attach.store_fname, bin_size)
|
||||
else:
|
||||
result[attach.id] = attach.db_datas
|
||||
return result
|
||||
|
||||
def _data_set(self, cr, uid, id, name, value, arg, context=None):
|
||||
# We dont handle setting data to null
|
||||
if not value:
|
||||
return True
|
||||
if context is None:
|
||||
context = {}
|
||||
location = self.pool.get('ir.config_parameter').get_param(cr, uid, 'ir_attachment.location')
|
||||
file_size = len(value.decode('base64'))
|
||||
if location:
|
||||
attach = self.browse(cr, uid, id, context=context)
|
||||
if attach.store_fname:
|
||||
self._file_delete(cr, uid, location, attach.store_fname)
|
||||
fname = self._file_write(cr, uid, location, value)
|
||||
super(ir_attachment, self).write(cr, uid, [id], {'store_fname': fname, 'file_size': file_size}, context=context)
|
||||
else:
|
||||
super(ir_attachment, self).write(cr, uid, [id], {'db_datas': value, 'file_size': file_size}, context=context)
|
||||
return True
|
||||
|
||||
_name = 'ir.attachment'
|
||||
_columns = {
|
||||
'name': fields.char('Attachment Name',size=256, required=True),
|
||||
'datas_fname': fields.char('File Name',size=256),
|
||||
'description': fields.text('Description'),
|
||||
'res_name': fields.function(_name_get_resname, type='char', size=128, string='Resource Name', store=True),
|
||||
'res_model': fields.char('Resource Model',size=64, readonly=True, help="The database object this attachment will be attached to"),
|
||||
'res_id': fields.integer('Resource ID', readonly=True, help="The record id this is attached to"),
|
||||
'create_date': fields.datetime('Date Created', readonly=True),
|
||||
'create_uid': fields.many2one('res.users', 'Owner', readonly=True),
|
||||
'company_id': fields.many2one('res.company', 'Company', change_default=True),
|
||||
'type': fields.selection( [ ('url','URL'), ('binary','Binary'), ],
|
||||
'Type', help="Binary File or URL", required=True, change_default=True),
|
||||
'url': fields.char('Url', size=1024),
|
||||
# al: We keep shitty field names for backward compatibility with document
|
||||
'datas': fields.function(_data_get, fnct_inv=_data_set, string='File Content', type="binary", nodrop=True),
|
||||
'store_fname': fields.char('Stored Filename', size=256),
|
||||
'db_datas': fields.binary('Database Data'),
|
||||
'file_size': fields.integer('File Size'),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'type': 'binary',
|
||||
'file_size': 0,
|
||||
'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'ir.attachment', context=c),
|
||||
}
|
||||
|
||||
def _auto_init(self, cr, context=None):
|
||||
super(ir_attachment, self)._auto_init(cr, context)
|
||||
cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('ir_attachment_res_idx',))
|
||||
if not cr.fetchone():
|
||||
cr.execute('CREATE INDEX ir_attachment_res_idx ON ir_attachment (res_model, res_id)')
|
||||
cr.commit()
|
||||
|
||||
def check(self, cr, uid, ids, mode, context=None, values=None):
|
||||
"""Restricts the access to an ir.attachment, according to referred model
|
||||
In the 'document' module, it is overriden to relax this hard rule, since
|
||||
@@ -108,6 +261,8 @@ class ir_attachment(osv.osv):
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
self.check(cr, uid, ids, 'write', context=context, values=vals)
|
||||
if 'file_size' in vals:
|
||||
del vals['file_size']
|
||||
return super(ir_attachment, self).write(cr, uid, ids, vals, context)
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
@@ -116,70 +271,22 @@ class ir_attachment(osv.osv):
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
self.check(cr, uid, ids, 'unlink', context=context)
|
||||
location = self.pool.get('ir.config_parameter').get_param(cr, uid, 'ir_attachment.location')
|
||||
if location:
|
||||
for attach in self.browse(cr, uid, ids, context=context):
|
||||
if attach.store_fname:
|
||||
self._file_delete(cr, uid, location, attach.store_fname)
|
||||
return super(ir_attachment, self).unlink(cr, uid, ids, context)
|
||||
|
||||
def create(self, cr, uid, values, context=None):
|
||||
self.check(cr, uid, [], mode='create', context=context, values=values)
|
||||
if 'file_size' in values:
|
||||
del values['file_size']
|
||||
return super(ir_attachment, self).create(cr, uid, values, context)
|
||||
|
||||
def action_get(self, cr, uid, context=None):
|
||||
return self.pool.get('ir.actions.act_window').for_xml_id(
|
||||
cr, uid, 'base', 'action_attachment', context=context)
|
||||
|
||||
def _name_get_resname(self, cr, uid, ids, object, method, context):
|
||||
data = {}
|
||||
for attachment in self.browse(cr, uid, ids, context=context):
|
||||
model_object = attachment.res_model
|
||||
res_id = attachment.res_id
|
||||
if model_object and res_id:
|
||||
model_pool = self.pool.get(model_object)
|
||||
res = model_pool.name_get(cr,uid,[res_id],context)
|
||||
res_name = res and res[0][1] or False
|
||||
if res_name:
|
||||
field = self._columns.get('res_name',False)
|
||||
if field and len(res_name) > field.size:
|
||||
res_name = res_name[:field.size-3] + '...'
|
||||
data[attachment.id] = res_name
|
||||
else:
|
||||
data[attachment.id] = False
|
||||
return data
|
||||
|
||||
_name = 'ir.attachment'
|
||||
_columns = {
|
||||
'name': fields.char('Attachment Name',size=256, required=True),
|
||||
'datas': fields.binary('Data'),
|
||||
'datas_fname': fields.char('File Name',size=256),
|
||||
'description': fields.text('Description'),
|
||||
'res_name': fields.function(_name_get_resname, type='char', size=128,
|
||||
string='Resource Name', store=True),
|
||||
'res_model': fields.char('Resource Object',size=64, readonly=True,
|
||||
help="The database object this attachment will be attached to"),
|
||||
'res_id': fields.integer('Resource ID', readonly=True,
|
||||
help="The record id this is attached to"),
|
||||
'url': fields.char('Url', size=512, oldname="link"),
|
||||
'type': fields.selection(
|
||||
[ ('url','URL'), ('binary','Binary'), ],
|
||||
'Type', help="Binary File or external URL", required=True, change_default=True),
|
||||
|
||||
'create_date': fields.datetime('Date Created', readonly=True),
|
||||
'create_uid': fields.many2one('res.users', 'Owner', readonly=True),
|
||||
'company_id': fields.many2one('res.company', 'Company', change_default=True),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'type': 'binary',
|
||||
'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'ir.attachment', context=c),
|
||||
}
|
||||
|
||||
def _auto_init(self, cr, context=None):
|
||||
super(ir_attachment, self)._auto_init(cr, context)
|
||||
cr.execute('SELECT indexname FROM pg_indexes WHERE indexname = %s', ('ir_attachment_res_idx',))
|
||||
if not cr.fetchone():
|
||||
cr.execute('CREATE INDEX ir_attachment_res_idx ON ir_attachment (res_model, res_id)')
|
||||
cr.commit()
|
||||
|
||||
ir_attachment()
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -182,10 +182,12 @@ class ir_mail_server(osv.osv):
|
||||
"(this is very verbose and may include confidential info!)"),
|
||||
'sequence': fields.integer('Priority', help="When no specific mail server is requested for a mail, the highest priority one "
|
||||
"is used. Default priority is 10 (smaller number = higher priority)"),
|
||||
'active': fields.boolean('Active')
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'smtp_port': 25,
|
||||
'active': True,
|
||||
'sequence': 10,
|
||||
'smtp_encryption': 'none',
|
||||
}
|
||||
|
||||
@@ -24,12 +24,22 @@ from docutils.transforms import Transform, writer_aux
|
||||
from docutils.writers.html4css1 import Writer
|
||||
import imp
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import tempfile
|
||||
import urllib
|
||||
import urllib2
|
||||
import zipfile
|
||||
import zipimport
|
||||
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
from StringIO import StringIO # NOQA
|
||||
|
||||
import openerp
|
||||
from openerp import modules, pooler, release, tools, addons
|
||||
from openerp import modules, pooler, tools, addons
|
||||
from openerp.modules.db import create_categories
|
||||
from openerp.tools.parse_version import parse_version
|
||||
from openerp.tools.translate import _
|
||||
@@ -43,14 +53,29 @@ ACTION_DICT = {
|
||||
'res_model': 'base.module.upgrade',
|
||||
'target': 'new',
|
||||
'type': 'ir.actions.act_window',
|
||||
'nodestroy':True,
|
||||
'nodestroy': True,
|
||||
}
|
||||
|
||||
def backup(path, raise_exception=True):
|
||||
path = os.path.normpath(path)
|
||||
if not os.path.exists(path):
|
||||
if not raise_exception:
|
||||
return None
|
||||
raise OSError('path does not exists')
|
||||
cnt = 1
|
||||
while True:
|
||||
bck = '%s~%d' % (path, cnt)
|
||||
if not os.path.exists(bck):
|
||||
shutil.move(path, bck)
|
||||
return bck
|
||||
cnt += 1
|
||||
|
||||
|
||||
class module_category(osv.osv):
|
||||
_name = "ir.module.category"
|
||||
_description = "Application"
|
||||
|
||||
def _module_nbr(self,cr,uid, ids, prop, unknow_none, context):
|
||||
def _module_nbr(self, cr, uid, ids, prop, unknow_none, context):
|
||||
cr.execute('SELECT category_id, COUNT(*) \
|
||||
FROM ir_module_module \
|
||||
WHERE category_id IN %(ids)s \
|
||||
@@ -58,7 +83,7 @@ class module_category(osv.osv):
|
||||
FROM ir_module_category \
|
||||
WHERE parent_id IN %(ids)s) \
|
||||
GROUP BY category_id', {'ids': tuple(ids)}
|
||||
)
|
||||
)
|
||||
result = dict(cr.fetchall())
|
||||
for id in ids:
|
||||
cr.execute('select id from ir_module_category where parent_id=%s', (id,))
|
||||
@@ -71,16 +96,16 @@ class module_category(osv.osv):
|
||||
'parent_id': fields.many2one('ir.module.category', 'Parent Application', select=True),
|
||||
'child_ids': fields.one2many('ir.module.category', 'parent_id', 'Child Applications'),
|
||||
'module_nr': fields.function(_module_nbr, string='Number of Modules', type='integer'),
|
||||
'module_ids' : fields.one2many('ir.module.module', 'category_id', 'Modules'),
|
||||
'description' : fields.text("Description", translate=True),
|
||||
'sequence' : fields.integer('Sequence'),
|
||||
'visible' : fields.boolean('Visible'),
|
||||
'module_ids': fields.one2many('ir.module.module', 'category_id', 'Modules'),
|
||||
'description': fields.text("Description", translate=True),
|
||||
'sequence': fields.integer('Sequence'),
|
||||
'visible': fields.boolean('Visible'),
|
||||
'xml_id': fields.function(osv.osv.get_external_id, type='char', size=128, string="External ID"),
|
||||
}
|
||||
_order = 'name'
|
||||
|
||||
_defaults = {
|
||||
'visible' : 1,
|
||||
'visible': 1,
|
||||
}
|
||||
|
||||
class MyFilterMessages(Transform):
|
||||
@@ -119,7 +144,6 @@ class module(osv.osv):
|
||||
info = {}
|
||||
try:
|
||||
info = modules.load_information_from_description_file(name)
|
||||
info['version'] = release.major_version + '.' + info['version']
|
||||
except Exception:
|
||||
_logger.debug('Error when trying to fetch informations for '
|
||||
'module %s', name, exc_info=True)
|
||||
@@ -134,9 +158,10 @@ class module(osv.osv):
|
||||
return res
|
||||
|
||||
def _get_latest_version(self, cr, uid, ids, field_name=None, arg=None, context=None):
|
||||
res = dict.fromkeys(ids, '')
|
||||
default_version = modules.adapt_version('1.0')
|
||||
res = dict.fromkeys(ids, default_version)
|
||||
for m in self.browse(cr, uid, ids):
|
||||
res[m.id] = self.get_module_info(m.name).get('version', '')
|
||||
res[m.id] = self.get_module_info(m.name).get('version', default_version)
|
||||
return res
|
||||
|
||||
def _get_views(self, cr, uid, ids, field_name=None, arg=None, context=None):
|
||||
@@ -167,9 +192,11 @@ class module(osv.osv):
|
||||
continue
|
||||
|
||||
# then, search and group ir.model.data records
|
||||
imd_models = dict( [(m,[]) for m in dmodels])
|
||||
imd_ids = model_data_obj.search(cr,uid,[('module','=', module_rec.name),
|
||||
('model','in',tuple(dmodels))])
|
||||
imd_models = dict([(m, []) for m in dmodels])
|
||||
imd_ids = model_data_obj.search(cr, uid, [
|
||||
('module', '=', module_rec.name),
|
||||
('model', 'in', tuple(dmodels))
|
||||
])
|
||||
|
||||
for imd_res in model_data_obj.read(cr, uid, imd_ids, ['model', 'res_id'], context=context):
|
||||
imd_models[imd_res['model']].append(imd_res['res_id'])
|
||||
@@ -181,7 +208,7 @@ class module(osv.osv):
|
||||
view_ids = imd_models.get('ir.ui.view', [])
|
||||
for v in view_obj.browse(cr, uid, view_ids, context=context):
|
||||
aa = v.inherit_id and '* INHERIT ' or ''
|
||||
res_mod_dic['views_by_module'].append(aa + v.name + '('+v.type+')')
|
||||
res_mod_dic['views_by_module'].append('%s%s (%s)' % (aa, v.name, v.type))
|
||||
|
||||
report_ids = imd_models.get('ir.actions.report.xml', [])
|
||||
for rx in report_obj.browse(cr, uid, report_ids, context=context):
|
||||
@@ -191,15 +218,13 @@ class module(osv.osv):
|
||||
for um in menu_obj.browse(cr, uid, menu_ids, context=context):
|
||||
res_mod_dic['menus_by_module'].append(um.complete_name)
|
||||
except KeyError, e:
|
||||
_logger.warning(
|
||||
'Data not found for items of %s', module_rec.name)
|
||||
_logger.warning('Data not found for items of %s', module_rec.name)
|
||||
except AttributeError, e:
|
||||
_logger.warning(
|
||||
'Data not found for items of %s %s', module_rec.name, str(e))
|
||||
_logger.warning('Data not found for items of %s %s', module_rec.name, str(e))
|
||||
except Exception, e:
|
||||
_logger.warning('Unknown error while fetching data of %s',
|
||||
module_rec.name, exc_info=True)
|
||||
for key, _ in res.iteritems():
|
||||
_logger.warning('Unknown error while fetching data of %s', module_rec.name, exc_info=True)
|
||||
|
||||
for key in res.iterkeys():
|
||||
for k, v in res[key].iteritems():
|
||||
res[key][k] = "\n".join(sorted(v))
|
||||
return res
|
||||
@@ -232,36 +257,34 @@ class module(osv.osv):
|
||||
# installed_version refer the latest version (the one on disk)
|
||||
# latest_version refer the installed version (the one in database)
|
||||
# published_version refer the version available on the repository
|
||||
'installed_version': fields.function(_get_latest_version,
|
||||
string='Latest Version', type='char'),
|
||||
'installed_version': fields.function(_get_latest_version, string='Latest Version', type='char'),
|
||||
'latest_version': fields.char('Installed Version', size=64, readonly=True),
|
||||
'published_version': fields.char('Published Version', size=64, readonly=True),
|
||||
|
||||
'url': fields.char('URL', size=128, readonly=True),
|
||||
'sequence': fields.integer('Sequence'),
|
||||
'dependencies_id': fields.one2many('ir.module.module.dependency',
|
||||
'module_id', 'Dependencies', readonly=True),
|
||||
'dependencies_id': fields.one2many('ir.module.module.dependency', 'module_id', 'Dependencies', readonly=True),
|
||||
'auto_install': fields.boolean('Automatic Installation',
|
||||
help='An auto-installable module is automatically installed by the '
|
||||
'system when all its dependencies are satisfied. '
|
||||
'If the module has no dependency, it is always installed.'),
|
||||
help='An auto-installable module is automatically installed by the '
|
||||
'system when all its dependencies are satisfied. '
|
||||
'If the module has no dependency, it is always installed.'),
|
||||
'state': fields.selection([
|
||||
('uninstallable','Not Installable'),
|
||||
('uninstalled','Not Installed'),
|
||||
('installed','Installed'),
|
||||
('to upgrade','To be upgraded'),
|
||||
('to remove','To be removed'),
|
||||
('to install','To be installed')
|
||||
('uninstallable', 'Not Installable'),
|
||||
('uninstalled', 'Not Installed'),
|
||||
('installed', 'Installed'),
|
||||
('to upgrade', 'To be upgraded'),
|
||||
('to remove', 'To be removed'),
|
||||
('to install', 'To be installed')
|
||||
], string='Status', readonly=True, select=True),
|
||||
'demo': fields.boolean('Demo Data', readonly=True),
|
||||
'license': fields.selection([
|
||||
('GPL-2', 'GPL Version 2'),
|
||||
('GPL-2 or any later version', 'GPL-2 or later version'),
|
||||
('GPL-3', 'GPL Version 3'),
|
||||
('GPL-3 or any later version', 'GPL-3 or later version'),
|
||||
('AGPL-3', 'Affero GPL-3'),
|
||||
('Other OSI approved licence', 'Other OSI Approved Licence'),
|
||||
('Other proprietary', 'Other Proprietary')
|
||||
('GPL-2', 'GPL Version 2'),
|
||||
('GPL-2 or any later version', 'GPL-2 or later version'),
|
||||
('GPL-3', 'GPL Version 3'),
|
||||
('GPL-3 or any later version', 'GPL-3 or later version'),
|
||||
('AGPL-3', 'Affero GPL-3'),
|
||||
('Other OSI approved licence', 'Other OSI Approved Licence'),
|
||||
('Other proprietary', 'Other Proprietary')
|
||||
], string='License', readonly=True),
|
||||
'menus_by_module': fields.function(_get_views, string='Menus', type='text', multi="meta", store=True),
|
||||
'reports_by_module': fields.function(_get_views, string='Reports', type='text', multi="meta", store=True),
|
||||
@@ -283,7 +306,7 @@ class module(osv.osv):
|
||||
return _('The name of the module must be unique !')
|
||||
|
||||
_sql_constraints = [
|
||||
('name_uniq', 'UNIQUE (name)',_name_uniq_msg ),
|
||||
('name_uniq', 'UNIQUE (name)', _name_uniq_msg),
|
||||
]
|
||||
|
||||
def unlink(self, cr, uid, ids, context=None):
|
||||
@@ -292,10 +315,9 @@ class module(osv.osv):
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
mod_names = []
|
||||
for mod in self.read(cr, uid, ids, ['state','name'], context):
|
||||
for mod in self.read(cr, uid, ids, ['state', 'name'], context):
|
||||
if mod['state'] in ('installed', 'to upgrade', 'to remove', 'to install'):
|
||||
raise orm.except_orm(_('Error'),
|
||||
_('You try to remove a module that is installed or will be installed'))
|
||||
raise orm.except_orm(_('Error'), _('You try to remove a module that is installed or will be installed'))
|
||||
mod_names.append(mod['name'])
|
||||
#Removing the entry from ir_model_data
|
||||
#ids_meta = self.pool.get('ir.model.data').search(cr, uid, [('name', '=', 'module_meta_information'), ('module', 'in', mod_names)])
|
||||
@@ -340,7 +362,7 @@ class module(osv.osv):
|
||||
raise orm.except_orm(_('Error'), msg % (module_name, e.args[0]))
|
||||
|
||||
def state_update(self, cr, uid, ids, newstate, states_to_update, context=None, level=100):
|
||||
if level<1:
|
||||
if level < 1:
|
||||
raise orm.except_orm(_('Error'), _('Recursion error in modules dependencies !'))
|
||||
demo = False
|
||||
for module in self.browse(cr, uid, ids, context=context):
|
||||
@@ -348,9 +370,9 @@ class module(osv.osv):
|
||||
for dep in module.dependencies_id:
|
||||
if dep.state == 'unknown':
|
||||
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,))
|
||||
ids2 = self.search(cr, uid, [('name','=',dep.name)])
|
||||
ids2 = self.search(cr, uid, [('name', '=', dep.name)])
|
||||
if dep.state != newstate:
|
||||
mdemo = self.state_update(cr, uid, ids2, newstate, states_to_update, context, level-1,) or mdemo
|
||||
mdemo = self.state_update(cr, uid, ids2, newstate, states_to_update, context, level - 1) or mdemo
|
||||
else:
|
||||
od = self.browse(cr, uid, ids2)[0]
|
||||
mdemo = od.demo or mdemo
|
||||
@@ -359,7 +381,7 @@ class module(osv.osv):
|
||||
if not module.dependencies_id:
|
||||
mdemo = module.demo
|
||||
if module.state in states_to_update:
|
||||
self.write(cr, uid, [module.id], {'state': newstate, 'demo':mdemo})
|
||||
self.write(cr, uid, [module.id], {'state': newstate, 'demo': mdemo})
|
||||
demo = demo or mdemo
|
||||
return demo
|
||||
|
||||
@@ -403,7 +425,7 @@ class module(osv.osv):
|
||||
return self._button_immediate_function(cr, uid, ids, self.button_install, context=context)
|
||||
|
||||
def button_install_cancel(self, cr, uid, ids, context=None):
|
||||
self.write(cr, uid, ids, {'state': 'uninstalled', 'demo':False})
|
||||
self.write(cr, uid, ids, {'state': 'uninstalled', 'demo': False})
|
||||
return True
|
||||
|
||||
def module_uninstall(self, cr, uid, ids, context=None):
|
||||
@@ -421,12 +443,13 @@ class module(osv.osv):
|
||||
return True
|
||||
|
||||
def downstream_dependencies(self, cr, uid, ids, known_dep_ids=None,
|
||||
exclude_states=['uninstalled','uninstallable','to remove'],
|
||||
exclude_states=['uninstalled', 'uninstallable', 'to remove'],
|
||||
context=None):
|
||||
"""Return the ids of all modules that directly or indirectly depend
|
||||
on the given module `ids`, and that satisfy the `exclude_states`
|
||||
filter"""
|
||||
if not ids: return []
|
||||
if not ids:
|
||||
return []
|
||||
known_dep_ids = set(known_dep_ids or [])
|
||||
cr.execute('''SELECT DISTINCT m.id
|
||||
FROM
|
||||
@@ -437,13 +460,13 @@ class module(osv.osv):
|
||||
d.name IN (SELECT name from ir_module_module where id in %s) AND
|
||||
m.state NOT IN %s AND
|
||||
m.id NOT IN %s ''',
|
||||
(tuple(ids),tuple(exclude_states), tuple(known_dep_ids or ids)))
|
||||
(tuple(ids), tuple(exclude_states), tuple(known_dep_ids or ids)))
|
||||
new_dep_ids = set([m[0] for m in cr.fetchall()])
|
||||
missing_mod_ids = new_dep_ids - known_dep_ids
|
||||
known_dep_ids |= new_dep_ids
|
||||
if missing_mod_ids:
|
||||
known_dep_ids |= set(self.downstream_dependencies(cr, uid, list(missing_mod_ids),
|
||||
known_dep_ids, exclude_states,context))
|
||||
known_dep_ids, exclude_states, context))
|
||||
return list(known_dep_ids)
|
||||
|
||||
def _button_immediate_function(self, cr, uid, ids, function, context=None):
|
||||
@@ -460,9 +483,9 @@ class module(osv.osv):
|
||||
menu_obj = self.pool.get('ir.ui.menu')
|
||||
menu_ids = menu_obj.search(cr, uid, [('parent_id', '=', False)], context=context)
|
||||
return {
|
||||
'type' : 'ir.actions.client',
|
||||
'tag' : 'reload',
|
||||
'params' : {'menu_id' : menu_ids and menu_ids[0] or False}
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'reload',
|
||||
'params': {'menu_id': menu_ids and menu_ids[0] or False}
|
||||
}
|
||||
|
||||
def button_immediate_uninstall(self, cr, uid, ids, context=None):
|
||||
@@ -496,20 +519,19 @@ class module(osv.osv):
|
||||
self.update_list(cr, uid)
|
||||
|
||||
i = 0
|
||||
while i<len(todo):
|
||||
while i < len(todo):
|
||||
mod = todo[i]
|
||||
i += 1
|
||||
if mod.state not in ('installed','to upgrade'):
|
||||
raise orm.except_orm(_('Error'),
|
||||
_("Can not upgrade module '%s'. It is not installed.") % (mod.name,))
|
||||
if mod.state not in ('installed', 'to upgrade'):
|
||||
raise orm.except_orm(_('Error'), _("Can not upgrade module '%s'. It is not installed.") % (mod.name,))
|
||||
self.check_external_dependencies(mod.name, 'to upgrade')
|
||||
iids = depobj.search(cr, uid, [('name', '=', mod.name)], context=context)
|
||||
for dep in depobj.browse(cr, uid, iids, context=context):
|
||||
if dep.module_id.state=='installed' and dep.module_id not in todo:
|
||||
if dep.module_id.state == 'installed' and dep.module_id not in todo:
|
||||
todo.append(dep.module_id)
|
||||
|
||||
ids = map(lambda x: x.id, todo)
|
||||
self.write(cr, uid, ids, {'state':'to upgrade'}, context=context)
|
||||
self.write(cr, uid, ids, {'state': 'to upgrade'}, context=context)
|
||||
|
||||
to_install = []
|
||||
for mod in todo:
|
||||
@@ -517,7 +539,7 @@ class module(osv.osv):
|
||||
if dep.state == 'unknown':
|
||||
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,))
|
||||
if dep.state == 'uninstalled':
|
||||
ids2 = self.search(cr, uid, [('name','=',dep.name)])
|
||||
ids2 = self.search(cr, uid, [('name', '=', dep.name)])
|
||||
to_install.extend(ids2)
|
||||
|
||||
self.button_install(cr, uid, to_install, context=context)
|
||||
@@ -550,8 +572,9 @@ class module(osv.osv):
|
||||
|
||||
# update the list of available packages
|
||||
def update_list(self, cr, uid, context=None):
|
||||
res = [0, 0] # [update, add]
|
||||
res = [0, 0] # [update, add]
|
||||
|
||||
default_version = modules.adapt_version('1.0')
|
||||
known_mods = self.browse(cr, uid, self.search(cr, uid, []))
|
||||
known_mods_names = dict([(m.name, m) for m in known_mods])
|
||||
|
||||
@@ -570,7 +593,7 @@ class module(osv.osv):
|
||||
updated_values[key] = values[key]
|
||||
if terp.get('installable', True) and mod.state == 'uninstallable':
|
||||
updated_values['state'] = 'uninstalled'
|
||||
if parse_version(terp.get('version', '')) > parse_version(mod.latest_version or ''):
|
||||
if parse_version(terp.get('version', default_version)) > parse_version(mod.latest_version or default_version):
|
||||
res[0] += 1
|
||||
if updated_values:
|
||||
self.write(cr, uid, mod.id, updated_values)
|
||||
@@ -587,24 +610,32 @@ class module(osv.osv):
|
||||
self._update_dependencies(cr, uid, mod, terp.get('depends', []))
|
||||
self._update_category(cr, uid, mod, terp.get('category', 'Uncategorized'))
|
||||
|
||||
# Trigger load_addons if new module have been discovered it exists on
|
||||
# wsgi handlers, so they can react accordingly
|
||||
if tuple(res) != (0, 0):
|
||||
for handler in openerp.service.wsgi_server.module_handlers:
|
||||
if hasattr(handler,'load_addons'):
|
||||
handler.load_addons()
|
||||
|
||||
return res
|
||||
|
||||
def download(self, cr, uid, ids, download=True, context=None):
|
||||
res = []
|
||||
default_version = modules.adapt_version('1.0')
|
||||
for mod in self.browse(cr, uid, ids, context=context):
|
||||
if not mod.url:
|
||||
continue
|
||||
match = re.search('-([a-zA-Z0-9\._-]+)(\.zip)', mod.url, re.I)
|
||||
version = '0'
|
||||
version = default_version
|
||||
if match:
|
||||
version = match.group(1)
|
||||
if parse_version(mod.installed_version or '0') >= parse_version(version):
|
||||
if parse_version(mod.installed_version) >= parse_version(version):
|
||||
continue
|
||||
res.append(mod.url)
|
||||
if not download:
|
||||
continue
|
||||
zip_content = urllib.urlopen(mod.url).read()
|
||||
fname = modules.get_module_path(str(mod.name)+'.zip', downloaded=True)
|
||||
fname = modules.get_module_path(str(mod.name) + '.zip', downloaded=True)
|
||||
try:
|
||||
with open(fname, 'wb') as fp:
|
||||
fp.write(zip_content)
|
||||
@@ -614,17 +645,77 @@ class module(osv.osv):
|
||||
raise orm.except_orm(_('Error'), _('Can not create the module file:\n %s') % (fname,))
|
||||
terp = self.get_module_info(mod.name)
|
||||
self.write(cr, uid, mod.id, self.get_values_from_terp(terp))
|
||||
cr.execute('DELETE FROM ir_module_module_dependency ' \
|
||||
'WHERE module_id = %s', (mod.id,))
|
||||
self._update_dependencies(cr, uid, mod, terp.get('depends',
|
||||
[]))
|
||||
self._update_category(cr, uid, mod, terp.get('category',
|
||||
'Uncategorized'))
|
||||
cr.execute('DELETE FROM ir_module_module_dependency WHERE module_id = %s', (mod.id,))
|
||||
self._update_dependencies(cr, uid, mod, terp.get('depends', []))
|
||||
self._update_category(cr, uid, mod, terp.get('category', 'Uncategorized'))
|
||||
# Import module
|
||||
zimp = zipimport.zipimporter(fname)
|
||||
zimp.load_module(mod.name)
|
||||
return res
|
||||
|
||||
def install_from_urls(self, cr, uid, urls, context=None):
|
||||
OPENERP = 'openerp'
|
||||
tmp = tempfile.mkdtemp()
|
||||
try:
|
||||
for module_name, url in urls.items():
|
||||
if not url:
|
||||
continue # nothing to download, local version is already the last one
|
||||
try:
|
||||
content = urllib2.urlopen(url).read()
|
||||
except Exception, e:
|
||||
_logger.exception('ggr')
|
||||
raise osv.except_osv('grrr', e)
|
||||
else:
|
||||
zipfile.ZipFile(StringIO(content)).extractall(tmp)
|
||||
assert os.path.isdir(os.path.join(tmp, module_name))
|
||||
|
||||
for module_name in urls:
|
||||
if module_name == OPENERP:
|
||||
continue # special case. handled below
|
||||
module_path = modules.get_module_path(module_name, downloaded=True, display_warning=False)
|
||||
bck = backup(module_path, False)
|
||||
shutil.move(os.path.join(tmp, module_name), module_path)
|
||||
if bck:
|
||||
shutil.rmtree(bck)
|
||||
|
||||
if urls.get(OPENERP, None):
|
||||
# special case. it containt the server and the base module.
|
||||
# extract path is not the same
|
||||
|
||||
base_path = os.path.dirname(modules.get_module_path('base'))
|
||||
|
||||
# copy all modules in the SERVER/openerp/addons directory to the new "openerp" module (except base itself)
|
||||
for d in os.listdir(base_path):
|
||||
if d != 'base' and os.path.isdir(os.path.join(base_path, d)):
|
||||
destdir = os.path.join(tmp, OPENERP, 'addons', d) # XXX 'openerp' subdirectory ?
|
||||
shutil.copytree(os.path.join(base_path, d), destdir)
|
||||
|
||||
# then replace the server by the new "base" module
|
||||
server_dir = openerp.tools.config['root_path'] # XXX or dirname()
|
||||
bck = backup(server_dir)
|
||||
shutil.move(os.path.join(tmp, OPENERP), server_dir)
|
||||
#if bck:
|
||||
# shutil.rmtree(bck)
|
||||
|
||||
self.update_list(cr, uid, context=context)
|
||||
|
||||
ids = self.search(cr, uid, [('name', 'in', urls.keys())], context=context)
|
||||
if self.search_count(cr, uid, [('id', 'in', ids), ('state', '=', 'installed')], context=context):
|
||||
# if any to update
|
||||
cr.commit()
|
||||
openerp.service.restart_server()
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'home',
|
||||
'params': {'wait': True},
|
||||
}
|
||||
return self.button_immediate_install(cr, uid, ids, context=context)
|
||||
finally:
|
||||
shutil.rmtree(tmp)
|
||||
|
||||
def install_by_names(self, cr, uid, names, context=None):
|
||||
raise NotImplementedError('# TODO')
|
||||
|
||||
def _update_dependencies(self, cr, uid, mod_browse, depends=None):
|
||||
if depends is None:
|
||||
depends = []
|
||||
@@ -679,20 +770,20 @@ class module_dependency(osv.osv):
|
||||
|
||||
_columns = {
|
||||
# The dependency name
|
||||
'name': fields.char('Name', size=128, select=True),
|
||||
'name': fields.char('Name', size=128, select=True),
|
||||
|
||||
# The module that depends on it
|
||||
'module_id': fields.many2one('ir.module.module', 'Module', select=True, ondelete='cascade'),
|
||||
|
||||
'state': fields.function(_state, type='selection', selection=[
|
||||
('uninstallable','Uninstallable'),
|
||||
('uninstalled','Not Installed'),
|
||||
('installed','Installed'),
|
||||
('to upgrade','To be upgraded'),
|
||||
('to remove','To be removed'),
|
||||
('to install','To be installed'),
|
||||
('uninstallable', 'Uninstallable'),
|
||||
('uninstalled', 'Not Installed'),
|
||||
('installed', 'Installed'),
|
||||
('to upgrade', 'To be upgraded'),
|
||||
('to remove', 'To be removed'),
|
||||
('to install', 'To be installed'),
|
||||
('unknown', 'Unknown'),
|
||||
], string='Status', readonly=True, select=True),
|
||||
], string='Status', readonly=True, select=True),
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Modules Categories -->
|
||||
|
||||
<record id="view_module_category_form" model="ir.ui.view">
|
||||
<field name="name">ir.module.category.form</field>
|
||||
<field name="model">ir.module.category</field>
|
||||
@@ -32,7 +30,6 @@
|
||||
</record>
|
||||
|
||||
<!-- Click on a category -->
|
||||
|
||||
<record id="view_module_filter" model="ir.ui.view">
|
||||
<field name="name">ir.module.module.list.select</field>
|
||||
<field name="model">ir.module.module</field>
|
||||
@@ -43,7 +40,7 @@
|
||||
<filter name="app" icon="terp-check" string="Apps" domain="[('application', '=', 1)]"/>
|
||||
<filter name="extra" icon="terp-check" string="Extra" domain="[('application', '=', 0)]"/>
|
||||
<separator/>
|
||||
<filter icon="terp-check" string="Installed" domain="[('state', 'in', ['installed', 'to upgrade', 'to remove'])]"/>
|
||||
<filter name="installed" icon="terp-check" string="Installed" domain="[('state', 'in', ['installed', 'to upgrade', 'to remove'])]"/>
|
||||
<filter icon="terp-dialog-close" string="Not Installed" domain="[('state', 'in', ['uninstalled', 'uninstallable', 'to install'])]"/>
|
||||
<field name="category_id"/>
|
||||
<group expand="0" string="Group By...">
|
||||
@@ -53,37 +50,6 @@
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="module_view_kanban">
|
||||
<field name="name">Modules Kanban</field>
|
||||
<field name="model">ir.module.module</field>
|
||||
<field name="arch" type="xml">
|
||||
<kanban create="false">
|
||||
<field name="icon"/>
|
||||
<field name="name"/>
|
||||
<field name="state"/>
|
||||
<field name="summary"/>
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div class="oe_module_vignette">
|
||||
<t t-set="installed" t-value="record.state.raw_value == 'installed'"/>
|
||||
<img t-attf-src="#{record.icon.value}" class="oe_module_icon"/>
|
||||
<div class="oe_module_desc">
|
||||
<h4><a type="open"><field name="shortdesc"/></a></h4>
|
||||
<p class="oe_module_name">
|
||||
<t t-if="record.summary.raw_value"><field name="summary"/><br/></t>
|
||||
<i><field name="name" groups="base.group_no_one"/></i>
|
||||
</p>
|
||||
<button type="object" name="button_immediate_install" states="uninstalled">Install</button>
|
||||
<button t-if="installed" disabled="disabled">Installed</button>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_module_open_categ" model="ir.actions.act_window">
|
||||
<field name="name">Modules</field>
|
||||
<field name="res_model">ir.module.module</field>
|
||||
@@ -100,7 +66,6 @@
|
||||
|
||||
|
||||
<!-- Modules -->
|
||||
|
||||
<record id="module_form" model="ir.ui.view">
|
||||
<field name="name">ir.module.module.form</field>
|
||||
<field name="model">ir.module.module</field>
|
||||
@@ -176,20 +141,74 @@
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="module_view_kanban">
|
||||
<field name="name">Modules Kanban</field>
|
||||
<field name="model">ir.module.module</field>
|
||||
<field name="arch" type="xml">
|
||||
<kanban create="false">
|
||||
<field name="icon"/>
|
||||
<field name="name"/>
|
||||
<field name="state"/>
|
||||
<field name="summary"/>
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div class="oe_module_vignette">
|
||||
<t t-set="installed" t-value="record.state.raw_value == 'installed'"/>
|
||||
<img t-attf-src="#{record.icon.value}" class="oe_module_icon"/>
|
||||
<div class="oe_module_desc">
|
||||
<h4><a type="open"><field name="shortdesc"/></a></h4>
|
||||
<p class="oe_module_name">
|
||||
<t t-if="record.summary.raw_value"><field name="summary"/><br/></t>
|
||||
<i><field name="name" groups="base.group_no_one"/></i>
|
||||
</p>
|
||||
<button type="object" name="button_immediate_install" states="uninstalled">Install</button>
|
||||
<button t-if="installed" disabled="disabled">Installed</button>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>
|
||||
</field>
|
||||
</record>
|
||||
<record id="open_module_tree" model="ir.actions.act_window">
|
||||
<field name="name">Install a Module</field>
|
||||
<!-- uncomment on released
|
||||
<field name="name">Installed Modules</field>
|
||||
-->
|
||||
<field name="name">Modules</field>
|
||||
<field name="res_model">ir.module.module</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">kanban,tree,form</field>
|
||||
<field name="context">{'search_default_app':1}</field>
|
||||
<!-- uncomment on released
|
||||
<field name="context">{'search_default_installed':1}</field>
|
||||
-->
|
||||
<field name="search_view_id" ref="view_module_filter"/>
|
||||
<field name="help" type="html">
|
||||
<p><b>No module found!</b></p>
|
||||
<p>You should try others search criteria.</p>
|
||||
</field>
|
||||
</record>
|
||||
<menuitem id="menu_module_tree" parent="base.menu_management" name="Modules"
|
||||
sequence="1" action="open_module_tree"/>
|
||||
<menuitem id="menu_module_tree" parent="menu_management" name="Installed Modules" sequence="10" action="open_module_tree"/>
|
||||
|
||||
|
||||
<!-- Apps modules -->
|
||||
<record model="ir.actions.client" id="modules_act_cl">
|
||||
<field name="name">Apps</field>
|
||||
<field name="tag">apps</field>
|
||||
</record>
|
||||
<!-- uncomment on released
|
||||
<menuitem id="module_mi" parent="base.menu_management" sequence="3" action="modules_act_cl"/>
|
||||
-->
|
||||
<menuitem id="module_mi" parent="base.menu_management" sequence="20" action="modules_act_cl"/>
|
||||
|
||||
<record model="ir.actions.client" id="modules_updates_act_cl">
|
||||
<field name="name">Updates</field>
|
||||
<field name="tag">apps.updates</field>
|
||||
<field name="params">{}</field>
|
||||
</record>
|
||||
<!-- uncomment on released
|
||||
<menuitem id="menu_module_updates" parent="base.menu_management" sequence="7" action="modules_updates_act_cl"/>
|
||||
-->
|
||||
<menuitem id="menu_module_updates" parent="base.menu_management" sequence="30" action="modules_updates_act_cl"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<document filename="test.pdf">
|
||||
<template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20">
|
||||
<template title="Test" allowSplitting="20">
|
||||
<pageTemplate id="first">
|
||||
<frame id="first" x1="42.0" y1="42.0" width="511" height="758"/>
|
||||
<header>
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<group states="choose" string="Export Settings">
|
||||
<field name="lang"/>
|
||||
<field name="format"/>
|
||||
<field name="modules"/>
|
||||
<field name="modules" widget="many2many_tags"/>
|
||||
</group>
|
||||
<div states="get">
|
||||
<h2>Export Complete</h2>
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
id="menu_view_base_module_import"
|
||||
parent="menu_management"
|
||||
groups="base.group_no_one"
|
||||
sequence="1"/>
|
||||
sequence="6"/>
|
||||
-->
|
||||
|
||||
</data>
|
||||
|
||||
@@ -18,17 +18,17 @@
|
||||
</group>
|
||||
<footer>
|
||||
<div states="init">
|
||||
<button name="update_module" string="Update" type="object" class="oe_highlight"/> or
|
||||
<button name="update_module" string="Update" type="object" class="oe_highlight"/> or
|
||||
<button special="cancel" string="Cancel" class="oe_link"/>
|
||||
</div>
|
||||
<div states="done">
|
||||
<button name="action_module_open" string="Open Modules" type="object" class="oe_highlight"/> or
|
||||
<button name="action_module_open" string="Open Modules" type="object" class="oe_highlight"/> or
|
||||
<button special="cancel" string="Close" class="oe_link"/>
|
||||
</div>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
</record>
|
||||
|
||||
<record id="action_view_base_module_update" model="ir.actions.act_window">
|
||||
<field name="name">Module Update</field>
|
||||
@@ -45,7 +45,7 @@
|
||||
id="menu_view_base_module_update"
|
||||
groups="base.group_no_one"
|
||||
parent="menu_management"
|
||||
sequence="2"
|
||||
sequence="40"
|
||||
icon="STOCK_CONVERT"/>
|
||||
|
||||
</data>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
groups="base.group_no_one"
|
||||
id="menu_view_base_module_upgrade"
|
||||
parent="menu_management"
|
||||
sequence="3"/>
|
||||
sequence="50"/>
|
||||
|
||||
<record id="view_base_module_upgrade_install" model="ir.ui.view">
|
||||
<field name="name">Module Upgrade Install</field>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<xsl:template name="rml">
|
||||
<document filename="example.pdf">
|
||||
<template pageSize="29.7cm,21cm" leftMargin="2.0cm" rightMargin="2.0cm" topMargin="2.0cm" bottomMargin="2.0cm" title="Report" author="Generated by Open ERP, Fabien Pinckaers" allowSplitting="20">
|
||||
<template leftMargin="2.0cm" rightMargin="2.0cm" topMargin="2.0cm" bottomMargin="2.0cm" title="Report" author="Generated by Open ERP, Fabien Pinckaers" allowSplitting="20">
|
||||
<pageTemplate id="first_page">
|
||||
<pageGraphics>
|
||||
<xsl:call-template name="first_page_graphics_corporation"/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0"?>
|
||||
<document filename="preview_report.pdf">
|
||||
<template pageSize="(595.0,842.0)" title="Preview Report" author="OpenERP S.A.(sales@openerp.com)" allowSplitting="20">
|
||||
<template title="Preview Report" author="OpenERP S.A.(sales@openerp.com)" allowSplitting="20">
|
||||
<pageTemplate id="first">
|
||||
<frame id="first" x1="57.0" y1="57.0" width="481" height="728"/>
|
||||
</pageTemplate>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
@@ -15,7 +15,7 @@
|
||||
# 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/>.
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
@@ -32,6 +32,7 @@ import res_lang
|
||||
import ir_property
|
||||
|
||||
import report
|
||||
import wizard
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ class res_company(osv.osv):
|
||||
'child_ids': fields.one2many('res.company', 'parent_id', 'Child Companies'),
|
||||
'partner_id': fields.many2one('res.partner', 'Partner', required=True),
|
||||
'rml_header': fields.text('RML Header', required=True),
|
||||
'rml_header1': fields.char('Company Slogan', size=200, help="Appears by default on the top right corner of your printed documents (report header)."),
|
||||
'rml_header1': fields.char('Company Tagline', size=200, help="Appears by default on the top right corner of your printed documents (report header)."),
|
||||
'rml_header2': fields.text('RML Internal Header', required=True),
|
||||
'rml_header3': fields.text('RML Internal Header for Landscape Reports', required=True),
|
||||
'rml_footer': fields.text('Report Footer', help="Footer text displayed at the bottom of all reports."),
|
||||
@@ -330,7 +330,7 @@ class res_company(osv.osv):
|
||||
<!-- left margin -->
|
||||
<rotate degrees="90"/>
|
||||
<fill color="grey"/>
|
||||
<drawString x="2.65cm" y="-0.4cm">produced by OpenERP.com</drawString>
|
||||
<drawString x="2.65cm" y="-0.4cm">generated by OpenERP.com</drawString>
|
||||
<fill color="black"/>
|
||||
<rotate degrees="-90"/>
|
||||
|
||||
@@ -345,7 +345,7 @@ class res_company(osv.osv):
|
||||
</header>"""
|
||||
|
||||
_header_a4 = _header_main % ('23.0cm', '27.6cm', '27.7cm', '27.7cm', '27.8cm', '27.4cm', '25.8cm', '26.0cm', '26.0cm', '25.6cm', '25.6cm', '25.5cm', '25.5cm')
|
||||
_header_letter = _header_main % ('21.3cm', '25.9cm', '26.0cm', '26.0cm', '26.1cm', '25.5cm', '25.1cm', '24.3cm', '24.3cm', '23.9cm', '23.9cm', '23.8cm', '23.8cm')
|
||||
_header_letter = _header_main % ('21.3cm', '25.9cm', '26.0cm', '26.0cm', '26.1cm', '25.7cm', '24.1cm', '24.3cm', '24.3cm', '23.9cm', '23.9cm', '23.8cm', '23.8cm')
|
||||
|
||||
def onchange_paper_format(self, cr, uid, ids, paper_format, context=None):
|
||||
if paper_format == 'us_letter':
|
||||
|
||||
@@ -32,6 +32,11 @@
|
||||
<field name="name" class="oe_inline"/>
|
||||
</h1>
|
||||
</div>
|
||||
<div attrs="{'invisible' : [('logo','!=',False)]}" class="oe_view_nocontent oe_clear">
|
||||
<p class="oe_view_nocontent_create">
|
||||
Click to set your company logo.
|
||||
</p>
|
||||
</div>
|
||||
<group col="4">
|
||||
<field name="parent_id" groups="base.group_multi_company"/>
|
||||
</group>
|
||||
|
||||
@@ -466,7 +466,8 @@ class res_config_settings(osv.osv_memory):
|
||||
groups.append((name, ref(field_group), ref(field.implied_group)))
|
||||
elif name.startswith('module_') and isinstance(field, fields.boolean):
|
||||
mod_ids = ir_module.search(cr, uid, [('name', '=', name[7:])])
|
||||
modules.append((name, ir_module.browse(cr, uid, mod_ids[0], context)))
|
||||
record = ir_module.browse(cr, uid, mod_ids[0], context) if mod_ids else None
|
||||
modules.append((name, record))
|
||||
else:
|
||||
others.append(name)
|
||||
|
||||
@@ -490,7 +491,7 @@ class res_config_settings(osv.osv_memory):
|
||||
|
||||
# modules: which modules are installed/to install
|
||||
for name, module in classified['module']:
|
||||
res[name] = module.state in ('installed', 'to install', 'to upgrade')
|
||||
res[name] = module and module.state in ('installed', 'to install', 'to upgrade')
|
||||
|
||||
# other fields: call all methods that start with 'get_default_'
|
||||
for method in dir(self):
|
||||
@@ -501,9 +502,7 @@ class res_config_settings(osv.osv_memory):
|
||||
|
||||
def execute(self, cr, uid, ids, context=None):
|
||||
ir_values = self.pool.get('ir.values')
|
||||
ir_model_data = self.pool.get('ir.model.data')
|
||||
ir_module = self.pool.get('ir.module.module')
|
||||
res_groups = self.pool.get('res.groups')
|
||||
classified = self._get_classified_fields(cr, uid, context)
|
||||
|
||||
config = self.browse(cr, uid, ids[0], context)
|
||||
@@ -526,18 +525,34 @@ class res_config_settings(osv.osv_memory):
|
||||
getattr(self, method)(cr, uid, ids, context)
|
||||
|
||||
# module fields: install/uninstall the selected modules
|
||||
to_install_ids = []
|
||||
to_install_missing_names = []
|
||||
to_uninstall_ids = []
|
||||
to_install_ids = []
|
||||
lm = len('module_')
|
||||
for name, module in classified['module']:
|
||||
if config[name]:
|
||||
if module.state == 'uninstalled': to_install_ids.append(module.id)
|
||||
if not module:
|
||||
# missing module, will be provided by apps.openerp.com
|
||||
to_install_missing_names.append(name[lm:])
|
||||
elif module.state == 'uninstalled':
|
||||
# local module, to be installed
|
||||
to_install_ids.append(module.id)
|
||||
else:
|
||||
if module.state in ('installed','upgrade'): to_uninstall_ids.append(module.id)
|
||||
if module and module.state in ('installed', 'to upgrade'):
|
||||
to_uninstall_ids.append(module.id)
|
||||
|
||||
if to_install_ids or to_uninstall_ids:
|
||||
ir_module.button_uninstall(cr, uid, to_uninstall_ids, context=context)
|
||||
if to_uninstall_ids:
|
||||
ir_module.button_immediate_uninstall(cr, uid, to_uninstall_ids, context=context)
|
||||
if to_install_ids:
|
||||
ir_module.button_immediate_install(cr, uid, to_install_ids, context=context)
|
||||
|
||||
if to_install_missing_names:
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'apps',
|
||||
'params': {'modules': to_install_missing_names},
|
||||
}
|
||||
|
||||
config = self.pool.get('res.config').next(cr, uid, [], context=context) or {}
|
||||
if config.get('type') not in ('ir.actions.act_window_close',):
|
||||
return config
|
||||
|
||||
@@ -187,6 +187,12 @@ class res_partner(osv.osv, format_address):
|
||||
def _set_image(self, cr, uid, id, name, value, args, context=None):
|
||||
return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context)
|
||||
|
||||
def _has_image(self, cr, uid, ids, name, args, context=None):
|
||||
result = {}
|
||||
for obj in self.browse(cr, uid, ids, context=context):
|
||||
result[obj.id] = obj.image != False
|
||||
return result
|
||||
|
||||
_order = "name"
|
||||
_columns = {
|
||||
'name': fields.char('Name', size=128, required=True, select=True),
|
||||
@@ -253,6 +259,7 @@ class res_partner(osv.osv, format_address):
|
||||
help="Small-sized image of this contact. It is automatically "\
|
||||
"resized as a 64x64px image, with aspect ratio preserved. "\
|
||||
"Use this field anywhere a small image is required."),
|
||||
'has_image': fields.function(_has_image, type="boolean"),
|
||||
'company_id': fields.many2one('res.company', 'Company', select=1),
|
||||
'color': fields.integer('Color Index'),
|
||||
'user_ids': fields.one2many('res.users', 'partner_id', 'Users'),
|
||||
@@ -297,7 +304,7 @@ class res_partner(osv.osv, format_address):
|
||||
'is_company': False,
|
||||
'type': 'default',
|
||||
'use_parent_address': True,
|
||||
'image': lambda self, cr, uid, ctx: self._get_default_image(cr, uid, ctx.get('default_is_company', False), ctx),
|
||||
'image': False,
|
||||
}
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
@@ -308,8 +315,7 @@ class res_partner(osv.osv, format_address):
|
||||
return super(res_partner, self).copy(cr, uid, id, default, context)
|
||||
|
||||
def onchange_type(self, cr, uid, ids, is_company, context=None):
|
||||
# get value as for an onchange on the image
|
||||
value = tools.image_get_resized_images(self._get_default_image(cr, uid, is_company, context), return_big=True, return_medium=False, return_small=False)
|
||||
value = {}
|
||||
value['title'] = False
|
||||
if is_company:
|
||||
value['parent_id'] = False
|
||||
@@ -402,6 +408,8 @@ class res_partner(osv.osv, format_address):
|
||||
name = name + "\n" + self._display_address(cr, uid, record, without_company=True, context=context)
|
||||
name = name.replace('\n\n','\n')
|
||||
name = name.replace('\n\n','\n')
|
||||
if context.get('show_email') and record.email:
|
||||
name = "%s <%s>" % (name, record.email)
|
||||
res.append((record.id, name))
|
||||
return res
|
||||
|
||||
@@ -437,18 +445,23 @@ class res_partner(osv.osv, format_address):
|
||||
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
|
||||
if not args:
|
||||
args = []
|
||||
if name and operator in ('=', 'ilike', '=ilike', 'like'):
|
||||
if name and operator in ('=', 'ilike', '=ilike', 'like', '=like'):
|
||||
# search on the name of the contacts and of its company
|
||||
name2 = operator == '=' and name or '%' + name + '%'
|
||||
search_name = name
|
||||
if operator in ('ilike', 'like'):
|
||||
search_name = '%%%s%%' % name
|
||||
if operator in ('=ilike', '=like'):
|
||||
operator = operator[1:]
|
||||
query_args = {'name': search_name}
|
||||
limit_str = ''
|
||||
query_args = [name2]
|
||||
if limit:
|
||||
limit_str = ' limit %s'
|
||||
query_args += [limit]
|
||||
limit_str = ' limit %(limit)s'
|
||||
query_args['limit'] = limit
|
||||
cr.execute('''SELECT partner.id FROM res_partner partner
|
||||
LEFT JOIN res_partner company ON partner.parent_id = company.id
|
||||
WHERE partner.name || ' (' || COALESCE(company.name,'') || ')'
|
||||
''' + operator + ''' %s ''' + limit_str, query_args)
|
||||
WHERE partner.email ''' + operator +''' %(name)s
|
||||
OR partner.name || ' (' || COALESCE(company.name,'') || ')'
|
||||
''' + operator + ' %(name)s ' + limit_str, query_args)
|
||||
ids = map(lambda x: x[0], cr.fetchall())
|
||||
if args:
|
||||
ids = self.search(cr, uid, [('id', 'in', ids)] + args, limit=limit, context=context)
|
||||
|
||||
@@ -196,12 +196,13 @@
|
||||
<field name="phone"/>
|
||||
<field name="street"/>
|
||||
<field name="street2"/>
|
||||
<field name="image"/>
|
||||
<field name="zip"/>
|
||||
<field name="city"/>
|
||||
<field name="country_id"/>
|
||||
<field name="mobile"/>
|
||||
<field name="fax"/>
|
||||
<field name="state_id"/>
|
||||
<field name="has_image"/>
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<t t-set="color" t-value="kanban_color(record.color.raw_value)"/>
|
||||
@@ -209,7 +210,17 @@
|
||||
<a t-if="! read_only_mode" type="delete" style="position: absolute; right: 0; padding: 4px; diplay: inline-block">X</a>
|
||||
<div class="oe_module_vignette">
|
||||
<a type="open">
|
||||
<img t-att-src="kanban_image('res.partner', 'image', record.id.value, {'preview_image': 'image_small'})" class="oe_avatar oe_kanban_avatar_smallbox"/>
|
||||
<t t-if="record.has_image.raw_value === true">
|
||||
<img t-att-src="kanban_image('res.partner', 'image', record.id.value, {'preview_image': 'image_small'})" class="oe_avatar oe_kanban_avatar_smallbox"/>
|
||||
</t>
|
||||
<t t-if="record.has_image.raw_value === false">
|
||||
<t t-if="record.is_company.raw_value === true">
|
||||
<img t-att-src='_s + "/base/static/src/img/company_image.png"' class="oe_kanban_image"/>
|
||||
</t>
|
||||
<t t-if="record.is_company.raw_value === false">
|
||||
<img t-att-src='_s + "/base/static/src/img/avatar.png"' class="oe_kanban_image"/>
|
||||
</t>
|
||||
</t>
|
||||
</a>
|
||||
<div class="oe_module_desc">
|
||||
<div class="oe_kanban_box_content oe_kanban_color_bglight oe_kanban_color_border">
|
||||
@@ -222,6 +233,9 @@
|
||||
<div><a t-if="record.email.raw_value" title="Mail" t-att-href="'mailto:'+record.email.value">
|
||||
<field name="email"/>
|
||||
</a></div>
|
||||
<div t-if="record.phone.raw_value">Phone: <field name="phone"/></div>
|
||||
<div t-if="record.mobile.raw_value">Mobile: <field name="mobile"/></div>
|
||||
<div t-if="record.fax.raw_value">Fax: <field name="fax"/></div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -285,8 +299,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<search string="Search Partner">
|
||||
<field name="name"
|
||||
filter_domain="['|','|',('name','ilike',self),('parent_id','ilike',self),('ref','=',self)]"
|
||||
string="Partner"/>
|
||||
filter_domain="['|','|',('name','ilike',self),('parent_id','ilike',self),('ref','=',self)]"/>
|
||||
<filter help="My Partners" icon="terp-personal+" domain="[('user_id','=',uid)]"/>
|
||||
<separator/>
|
||||
<filter string="Persons" name="type_person" icon="terp-personal" domain="[('is_company','=',0)]"/>
|
||||
@@ -328,11 +341,22 @@
|
||||
<field name="mobile"/>
|
||||
<field name="state_id"/>
|
||||
<field name="category_id"/>
|
||||
<field name="has_image"/>
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div class="oe_kanban_vignette oe_semantic_html_override">
|
||||
<a type="open">
|
||||
<img t-att-src="kanban_image('res.partner', 'image_small', record.id.value)" class="oe_kanban_image"/>
|
||||
<t t-if="record.has_image.raw_value === true">
|
||||
<img t-att-src="kanban_image('res.partner', 'image_small', record.id.value)" class="oe_kanban_image"/>
|
||||
</t>
|
||||
<t t-if="record.has_image.raw_value === false">
|
||||
<t t-if="record.is_company.raw_value === true">
|
||||
<img t-att-src='_s + "/base/static/src/img/company_image.png"' class="oe_kanban_image"/>
|
||||
</t>
|
||||
<t t-if="record.is_company.raw_value === false">
|
||||
<img t-att-src='_s + "/base/static/src/img/avatar.png"' class="oe_kanban_image"/>
|
||||
</t>
|
||||
</t>
|
||||
</a>
|
||||
<div class="oe_kanban_details">
|
||||
<h4 class="oe_partner_heading"><a type="open"><field name="name"/></a></h4>
|
||||
|
||||
@@ -136,6 +136,10 @@
|
||||
<form string="Users" version="7.0">
|
||||
<field name="id" invisible="1"/>
|
||||
<sheet>
|
||||
<div class="oe_right oe_button_box">
|
||||
<button string="Change Password" type="action" name="%(change_password_wizard_action)d"
|
||||
help="Change the user password."/>
|
||||
</div>
|
||||
<field name="image" widget='image' class="oe_avatar oe_left" options='{"preview_image": "image_medium"}'/>
|
||||
<div class="oe_title">
|
||||
<label for="name" class="oe_edit_only"/>
|
||||
@@ -145,7 +149,6 @@
|
||||
</div>
|
||||
<group>
|
||||
<group>
|
||||
<field name="new_password" password="True" attrs="{'required': [('id','=',False)]}"/>
|
||||
<field name="company_id" context="{'user_preference': 0}"/>
|
||||
</group>
|
||||
<group>
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2011 OpenERP S.A (<http://www.openerp.com>).
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import change_password_wizard
|
||||
@@ -0,0 +1,81 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2011 OpenERP S.A (<http://www.openerp.com>).
|
||||
#
|
||||
# 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 openerp.osv import fields, osv
|
||||
|
||||
class change_password_wizard(osv.TransientModel):
|
||||
"""
|
||||
A wizard to manage the change of users' passwords
|
||||
"""
|
||||
|
||||
_name = "change.password.wizard"
|
||||
_description = "Change Password Wizard"
|
||||
_columns = {
|
||||
'user_ids': fields.one2many('change.password.user', 'wizard_id', string='Users'),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
if context == None:
|
||||
context = {}
|
||||
user_ids = context.get('active_ids', [])
|
||||
wiz_id = context.get('active_id', None)
|
||||
res = []
|
||||
users = self.pool.get('res.users').browse(cr, uid, user_ids, context=context)
|
||||
for user in users:
|
||||
res.append((0, 0, {
|
||||
'wizard_id': wiz_id,
|
||||
'user_id': user.id,
|
||||
'user_login': user.login,
|
||||
}))
|
||||
return {'user_ids': res}
|
||||
|
||||
|
||||
def change_password_button(self, cr, uid, id, context=None):
|
||||
wizard = self.browse(cr, uid, id, context=context)[0]
|
||||
user_ids = []
|
||||
for user in wizard.user_ids:
|
||||
user_ids.append(user.id)
|
||||
self.pool.get('change.password.user').change_password_button(cr, uid, user_ids, context=context)
|
||||
return {
|
||||
'type': 'ir.actions.act_window_close',
|
||||
}
|
||||
|
||||
class change_password_user(osv.TransientModel):
|
||||
"""
|
||||
A model to configure users in the change password wizard
|
||||
"""
|
||||
|
||||
_name = 'change.password.user'
|
||||
_description = 'Change Password Wizard User'
|
||||
_columns = {
|
||||
'wizard_id': fields.many2one('change.password.wizard', string='Wizard', required=True),
|
||||
'user_id': fields.many2one('res.users', string='User', required=True),
|
||||
'user_login': fields.char('User Login', readonly=True),
|
||||
'new_passwd': fields.char('New Password'),
|
||||
}
|
||||
_defaults = {
|
||||
'new_passwd': '',
|
||||
}
|
||||
|
||||
def change_password_button(self, cr, uid, ids, context=None):
|
||||
for user in self.browse(cr, uid, ids, context=context):
|
||||
self.pool.get('res.users').write(cr, uid, user.user_id.id, {'password': user.new_passwd})
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- wizard action on res.users -->
|
||||
<act_window id="change_password_wizard_action"
|
||||
name="Change Password"
|
||||
src_model="res.users"
|
||||
res_model="change.password.wizard"
|
||||
view_type="form" view_mode="form"
|
||||
key2="client_action_multi" target="new"
|
||||
groups="base.group_erp_manager"/>
|
||||
|
||||
<!-- wizard view -->
|
||||
<record id="change_password_wizard_view" model="ir.ui.view">
|
||||
<field name="name">Change Password</field>
|
||||
<field name="model">change.password.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Change Password" version="7.0">
|
||||
<field name="user_ids"/>
|
||||
<footer>
|
||||
<button string="Change Password" name="change_password_button" type="object" class="oe_highlight"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- wizard user list view -->
|
||||
<record id="change_password_wizard_user_tree_view" model="ir.ui.view">
|
||||
<field name="name">Change Password Users</field>
|
||||
<field name="model">change.password.user</field>
|
||||
<field name="arch" type="xml">
|
||||
<!-- the user list is editable, but one cannot add or delete rows -->
|
||||
<tree string="Users" editable="bottom" create="false" delete="false">
|
||||
<field name="user_login"/>
|
||||
<field name="new_passwd" required="True"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -0,0 +1,117 @@
|
||||
openerp.base = function(instance) {
|
||||
|
||||
instance.base.apps_remote = null;
|
||||
instance.base.apps_client = null;
|
||||
|
||||
instance.base.Apps = instance.web.Widget.extend({
|
||||
template: 'EmptyComponent',
|
||||
remote_action_id: 'loempia.action_embed',
|
||||
failback_action_id: 'base.open_module_tree',
|
||||
|
||||
init: function(parent, action) {
|
||||
this._super(parent, action);
|
||||
var options = action.params || {};
|
||||
|
||||
if (options.apps_user) {
|
||||
sessionStorage.setItem('apps.login', options.apps_user);
|
||||
}
|
||||
if (options.apps_access_token) {
|
||||
sessionStorage.setItem('apps.access_token', options.apps_access_token);
|
||||
}
|
||||
|
||||
this.params = options; // NOTE read by embedded client action
|
||||
},
|
||||
|
||||
get_client: function() {
|
||||
// return the client via a deferred, resolved or rejected depending if the remote host is available or not.
|
||||
var check_client_available = function(client) {
|
||||
var d = $.Deferred();
|
||||
var i = new Image();
|
||||
i.onerror = function() {
|
||||
d.reject(client);
|
||||
};
|
||||
i.onload = function() {
|
||||
client.session.session_bind(client.origin).then(function() {
|
||||
// check if client can authenticate
|
||||
client.authenticate().then(
|
||||
function() { /* done */
|
||||
d.resolve(client);
|
||||
}, function() { /* fail */
|
||||
if (client.login === 'anonymous') {
|
||||
d.reject(client);
|
||||
} else {
|
||||
sessionStorage.removeItem('apps.login');
|
||||
sessionStorage.removeItem('apps.access_token');
|
||||
client.bind_crendentials(client.dbname, 'anonymous', 'anonymous');
|
||||
client.authenticate().then(
|
||||
function() { /* done */
|
||||
d.resolve(client);
|
||||
}, function() { /* fail */
|
||||
d.reject(client);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
};
|
||||
i.src = _.str.sprintf('%s/web/static/src/img/sep-a.gif', client.origin);
|
||||
return d.promise();
|
||||
};
|
||||
if (instance.base.apps_client) {
|
||||
return check_client_available(instance.base.apps_client);
|
||||
} else {
|
||||
var ICP = new instance.web.Model('ir.config_parameter');
|
||||
return ICP.call('get_param', ['apps.server', 'https://apps.openerp.com/apps']).then(function(u) {
|
||||
var link = $(_.str.sprintf('<a href="%s"></a>', u))[0];
|
||||
var host = _.str.sprintf('%s//%s', link.protocol, link.host);
|
||||
var dbname = link.pathname;
|
||||
if (dbname[0] === '/') {
|
||||
dbname = dbname.substr(1);
|
||||
}
|
||||
var login = (sessionStorage ? sessionStorage.getItem('apps.login') : null) || 'anonymous';
|
||||
var passwd = (sessionStorage ? sessionStorage.getItem('apps.access_token') : null) || 'anonymous';
|
||||
if (_.isNull(instance.base.apps_remote)) {
|
||||
instance.base.apps_remote = new openerp.init();
|
||||
}
|
||||
var client = new instance.base.apps_remote.web.EmbeddedClient(null, host, dbname, login, passwd);
|
||||
instance.base.apps_client = client;
|
||||
return check_client_available(client);
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
if (instance.base.apps_client) {
|
||||
instance.base.apps_client.destroy();
|
||||
}
|
||||
return this._super();
|
||||
},
|
||||
|
||||
start: function() {
|
||||
var self = this;
|
||||
return self.get_client().
|
||||
done(function(client) {
|
||||
client.replace(self.$el).
|
||||
done(function() {
|
||||
client.$el.removeClass('openerp');
|
||||
client.do_action(self.remote_action_id);
|
||||
});
|
||||
}).
|
||||
fail(function(client) {
|
||||
self.do_warn('Apps Server not reachable.', 'Showing local modules.', true);
|
||||
self.rpc('/web/action/load', {action_id: self.failback_action_id}).done(function(action) {
|
||||
self.do_action(action);
|
||||
instance.webclient.menu.open_action(action.id);
|
||||
});
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
instance.base.AppsUpdates = instance.base.Apps.extend({
|
||||
remote_action_id: 'loempia.action_embed_updates'
|
||||
});
|
||||
|
||||
instance.web.client_actions.add("apps", "instance.base.Apps");
|
||||
instance.web.client_actions.add("apps.updates", "instance.base.AppsUpdates");
|
||||
|
||||
};
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!--
|
||||
Assert:
|
||||
-->
|
||||
|
||||
<assert model="res.request" id="res_partner_asustek_request" string="Reference field request returns a browsable object">
|
||||
<test expr="ref_doc1.name">ASUSTeK</test>
|
||||
</assert>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,116 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2011-TODAY OpenERP S.A. <http://www.openerp.com>
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
import openerp
|
||||
|
||||
JOB = {
|
||||
'function': u'_0_seconds',
|
||||
'interval_type': u'minutes',
|
||||
'user_id': 1,
|
||||
'name': u'test',
|
||||
'args': False,
|
||||
'numbercall': 1,
|
||||
'nextcall': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'priority': 5,
|
||||
'doall': True,
|
||||
'active': True,
|
||||
'interval_number': 1,
|
||||
'model': u'ir.cron'
|
||||
}
|
||||
|
||||
class test_ir_cron(openerp.osv.osv.osv):
|
||||
""" Add a few handy methods to test cron jobs scheduling. """
|
||||
_inherit = "ir.cron"
|
||||
|
||||
def _0_seconds(a, b, c):
|
||||
print ">>> _0_seconds"
|
||||
|
||||
def _20_seconds(self, cr, uid):
|
||||
print ">>> in _20_seconds"
|
||||
time.sleep(20)
|
||||
print ">>> out _20_seconds"
|
||||
|
||||
def _80_seconds(self, cr, uid):
|
||||
print ">>> in _80_seconds"
|
||||
time.sleep(80)
|
||||
print ">>> out _80_seconds"
|
||||
|
||||
def test_0(self, cr, uid):
|
||||
now = datetime.now()
|
||||
t1 = (now + relativedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
t2 = (now + relativedelta(minutes=1, seconds=5)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
t3 = (now + relativedelta(minutes=1, seconds=10)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
self.create(cr, uid, dict(JOB, name='test_0 _20_seconds A', function='_20_seconds', nextcall=t1))
|
||||
self.create(cr, uid, dict(JOB, name='test_0 _20_seconds B', function='_20_seconds', nextcall=t2))
|
||||
self.create(cr, uid, dict(JOB, name='test_0 _20_seconds C', function='_20_seconds', nextcall=t3))
|
||||
|
||||
def test_1(self, cr, uid):
|
||||
now = datetime.now()
|
||||
t1 = (now + relativedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
self.create(cr, uid, dict(JOB, name='test_1 _20_seconds * 3', function='_20_seconds', nextcall=t1, numbercall=3))
|
||||
|
||||
def test_2(self, cr, uid):
|
||||
now = datetime.now()
|
||||
t1 = (now + relativedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
self.create(cr, uid, dict(JOB, name='test_2 _80_seconds * 2', function='_80_seconds', nextcall=t1, numbercall=2))
|
||||
|
||||
def test_3(self, cr, uid):
|
||||
now = datetime.now()
|
||||
t1 = (now + relativedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
t2 = (now + relativedelta(minutes=1, seconds=5)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
t3 = (now + relativedelta(minutes=1, seconds=10)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
self.create(cr, uid, dict(JOB, name='test_3 _80_seconds A', function='_80_seconds', nextcall=t1))
|
||||
self.create(cr, uid, dict(JOB, name='test_3 _20_seconds B', function='_20_seconds', nextcall=t2))
|
||||
self.create(cr, uid, dict(JOB, name='test_3 _20_seconds C', function='_20_seconds', nextcall=t3))
|
||||
|
||||
# This test assumes 4 cron threads.
|
||||
def test_00(self, cr, uid):
|
||||
self.test_00_set = set()
|
||||
now = datetime.now()
|
||||
t1 = (now + relativedelta(minutes=1)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
t2 = (now + relativedelta(minutes=1, seconds=5)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
t3 = (now + relativedelta(minutes=1, seconds=10)).strftime('%Y-%m-%d %H:%M:%S')
|
||||
self.create(cr, uid, dict(JOB, name='test_00 _20_seconds_A', function='_20_seconds_A', nextcall=t1))
|
||||
self.create(cr, uid, dict(JOB, name='test_00 _20_seconds_B', function='_20_seconds_B', nextcall=t2))
|
||||
self.create(cr, uid, dict(JOB, name='test_00 _20_seconds_C', function='_20_seconds_C', nextcall=t3))
|
||||
|
||||
def _expect(self, cr, uid, to_add, to_sleep, to_expect_in, to_expect_out):
|
||||
assert self.test_00_set == to_expect_in
|
||||
self.test_00_set.add(to_add)
|
||||
time.sleep(to_sleep)
|
||||
self.test_00_set.discard(to_add)
|
||||
assert self.test_00_set == to_expect_out
|
||||
|
||||
def _20_seconds_A(self, cr, uid):
|
||||
self._expect(cr, uid, 'A', 20, set(), set(['B', 'C']))
|
||||
|
||||
def _20_seconds_B(self, cr, uid):
|
||||
self._expect(cr, uid, 'B', 20, set('A'), set('C'))
|
||||
|
||||
def _20_seconds_C(self, cr, uid):
|
||||
self._expect(cr, uid, 'C', 20, set(['A', 'B']), set())
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
-
|
||||
Test the cron jobs scheduling.
|
||||
-
|
||||
Disable the existing cron jobs if any during the tests.
|
||||
-
|
||||
!python {model: ir.cron }: |
|
||||
# For this test to work, as it involves multiple database cursors,
|
||||
# we have to commit changes. But YAML tests must be rollbacked, so
|
||||
# the final database state is left untouched. So we have to be a bit
|
||||
# ugly here: use our own cursor, commit, and clean after ourselves.
|
||||
# We also pass around some ids using setattr/delattr, and we have to
|
||||
# rollback the previous tests otherwise we won't be able to touch the
|
||||
# db.
|
||||
# Well, this should probably be a standalone, or regular unit test,
|
||||
# instead of using the YAML infrastructure.
|
||||
cr.rollback()
|
||||
our_cr = self.pool.db.cursor()
|
||||
try:
|
||||
ids = self.search(our_cr, uid, [], {})
|
||||
setattr(self, 'saved_ids', ids)
|
||||
self.write(our_cr, uid, ids, {'active': False}, {})
|
||||
our_cr.commit()
|
||||
finally:
|
||||
our_cr.close()
|
||||
-
|
||||
Three concurrent jobs started with a slight time gap. Assume 4 cron threads.
|
||||
This will take about 2 minutes.
|
||||
-
|
||||
!python {model: ir.cron }: |
|
||||
# Pretend initialization is already done. We the use a try/finally
|
||||
# to reset _init correctly.
|
||||
self.pool._init = False
|
||||
our_cr = self.pool.db.cursor()
|
||||
try:
|
||||
self.test_00(our_cr, uid) # this will commit using the passed cursor
|
||||
import openerp.cron
|
||||
openerp.cron._thread_slots = 4
|
||||
# Wake up this db as soon as the master cron thread starts.
|
||||
openerp.cron.schedule_wakeup(1, self.pool.db.dbname)
|
||||
# Pretend to be the master thread, for 4 iterations.
|
||||
openerp.cron.runner_body()
|
||||
openerp.cron.runner_body()
|
||||
openerp.cron.runner_body()
|
||||
openerp.cron.runner_body()
|
||||
finally:
|
||||
self.pool._init = True
|
||||
our_cr.close()
|
||||
-
|
||||
Clean after ourselves.
|
||||
-
|
||||
!python {model: ir.cron }: |
|
||||
our_cr = self.pool.db.cursor()
|
||||
try:
|
||||
ids = [x for x in self.search(our_cr, uid, ['|', ('active', '=', True), ('active', '=', False)], {}) if x not in self.saved_ids]
|
||||
self.unlink(our_cr, uid, ids, {})
|
||||
ids = self.saved_ids
|
||||
delattr(self, 'saved_ids')
|
||||
self.write(our_cr, uid, ids, {'active': True}, {})
|
||||
our_cr.commit()
|
||||
finally:
|
||||
our_cr.close()
|
||||
@@ -1,9 +1,15 @@
|
||||
import test_base, test_expression, test_search, test_ir_values, test_menu
|
||||
import test_base
|
||||
import test_expression
|
||||
import test_ir_attachment
|
||||
import test_ir_values
|
||||
import test_menu
|
||||
import test_search
|
||||
|
||||
checks = [
|
||||
test_base,
|
||||
test_expression,
|
||||
test_search,
|
||||
test_ir_attachment,
|
||||
test_ir_values,
|
||||
test_menu,
|
||||
test_search,
|
||||
]
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
import unittest2
|
||||
|
||||
import openerp
|
||||
import openerp.tests.common
|
||||
|
||||
class test_ir_attachment(openerp.tests.common.TransactionCase):
|
||||
|
||||
def test_00_attachment_flow(self):
|
||||
registry, cr, uid = self.registry, self.cr, self.uid
|
||||
root_path = openerp.tools.config['root_path']
|
||||
ira = registry('ir.attachment')
|
||||
|
||||
# Blob1
|
||||
blob1 = 'blob1'
|
||||
blob1_b64 = blob1.encode('base64')
|
||||
blob1_hash = hashlib.sha1(blob1).hexdigest()
|
||||
blob1_fname = blob1_hash[:3] + '/' + blob1_hash
|
||||
|
||||
# Blob2
|
||||
blob2 = 'blob2'
|
||||
blob2_b64 = blob2.encode('base64')
|
||||
blob2_hash = hashlib.sha1(blob2).hexdigest()
|
||||
blob2_fname = blob2_hash[:3] + '/' + blob2_hash
|
||||
|
||||
# 'ir_attachment.location' is undefined test database storage
|
||||
a1 = ira.create(cr, uid, {'name': 'a1', 'datas': blob1_b64})
|
||||
a1_read = ira.read(cr, uid, [a1], ['datas'])
|
||||
self.assertEqual(a1_read[0]['datas'], blob1_b64)
|
||||
|
||||
cr.execute("select id,db_datas from ir_attachment where id = %s", (a1,) )
|
||||
a1_db_datas = str(cr.fetchall()[0][1])
|
||||
self.assertEqual(a1_db_datas, blob1_b64)
|
||||
|
||||
# define a location for filestore
|
||||
registry('ir.config_parameter').set_param(cr, uid, 'ir_attachment.location', 'file:///filestore')
|
||||
|
||||
# Test file storage
|
||||
a2 = ira.create(cr, uid, {'name': 'a2', 'datas': blob1_b64})
|
||||
a2_read = ira.read(cr, uid, [a2], ['datas'])
|
||||
self.assertEqual(a2_read[0]['datas'], blob1_b64)
|
||||
|
||||
cr.execute("select id,store_fname from ir_attachment where id = %s", (a2,) )
|
||||
a2_store_fname = cr.fetchall()[0][1]
|
||||
self.assertEqual(a2_store_fname, blob1_fname)
|
||||
|
||||
a2_fn = os.path.join(root_path, 'filestore', cr.dbname, blob1_hash[:3], blob1_hash)
|
||||
fc = file(a2_fn).read()
|
||||
self.assertEqual(fc, blob1)
|
||||
|
||||
# create a3 with same blob
|
||||
a3 = ira.create(cr, uid, {'name': 'a3', 'datas': blob1_b64})
|
||||
a3_read = ira.read(cr, uid, [a3], ['datas'])
|
||||
self.assertEqual(a3_read[0]['datas'], blob1_b64)
|
||||
|
||||
cr.execute("select id,store_fname from ir_attachment where id = %s", (a3,) )
|
||||
a3_store_fname = cr.fetchall()[0][1]
|
||||
self.assertEqual(a3_store_fname, a2_store_fname)
|
||||
|
||||
# create a4 blob2
|
||||
a4 = ira.create(cr, uid, {'name': 'a4', 'datas': blob2_b64})
|
||||
a4_read = ira.read(cr, uid, [a4], ['datas'])
|
||||
self.assertEqual(a4_read[0]['datas'], blob2_b64)
|
||||
|
||||
a4_fn = os.path.join(root_path, 'filestore', cr.dbname, blob2_hash[:3], blob2_hash)
|
||||
self.assertTrue(os.path.isfile(a4_fn))
|
||||
|
||||
# delete a3 but file stays
|
||||
ira.unlink(cr, uid, [a3])
|
||||
self.assertTrue(os.path.isfile(a2_fn))
|
||||
|
||||
# delete a2 it is unlinked
|
||||
ira.unlink(cr, uid, [a2])
|
||||
self.assertFalse(os.path.isfile(a2_fn))
|
||||
|
||||
# update a4 blob2 by blob1
|
||||
ira.write(cr, uid, [a4], {'datas': blob1_b64})
|
||||
a4_read = ira.read(cr, uid, [a4], ['datas'])
|
||||
self.assertEqual(a4_read[0]['datas'], blob1_b64)
|
||||
|
||||
# file of a4 disapear and a2 reappear
|
||||
self.assertFalse(os.path.isfile(a4_fn))
|
||||
self.assertTrue(os.path.isfile(a2_fn))
|
||||
|
||||
# everybody applause
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user