Skip to content

Commit

Permalink
Merge 8837fc7 into dd59d0e
Browse files Browse the repository at this point in the history
  • Loading branch information
David Dufresne committed Mar 10, 2016
2 parents dd59d0e + 8837fc7 commit 0434aa1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 6 deletions.
1 change: 0 additions & 1 deletion connector_redmine/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_redmine_employee,redmine employee,model_redmine_backend,base.group_user,1,0,0,0
access_redmine_manager,redmine manager,model_redmine_backend,connector.group_connector_manager,1,1,1,1
2 changes: 2 additions & 0 deletions connector_redmine/unit/backend_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def search_user(self, login):
"""
Get a Redmine user id from a Odoo login
"""
self._auth()

users = self.redmine_api.user.filter(name=login)

user_id = next(
Expand Down
5 changes: 3 additions & 2 deletions redmine_import_time_entry/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

{
'name': 'Redmine Import Time Entry',
'version': '0.1',
'version': '7.0.2.0.0',
'author': 'Savoir-faire Linux',
'maintainer': 'Savoir-faire Linux,Odoo Community Association (OCA)',
'website': 'http://odoo-community.org',
Expand All @@ -41,7 +41,8 @@
'views/redmine_backend_view.xml',
'views/hr_timesheet_sheet_view.xml',
],
'application': True,
'application': False,
'installable': True,
'active': False,
'js': ['static/src/js/timesheet.js'],
}
13 changes: 11 additions & 2 deletions redmine_import_time_entry/models/hr_timesheet_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#
##############################################################################

from openerp import SUPERUSER_ID
from openerp.osv import orm
from openerp.tools.translate import _
from openerp.addons.connector.session import ConnectorSession
Expand All @@ -30,12 +31,20 @@ class HrTimesheetSheet(orm.Model):
_inherit = 'hr_timesheet_sheet.sheet'

def import_timesheets_from_redmine(self, cr, uid, ids, context=None):
"""
Call the connector to import timesheets as superuser
to prevent errors related with security issues.
We ensure that the user has write access to the
timesheet.
"""
if isinstance(ids, (int, long)):
ids = [ids]

session = ConnectorSession(cr, uid, context)
self.check_access_rule(cr, uid, ids, 'write', context=context)

session = ConnectorSession(cr, SUPERUSER_ID, context)
backend_ids = self.pool['redmine.backend'].search(
cr, uid, [('time_entry_import_activate', '=', True)],
cr, SUPERUSER_ID, [('time_entry_import_activate', '=', True)],
limit=1, context=context)

if not backend_ids:
Expand Down
59 changes: 59 additions & 0 deletions redmine_import_time_entry/static/src/js/timesheet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
openerp.redmine_import_time_entry = function(instance) {

var QWeb = instance.web.qweb;
var _t = instance.web._t;

instance.hr_timesheet_sheet.WeeklyTimesheet = instance.hr_timesheet_sheet.WeeklyTimesheet.extend({
update_sheets: function() {
var self = this;
if (self.querying)
return;
self.updating = true;

var new_timesheets = _(self.get("sheets"));
var res = [];

new_timesheets.forEach(function(new_ts){
if(typeof(new_ts.id) === "undefined"){
// New record
res.push([0, 0, new_ts]);
}
else{
// Old record
res.push([1, new_ts.id, {'unit_amount': new_ts.unit_amount}]);
}
})

self.field_manager.set_values({timesheet_ids: res}).done(function() {
self.updating = false;
});
},
generate_o2m_value: function() {
var self = this;
var ops = [];
var ignored_fields = self.ignore_fields();
_.each(self.accounts, function(account) {
_.each(account.days, function(day) {
_.each(day.lines, function(line) {
if (line.unit_amount !== 0) {
var tmp = _.clone(line);

// The following line was removed from the method
// tmp.id = undefined;

_.each(line, function(v, k) {
if (v instanceof Array) {
tmp[k] = v[0];
}
});
tmp = _.omit(tmp, ignored_fields);

ops.push(tmp);
}
});
});
});
return ops;
},
})
};
5 changes: 4 additions & 1 deletion redmine_import_time_entry/unit/backend_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ def read(self, redmine_id):
if not contract_ref:
raise InvalidDataError(
_('The field %(field)s is not set in Redmine for project '
'%(project)s.') % (custom_field, project.name))
'%(project)s.') % {
'field': custom_field,
'project': project.name
})

user = self.redmine_api.user.get(entry.user.id)

Expand Down

0 comments on commit 0434aa1

Please sign in to comment.