diff --git a/addons/account/installer.py b/addons/account/installer.py index 961b8f9e763..343e22a7632 100644 --- a/addons/account/installer.py +++ b/addons/account/installer.py @@ -47,7 +47,7 @@ class account_installer(osv.osv_memory): # try get the list on apps server try: - apps_server = self.pool.get('ir.config_parameter').get_param(cr, uid, 'apps.server', 'https://apps.openerp.com') + apps_server = self.pool.get('ir.module.module').get_apps_server(cr, uid, context=context) up = urlparse.urlparse(apps_server) url = '{0.scheme}://{0.netloc}/apps/charts?serie={1}'.format(up, serie) diff --git a/addons/account/report/account_entries_report.py b/addons/account/report/account_entries_report.py index 6060d97c182..df2d92c9f12 100644 --- a/addons/account/report/account_entries_report.py +++ b/addons/account/report/account_entries_report.py @@ -94,7 +94,7 @@ class account_entries_report(osv.osv): return super(account_entries_report, self).search(cr, uid, args=args, offset=offset, limit=limit, order=order, context=context, count=count) - def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False): + def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False,lazy=True): if context is None: context = {} fiscalyear_obj = self.pool.get('account.fiscalyear') @@ -108,7 +108,7 @@ class account_entries_report(osv.osv): domain.append(['period_id','in',ids]) else: domain = domain - return super(account_entries_report, self).read_group(cr, uid, domain, fields, groupby, offset, limit, context, orderby) + return super(account_entries_report, self).read_group(cr, uid, domain, fields, groupby, offset, limit, context, orderby,lazy) def init(self, cr): tools.drop_view_if_exists(cr, 'account_entries_report') diff --git a/addons/account_asset/account_asset.py b/addons/account_asset/account_asset.py index f4e5d17a8e0..7041c3aafbf 100644 --- a/addons/account_asset/account_asset.py +++ b/addons/account_asset/account_asset.py @@ -328,7 +328,7 @@ class account_asset_asset(osv.osv): default = {} if context is None: context = {} - default.update({'depreciation_line_ids': [], 'state': 'draft'}) + default.update({'depreciation_line_ids': [], 'account_move_line_ids': [], 'history_ids': [], 'state': 'draft'}) return super(account_asset_asset, self).copy(cr, uid, id, default, context=context) def _compute_entries(self, cr, uid, ids, period_id, context=None): diff --git a/addons/analytic_user_function/analytic_user_function.py b/addons/analytic_user_function/analytic_user_function.py index 2671fc92581..5a17ac91e53 100644 --- a/addons/analytic_user_function/analytic_user_function.py +++ b/addons/analytic_user_function/analytic_user_function.py @@ -26,6 +26,7 @@ import openerp.addons.decimal_precision as dp class analytic_user_funct_grid(osv.osv): _name="analytic.user.funct.grid" _description= "Price per User" + _rec_name="user_id" _columns={ 'user_id': fields.many2one("res.users", "User", required=True,), 'product_id': fields.many2one("product.product", "Service", required=True,), diff --git a/addons/auth_oauth/controllers/main.py b/addons/auth_oauth/controllers/main.py index b4ce20d49e3..4fca426ffc0 100644 --- a/addons/auth_oauth/controllers/main.py +++ b/addons/auth_oauth/controllers/main.py @@ -2,6 +2,7 @@ import functools import logging import simplejson +import urlparse import werkzeug.utils from werkzeug.exceptions import BadRequest @@ -68,7 +69,8 @@ class OAuthLogin(openerp.addons.web.controllers.main.Home): def get_state(self, provider): state = dict( d=request.session.db, - p=provider['id'] + p=provider['id'], + r=request.httprequest.full_path ) token = request.params.get('token') if token: @@ -137,8 +139,12 @@ class OAuthController(http.Controller): cr.commit() action = state.get('a') menu = state.get('m') + redirect = state.get('r') url = '/web' - if action: + if redirect and not redirect.startswith('/auth_oauth/signin') and \ + (not redirect.startswith('/web/login') or 'redirect' in urlparse.urlsplit(redirect).query): + url = redirect + elif action: url = '/web#action=%s' % action elif menu: url = '/web#menu_id=%s' % menu diff --git a/addons/auth_signup/auth_signup_data.xml b/addons/auth_signup/auth_signup_data.xml index f470811d39e..2789fcd8315 100644 --- a/addons/auth_signup/auth_signup_data.xml +++ b/addons/auth_signup/auth_signup_data.xml @@ -10,7 +10,7 @@ - + _usertemplate diff --git a/addons/base_gengo/__init__.py b/addons/base_gengo/__init__.py index 133fa90dc51..ff48d6cc91f 100644 --- a/addons/base_gengo/__init__.py +++ b/addons/base_gengo/__init__.py @@ -22,5 +22,6 @@ import res_company import ir_translation import wizard +import controller # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/base_gengo/controller/__init__.py b/addons/base_gengo/controller/__init__.py new file mode 100644 index 00000000000..4648ae64b0f --- /dev/null +++ b/addons/base_gengo/controller/__init__.py @@ -0,0 +1 @@ +import gengo_callback diff --git a/addons/base_gengo/controller/gengo_callback.py b/addons/base_gengo/controller/gengo_callback.py new file mode 100644 index 00000000000..381ac7b7fe9 --- /dev/null +++ b/addons/base_gengo/controller/gengo_callback.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +import openerp +from openerp.addons.web import http +from openerp.addons.web.http import request + +import json + +class website_gengo(http.Controller): + @http.route('/website/gengo_callback', type='http', auth='none') + def gengo_callback(self,**post): + cr, uid, context = request.cr, openerp.SUPERUSER_ID, request.context + translation_pool = request.registry['ir.translation'] + if post and post.get('job'): + job = json.loads(post['job']) + tid = job.get('custom_data', False) + if (job.get('status') == 'approved') and tid: + term = translation_pool.browse(cr, uid, int(tid), context=context) + if term.job_id <> job.get('job_id'): + raise 'Error' + vals = {'state': 'translated', 'value': job.get('body_tgt')} + translation_pool.write(cr, uid, [int(tid)], vals, context=context) diff --git a/addons/base_gengo/wizard/base_gengo_translations.py b/addons/base_gengo/wizard/base_gengo_translations.py index 8cc7206e63e..f565b520d6c 100644 --- a/addons/base_gengo/wizard/base_gengo_translations.py +++ b/addons/base_gengo/wizard/base_gengo_translations.py @@ -33,10 +33,6 @@ try: from mygengo import MyGengo except ImportError: _logger.warning('Gengo library not found, Gengo features disabled. If you plan to use it, please install the mygengo library from http://pypi.python.org/pypi/mygengo') - class MyGengo(object): - def __init__(self, *args, **kwargs): - # no context for translations - so don't bother - raise ImportError('Gengo library not found, please install mygengo from http://pypi.python.org/pypi/mygengo') GENGO_DEFAULT_LIMIT = 20 @@ -120,51 +116,45 @@ class base_gengo_translations(osv.osv_memory): all_translation_ids = translation_pool.search(cr, uid, [('state', '=', 'inprogress'), ('gengo_translation', 'in', ('machine', 'standard', 'pro', 'ultra')), ('job_id', "!=", False)], context=context) while True: translation_ids = all_translation_ids[offset:offset + limit] - if translation_ids: - offset += limit - translation_terms = translation_pool.browse(cr, uid, translation_ids, context=context) - gengo_job_id = [term.job_id for term in translation_terms] - if gengo_job_id: - gengo_ids = ','.join(gengo_job_id) - job_response = gengo.getTranslationJobBatch(id=gengo_ids) - if job_response['opstat'] == 'ok': - job_response_dict = dict([(job['job_id'], job) for job in job_response['response']['jobs']]) - for term in translation_terms: - up_term = up_comment = 0 - vals = {} - if job_response_dict[term.job_id]['status'] == 'approved': - vals.update({'state': 'translated', - 'value': job_response_dict[term.job_id]['body_tgt']}) - up_term += 1 - job_comment = gengo.getTranslationJobComments(id=term.job_id) - if job_comment['opstat'] == 'ok': - gengo_comments = "" - for comment in job_comment['response']['thread']: - gengo_comments += _('%s\n-- Commented on %s by %s.\n\n') % (comment['body'], time.ctime(comment['ctime']), comment['author']) - vals.update({'gengo_comment': gengo_comments}) - up_comment += 1 - if vals: - translation_pool.write(cr, uid, term.id, vals) - _logger.info("Successfully Updated `%d` terms and %d Comments." % (up_term, up_comment)) - if not len(translation_ids) == limit: + offset += limit + if not translation_ids: break + translation_terms = translation_pool.browse(cr, uid, translation_ids, context=context) + gengo_job_id = [term.job_id for term in translation_terms] + if gengo_job_id: + gengo_ids = ','.join(gengo_job_id) + try: + job_response = gengo.getTranslationJobBatch(id=gengo_ids) + except: + continue + if job_response['opstat'] == 'ok': + for job in job_response['response'].get('jobs', []): + self._update_terms_job(cr, uid, job, context=context) return True + def _update_terms_job(self, cr, uid, job, context=None): + translation_pool = self.pool.get('ir.translation') + tid = int(job['custom_data']) + vals = {} + if job.get('job_id', False): + vals['job_id'] = job['job_id'] + vals['state'] = 'inprogress' + if job.get('status', False) in ('queued','available','pending','reviewable'): + vals['state'] = 'inprogress' + if job.get('body_tgt', False) and job.get('status', False)=='approved': + vals['value'] = job['body_tgt'] + if job.get('status', False) in ('approved', 'canceled'): + vals['state'] = 'translated' + if vals: + translation_pool.write(cr, uid, [tid], vals, context=context) + def _update_terms(self, cr, uid, response, context=None): """ Update the terms after their translation were requested to Gengo """ - translation_pool = self.pool.get('ir.translation') - for jobs in response['jobs']: + for jobs in response.get('jobs', []): for t_id, res in jobs.items(): - vals = {} - t_id = int(t_id) - tier = translation_pool.read(cr, uid, [t_id], ['gengo_translation'], context=context)[0]['gengo_translation'] - if tier == "machine": - vals.update({'value': res['body_tgt'], 'state': 'translated'}) - else: - vals.update({'job_id': res['job_id'], 'state': 'inprogress'}) - translation_pool.write(cr, uid, [t_id], vals, context=context) + self._update_terms_job(cr, uid, res, context=context) return def pack_jobs_request(self, cr, uid, term_ids, context=None): @@ -181,17 +171,22 @@ class base_gengo_translations(osv.osv_memory): auto_approve = 1 if user.company_id.gengo_auto_approve else 0 for term in translation_pool.browse(cr, uid, term_ids, context=context): if re.search(r"\w", term.src or ""): - jobs[term.id] = {'type': 'text', - 'slug': 'single::English to ' + term.lang, - 'tier': tools.ustr(term.gengo_translation), - 'body_src': term.src, - 'lc_src': 'en', - 'lc_tgt': translation_pool._get_gengo_corresponding_language(term.lang), - 'auto_approve': auto_approve, - 'comment': user.company_id.gengo_comment and "%s %s"%(user.company_id.gengo_comment,term.gengo_comment) or term.gengo_comment, - 'callback_url': self.pool.get('ir.config_parameter').get_param(cr, uid,'web.base.url') + '/website/gengo_callback/' + str(term.id) + comment = user.company_id.gengo_comment or '' + if term.gengo_comment: + comment+='\n' + term.gengo_comment + jobs[time.strftime('%Y%m%d%H%M%S') + '-' + str(term.id)] = { + 'type': 'text', + 'slug': 'Single :: English to ' + term.lang, + 'tier': tools.ustr(term.gengo_translation), + 'custom_data': str(term.id), + 'body_src': term.src, + 'lc_src': 'en', + 'lc_tgt': translation_pool._get_gengo_corresponding_language(term.lang), + 'auto_approve': auto_approve, + 'comment': comment, + 'callback_url': self.pool.get('ir.config_parameter').get_param(cr, uid,'web.base.url') + '/website/gengo_callback' } - return {'jobs': jobs} + return {'jobs': jobs, 'as_group': 1} def _send_translation_terms(self, cr, uid, term_ids, context=None): @@ -223,15 +218,14 @@ class base_gengo_translations(osv.osv_memory): context = {} language_pool = self.pool.get('res.lang') translation_pool = self.pool.get('ir.translation') + domain = [('state', '=', 'to_translate'), ('gengo_translation', 'in', ('machine', 'standard', 'pro', 'ultra')), ('job_id', "=", False)] + if context.get('gengo_language', False): + lc = language_pool.browse(cr, uid, context['gengo_language'], context=context).code + domain.append( ('lang', '=', lc) ) + + all_term_ids = translation_pool.search(cr, uid, domain, context=context) try: - #by default, the request will be made for all terms that needs it, whatever the language - lang_ids = language_pool.search(cr, uid, [], context=context) - if context.get('gengo_language'): - #but if this specific key is given, then we restrict the request on terms of this language only - lang_ids = [context.get('gengo_language')] - langs = [lang.code for lang in language_pool.browse(cr, uid, lang_ids, context=context)] offset = 0 - all_term_ids = translation_pool.search(cr, uid, [('state', '=', 'to_translate'), ('gengo_translation', 'in', ('machine', 'standard', 'pro', 'ultra')), ('lang', 'in', langs), ('job_id', "=", False)], context=context) while True: #search for the n first terms to translate term_ids = all_term_ids[offset:offset + limit] diff --git a/addons/calendar/calendar.py b/addons/calendar/calendar.py index e928432821b..add0030d76c 100644 --- a/addons/calendar/calendar.py +++ b/addons/calendar/calendar.py @@ -1476,7 +1476,7 @@ class calendar_event(osv.Model): self.create_attendees(cr, uid, [res], context=context) return res - def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False): + def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False, lazy=True): if not context: context = {} @@ -1484,7 +1484,7 @@ class calendar_event(osv.Model): raise osv.except_osv(_('Warning!'), _('Group by date is not supported, use the calendar view instead.')) virtual_id = context.get('virtual_id', True) context.update({'virtual_id': False}) - res = super(calendar_event, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby) + res = super(calendar_event, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby, lazy=lazy) for result in res: #remove the count, since the value is not consistent with the result of the search when expand the group for groupname in groupby: diff --git a/addons/event/event_view.xml b/addons/event/event_view.xml index 07a36ea3a6b..3669b5a1e6f 100644 --- a/addons/event/event_view.xml +++ b/addons/event/event_view.xml @@ -105,9 +105,9 @@ -