Skip to content

Commit

Permalink
[MERGE] forward port of branch saas-4 up to f68c835
Browse files Browse the repository at this point in the history
  • Loading branch information
KangOl committed Jun 25, 2014
2 parents 4cb5381 + f68c835 commit 9e8e365
Show file tree
Hide file tree
Showing 34 changed files with 287 additions and 117 deletions.
7 changes: 7 additions & 0 deletions addons/account/security/account_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
</record>

<record id="account_subscription_line_comp_rule" model="ir.rule">
<field name="name">Account subscription line company rule</field>
<field name="model_id" ref="model_account_subscription_line"/>
<field name="global" eval="True"/>
<field name="domain_force">['|',('subscription_id.model_id.company_id','=',False),('subscription_id.model_id.company_id','child_of',[user.company_id.id])]</field>
</record>

<record model="ir.rule" id="account_invoice_line_comp_rule">
<field name="name">Invoice Line company rule</field>
<field name="model_id" ref="model_account_invoice_line"/>
Expand Down
6 changes: 3 additions & 3 deletions addons/account/wizard/account_subscription_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class account_subscription_generate(osv.osv_memory):
def action_generate(self, cr, uid, ids, context=None):
mod_obj = self.pool.get('ir.model.data')
act_obj = self.pool.get('ir.actions.act_window')
sub_line_obj = self.pool.get('account.subscription.line')
moves_created=[]
for data in self.read(cr, uid, ids, context=context):
cr.execute('select id from account_subscription_line where date<%s and move_id is null', (data['date'],))
line_ids = map(lambda x: x[0], cr.fetchall())
moves = self.pool.get('account.subscription.line').move_create(cr, uid, line_ids, context=context)
line_ids = sub_line_obj.search(cr, uid, [('date', '<', data['date']), ('move_id', '=', False)], context=context)
moves = sub_line_obj.move_create(cr, uid, line_ids, context=context)
moves_created.extend(moves)
result = mod_obj.get_object_reference(cr, uid, 'account', 'action_move_line_form')
id = result and result[1] or False
Expand Down
45 changes: 38 additions & 7 deletions addons/base_gengo/controller/gengo_callback.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
# -*- coding: utf-8 -*-

import openerp
from openerp import SUPERUSER_ID
from openerp.addons.web import http
from openerp.addons.web.http import request

from werkzeug.wrappers import BaseResponse as Response

import json


class website_gengo(http.Controller):

def get_gengo_key(self, cr):
icp = request.registry['ir.config_parameter']
return icp.get_param(cr, SUPERUSER_ID, request.registry['base.gengo.translations'].GENGO_KEY, default="")

@http.route('/website/gengo_callback', type='http', auth='none')
def gengo_callback(self,**post):
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'])
if post and post.get('job') and post.get('pgk'):
if post.get('pgk') != self.get_gengo_key(cr):
return Response("Bad authentication - 403/412", status=412)
job = json.loads(post['job'], 'utf-8')
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)
if term.src != job.get('body_src'):
return Response("Text Altered - Not saved", status=100)
domain = [
'|',
('id', "=", int(tid)),
'&', '&', '&', '&', '&',
('state', '=', term.state),
('gengo_translation', '=', term.gengo_translation),
('src', "=", term.src),
('type', "=", term.type),
('name', "=", term.name),
('lang', "=", term.lang),
#('order_id', "=", term.order_id),
]

all_ir_tanslations = translation_pool.search(cr, uid, domain, context=context or {})

