Skip to content

Commit

Permalink
ADD redmine time entry deletion syncronized with odoo
Browse files Browse the repository at this point in the history
  • Loading branch information
eLBati committed Aug 21, 2018
1 parent 965fd86 commit e9e675a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion redmine_import_time_entry/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{
'name': 'Redmine Import Time Entry',
'version': '10.0.1.0.0',
'version': '10.0.1.1.0',
'author': 'Savoir-faire Linux,Odoo Community Association (OCA)',
'maintainer': 'Odoo Community Association (OCA)',
'website': 'http://odoo-community.org',
Expand Down
20 changes: 20 additions & 0 deletions redmine_import_time_entry/models/hr_analytic_timesheet.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# -*- coding: utf-8 -*-
# © 2016 Savoir-faire Linux
# © 2018 Lorenzo Battistini - Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import logging
from odoo import fields, models, api
from odoo.addons.queue_job.job import job

_logger = logging.getLogger(__name__)


class RedmineTimeEntry(models.Model):
_name = 'redmine.account.analytic.line'
Expand All @@ -17,6 +21,22 @@ class RedmineTimeEntry(models.Model):
ondelete='cascade'
)

@job
@api.model
def delete_batch(self, backend, filters=None):
with backend.work_on(self._name) as work:
deleter = work.component(usage='batch.deleter')
redmine_ids = deleter.get_all_records(filters=filters)
deleted_lines = self.search([
('date', '>=', filters['from_date']),
('date', '<=', filters['to_date']),
('redmine_id', 'not in', redmine_ids)
])
deleted_lines.mapped('odoo_id').unlink()
if deleted_lines:
_logger.debug(
'Deleted %s timesheet lines' % len(deleted_lines))

@job
@api.model
def import_batch(self, backend, filters=None):
Expand Down
8 changes: 4 additions & 4 deletions redmine_import_time_entry/models/redmine_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ def prepare_time_entry_import(self):
for backend in backends:
today = datetime.now()
date_to = to_string(today)
date_from = today - timedelta(
days=backend.time_entry_number_of_days)

date_from = to_string(today - timedelta(
days=backend.time_entry_number_of_days))
filters = {
'from_date': date_from,
'to_date': date_to,
}
model = 'redmine.account.analytic.line'
_logger.info(
'Scheduling time entry batch import from Redmine '
'Scheduling time entry batch synchronization from Redmine '
'with backend %s.' % backend.name)
self.env[model].with_delay().import_batch(backend, filters=filters)
self.env[model].with_delay().delete_batch(backend, filters=filters)
11 changes: 11 additions & 0 deletions redmine_import_time_entry/unit/import_synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ def run_single_user(self, filters=None, options=None):
return mapping_errors


class TimeEntryBatchDeleterSynchronizer(Component):

_name = 'redmine.account.analytic.line.batch.deleter'
_inherit = 'redmine.importer'
_usage = 'batch.deleter'
_apply_on = 'redmine.account.analytic.line'

def get_all_records(self, filters=None):
return self.backend_adapter.search(None, filters)


class TimeEntryImportSynchronizer(Component):

_name = 'redmine.account.analytic.line.importer'
Expand Down

0 comments on commit e9e675a

Please sign in to comment.