if all_ir_tanslations:
vals = {'state': 'translated', 'value': job.get('body_tgt')}
translation_pool.write(cr, uid, all_ir_tanslations, vals, context=context)
return Response("OK", status=200)
else:
return Response("No terms found", status=104)
return Response("Not saved", status=100)
2 changes: 2 additions & 0 deletions addons/base_gengo/gengo_sync_schedular_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<field name="interval_number">6</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="doall">0</field>
<field eval="'base.gengo.translations'" name="model"></field>
<field eval="'_sync_response'" name="function"/>
<field eval="'(20,)'" name="args"/>
Expand All @@ -20,6 +21,7 @@
<field name="interval_number">6</field>
<field name="interval_type">hours</field>
<field name="numbercall">-1</field>
<field name="doall">0</field>
<field eval="'base.gengo.translations'" name="model"></field>
<field eval="'_sync_request'" name="function"/>
<field eval="'(20,)'" name="args"/>
Expand Down
26 changes: 22 additions & 4 deletions addons/base_gengo/ir_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@
'fi_FI': ('fi', 'Finnish')
}


class ir_translation(osv.Model):
_name = "ir.translation"
_inherit = "ir.translation"

_columns = {
'gengo_comment': fields.text("Comments & Activity Linked to Gengo"),
'job_id': fields.char('Gengo Job ID', size=32),
'order_id': fields.char('Gengo Order ID', size=32),
"gengo_translation": fields.selection([('machine', 'Translation By Machine'),
('standard', 'Standard'),
('pro', 'Pro'),
('ultra', 'Ultra')], "Gengo Translation Service Level", help='You can select here the service level you want for an automatic translation using Gengo.'),
('standard', 'Standard'),
('pro', 'Pro'),
('ultra', 'Ultra')], "Gengo Translation Service Level", help='You can select here the service level you want for an automatic translation using Gengo.'),
}

def _get_all_supported_languages(self, cr, uid, context=None):
Expand All @@ -83,3 +85,19 @@ def _get_all_supported_languages(self, cr, uid, context=None):

def _get_gengo_corresponding_language(cr, lang):
return lang in LANG_CODE_MAPPING and LANG_CODE_MAPPING[lang][0] or lang

def _get_source_query(self, cr, uid, name, types, lang, source, res_id):
query, params = super(ir_translation, self)._get_source_query(cr, uid, name, types, lang, source, res_id)

query += """
ORDER BY
CASE
WHEN gengo_translation=%s then 10
WHEN gengo_translation=%s then 20
WHEN gengo_translation=%s then 30
WHEN gengo_translation=%s then 40
ELSE 0
END DESC
"""
params += ('machine', 'standard', 'ultra', 'pro',)
return (query, params)
81 changes: 57 additions & 24 deletions addons/base_gengo/wizard/base_gengo_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
#
##############################################################################

import uuid
import logging
import re
import time

from openerp.osv import osv, fields
from openerp import tools
from openerp import tools, SUPERUSER_ID
from openerp.tools.translate import _

_logger = logging.getLogger(__name__)
Expand All @@ -36,7 +37,9 @@

GENGO_DEFAULT_LIMIT = 20


class base_gengo_translations(osv.osv_memory):
GENGO_KEY = "Gengo.UUID"

_name = 'base.gengo.translations'
_columns = {
Expand All @@ -46,9 +49,20 @@ class base_gengo_translations(osv.osv_memory):
'lang_id': fields.many2one('res.lang', 'Language', required=True),
'sync_limit': fields.integer("No. of terms to sync"),
}
_defaults = {'sync_type' : 'both',
'sync_limit' : 20
}
_defaults = {
'sync_type': 'both',
'sync_limit': 20
}

def init(self, cr):
icp = self.pool['ir.config_parameter']
if not icp.get_param(cr, SUPERUSER_ID, self.GENGO_KEY, default=None):
icp.set_param(cr, SUPERUSER_ID, self.GENGO_KEY, str(uuid.uuid4()))

def get_gengo_key(self, cr):
icp = self.pool['ir.config_parameter']
return icp.get_param(cr, SUPERUSER_ID, self.GENGO_KEY, default="Undefined")

def gengo_authentication(self, cr, uid, context=None):
'''
This method tries to open a connection with Gengo. For that, it uses the Public and Private
Expand Down Expand Up @@ -113,48 +127,68 @@ def _sync_response(self, cr, uid, limit=GENGO_DEFAULT_LIMIT, context=None):
_logger.warning("%s", gengo)
else:
offset = 0
all_translation_ids = translation_pool.search(cr, uid, [('state', '=', 'inprogress'), ('gengo_translation', 'in', ('machine', 'standard', 'pro', 'ultra')), ('job_id', "!=", False)], context=context)
all_translation_ids = translation_pool.search(cr, uid, [('state', '=', 'inprogress'), ('gengo_translation', 'in', ('machine', 'standard', 'pro', 'ultra')), ('order_id', "!=", False)], context=context)
while True:
translation_ids = all_translation_ids[offset:offset + limit]
offset += limit
if not translation_ids:
break

terms_progress = {
'gengo_order_ids': set(),
'ir_translation_ids': set(),
}
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)
for term in translation_terms:
terms_progress['gengo_order_ids'].add(term.order_id)
terms_progress['ir_translation_ids'].add(tools.ustr(term.id))

for order_id in terms_progress['gengo_order_ids']:
order_response = gengo.getTranslationOrderJobs(id=order_id)
jobs_approved = order_response.get('response', []).get('order', []).get('jobs_approved', [])
gengo_ids = ','.join(jobs_approved)

if gengo_ids: # Need to check, because getTranslationJobBatch don't catch this case and so call the getTranslationJobs because no ids in url
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)
if job.get('custom_data') in terms_progress['ir_translation_ids']:
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'):
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':
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):
def _update_terms(self, cr, uid, response, term_ids, context=None):
"""
Update the terms after their translation were requested to Gengo
"""
for jobs in response.get('jobs', []):
translation_pool = self.pool.get('ir.translation')

vals = {
'order_id': response.get('order_id', ''),
'state': 'inprogress'
}

translation_pool.write(cr, uid, term_ids, vals, context=context)
jobs = response.get('jobs', [])
if jobs:
for t_id, res in jobs.items():
self._update_terms_job(cr, uid, res, context=context)

return

def pack_jobs_request(self, cr, uid, term_ids, context=None):
Expand All @@ -164,7 +198,7 @@ def pack_jobs_request(self, cr, uid, term_ids, context=None):
'term2.id': {...}
}
}'''

base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
translation_pool = self.pool.get('ir.translation')
jobs = {}
user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
Expand All @@ -173,7 +207,7 @@ def pack_jobs_request(self, cr, uid, term_ids, context=None):
if re.search(r"\w", term.src or ""):
comment = user.company_id.gengo_comment or ''
if term.gengo_comment:
comment+='\n' + 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,
Expand All @@ -184,10 +218,9 @@ def pack_jobs_request(self, cr, uid, term_ids, context=None):
'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'
'callback_url': "%s/website/gengo_callback?pgk=%s&db=%s" % (base_url, self.get_gengo_key(cr), cr.dbname)
}
return {'jobs': jobs, 'as_group': 1}

return {'jobs': jobs, 'as_group': 0}

def _send_translation_terms(self, cr, uid, term_ids, context=None):
"""
Expand All @@ -200,7 +233,7 @@ def _send_translation_terms(self, cr, uid, term_ids, context=None):
if request['jobs']:
result = gengo.postTranslationJobs(jobs=request)
if result['opstat'] == 'ok':
self._update_terms(cr, uid, result['response'], context=context)
self._update_terms(cr, uid, result['response'], term_ids, context=context)
else:
_logger.error(gengo)
return True
Expand All @@ -218,10 +251,10 @@ def _sync_request(self, cr, uid, limit=GENGO_DEFAULT_LIMIT, context=None):
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)]
domain = [('state', '=', 'to_translate'), ('gengo_translation', 'in', ('machine', 'standard', 'pro', 'ultra')), ('order_id', "=", False)]
if context.get('gengo_language', False):
lc = language_pool.browse(cr, uid, context['gengo_language'], context=context).code
domain.append( ('lang', '=', lc) )
domain.append(('lang', '=', lc))

all_term_ids = translation_pool.search(cr, uid, domain, context=context)
try:
Expand Down
7 changes: 7 additions & 0 deletions addons/crm_claim/crm_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ def create(self, cr, uid, vals, context=None):
# context: no_log, because subtype already handle this
return super(crm_claim, self).create(cr, uid, vals, context=context)

def copy(self, cr, uid, id, default=None, context=None):
claim = self.browse(cr, uid, id, context=context)
default = dict(default or {},
stage_id = self._get_default_stage_id(cr, uid, context=context),
name = _('%s (copy)') % claim.name)
return super(crm_claim, self).copy(cr, uid, id, default, context=context)

# -------------------------------------------------------
# Mail gateway
# -------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion addons/l10n_be/wizard/l10n_be_vat_intra.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def create_xml(self, cursor, user, ids, context=None):
data_head = """<?xml version="1.0" encoding="ISO-8859-1"?>
<ns2:IntraConsignment xmlns="http://www.minfin.fgov.be/InputCommon" xmlns:ns2="http://www.minfin.fgov.be/IntraConsignment" IntraListingsNbr="1">
<ns2:Representative>
<RepresentativeID identificationType="NVAT" issuedBy="%(issued_by)s">%(company_vat)s</RepresentativeID>
<RepresentativeID identificationType="NVAT" issuedBy="%(issued_by)s">%(vatnum)s</RepresentativeID>
<Name>%(company_name)s</Name>
<Street>%(street)s</Street>
<PostCode>%(post_code)s</PostCode>
Expand Down
8 changes: 8 additions & 0 deletions addons/purchase_requisition/purchase_requisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def tender_cancel(self, cr, uid, ids, context=None):
for purchase_order in tender.purchase_ids:
purchase_order_obj.action_cancel(cr, uid, [purchase_order.id], context=context)
purchase_order_obj.message_post(cr, uid, [purchase_order.id], body=_('Cancelled by the tender associated to this quotation.'), context=context)
procurement_ids = self.pool['procurement.order'].search(cr, uid, [('requisition_id', 'in', ids)], context=context)
self.pool['procurement.order'].action_done(cr, uid, procurement_ids)
return self.write(cr, uid, ids, {'state': 'cancel'})

def tender_in_progress(self, cr, uid, ids, context=None):
Expand All @@ -108,6 +110,8 @@ def tender_reset(self, cr, uid, ids, context=None):
return True

def tender_done(self, cr, uid, ids, context=None):
procurement_ids = self.pool['procurement.order'].search(cr, uid, [('requisition_id', 'in', ids)], context=context)
self.pool['procurement.order'].action_done(cr, uid, procurement_ids)
return self.write(cr, uid, ids, {'state': 'done'}, context=context)

def open_product_line(self, cr, uid, ids, context=None):
Expand Down Expand Up @@ -352,6 +356,10 @@ def wkf_confirm_order(self, cr, uid, ids, context=None):
proc_obj.write(cr, uid, proc_ids, {'purchase_id': po.id})
self.signal_purchase_cancel(cr, uid, [order.id])
po.requisition_id.tender_done(context=context)
if po.requisition_id and all(purchase_id.state in ['draft', 'cancel'] for purchase_id in po.requisition_id.purchase_ids if purchase_id.id != po.id):
procurement_ids = self.pool['procurement.order'].search(cr, uid, [('requisition_id', '=', po.requisition_id.id)], context=context)
for procurement in proc_obj.browse(cr, uid, procurement_ids, context=context):
procurement.move_id.write({'location_id': procurement.move_id.location_dest_id.id})
return res

def copy(self, cr, uid, id, default=None, context=None):
Expand Down
Loading

0 comments on commit 9e8e365

Please sign in to comment.