diff --git a/pingen/__init__.py b/pingen/__init__.py
index ecfdbd0..f9e1108 100644
--- a/pingen/__init__.py
+++ b/pingen/__init__.py
@@ -21,5 +21,5 @@
import ir_attachment
import pingen
-import pingen_task
+import pingen_document
diff --git a/pingen/__openerp__.py b/pingen/__openerp__.py
index e6d7d0e..c325fd5 100644
--- a/pingen/__openerp__.py
+++ b/pingen/__openerp__.py
@@ -57,7 +57,7 @@ Dependencies
'init_xml': [],
'update_xml': [
'ir_attachment_view.xml',
- 'pingen_task_view.xml',
+ 'pingen_document_view.xml',
],
'demo_xml': [],
'tests': [],
diff --git a/pingen/ir_attachment.py b/pingen/ir_attachment.py
index 4666930..cecdb68 100644
--- a/pingen/ir_attachment.py
+++ b/pingen/ir_attachment.py
@@ -32,9 +32,9 @@ class ir_attachment(orm.Model):
_columns = {
'send_to_pingen': fields.boolean('Send to Pingen.com'),
- 'pingen_task_ids': fields.one2many(
- 'pingen.task', 'attachment_id',
- string="Pingen Task", readonly=True),
+ 'pingen_document_ids': fields.one2many(
+ 'pingen.document', 'attachment_id',
+ string='Pingen Document', readonly=True),
'pingen_send': fields.boolean(
'Send',
help="Defines if a document is merely uploaded or also sent"),
@@ -50,58 +50,59 @@ class ir_attachment(orm.Model):
'pingen_speed': '2',
}
- def _prepare_pingen_task_vals(self, cr, uid, attachment, context=None):
+ def _prepare_pingen_document_vals(self, cr, uid, attachment, context=None):
return {'attachment_id': attachment.id,
'config': 'created from attachment'}
- def _handle_pingen_task(self, cr, uid, attachment_id, context=None):
- """ Reponsible of the related ``pingen.task`` when the ``send_to_pingen``
+ def _handle_pingen_document(self, cr, uid, attachment_id, context=None):
+ """ Reponsible of the related ``pingen.document`` when the ``send_to_pingen``
field is modified.
- Only one pingen task can be created per attachment.
+ Only one pingen document can be created per attachment.
When ``send_to_pingen`` is activated:
- * Create a ``pingen.task`` if it does not already exist
- * Put the related ``pingen.task`` to ``pending`` if it already exist
+ * Create a ``pingen.document`` if it does not already exist
+ * Put the related ``pingen.document`` to ``pending`` if it already exist
When it is deactivated:
- * Do nothing if no related ``pingen.task`` exists
+ * Do nothing if no related ``pingen.document`` exists
* Or cancel it
* If it has already been pushed to pingen.com, raises
an `osv.except_osv` exception
"""
- pingen_task_obj = self.pool.get('pingen.task')
+ pingen_document_obj = self.pool.get('pingen.document')
attachment = self.browse(cr, uid, attachment_id, context=context)
- task = attachment.pingen_task_ids[0] if attachment.pingen_task_ids else None
+ document = attachment.pingen_document_ids[0] if attachment.pingen_document_ids else None
if attachment.send_to_pingen:
- if task:
- task.write({'state': 'pending'}, context=context)
+ if document:
+ document.write({'state': 'pending'}, context=context)
else:
- pingen_task_obj.create(
+ pingen_document_obj.create(
cr, uid,
- self._prepare_pingen_task_vals(
+ self._prepare_pingen_document_vals(
cr, uid, attachment, context=context),
context=context)
else:
- if task:
- if task.state == 'pushed':
+ if document:
+ if document.state == 'pushed':
+ # TODO: cancel on pingen.com
raise osv.except_osv(
_('Error'),
_('The attachment %s is already pushed to pingen.com.') % \
attachment.name)
- task.write({'state': 'canceled'}, context=context)
+ document.write({'state': 'canceled'}, context=context)
return
def create(self, cr, uid, vals, context=None):
attachment_id = super(ir_attachment, self).create(cr, uid, vals, context=context)
if 'send_to_pingen' in vals:
- self._handle_pingen_task(cr, uid, attachment_id, context=context)
+ self._handle_pingen_document(cr, uid, attachment_id, context=context)
return attachment_id
def write(self, cr, uid, ids, vals, context=None):
res = super(ir_attachment, self).write(cr, uid, ids, vals, context=context)
if 'send_to_pingen' in vals:
for attachment_id in ids:
- self._handle_pingen_task(cr, uid, attachment_id, context=context)
+ self._handle_pingen_document(cr, uid, attachment_id, context=context)
return res
def _decoded_content(self, cr, uid, attachment, context=None):
diff --git a/pingen/ir_attachment_view.xml b/pingen/ir_attachment_view.xml
index f13d9b7..d51a906 100644
--- a/pingen/ir_attachment_view.xml
+++ b/pingen/ir_attachment_view.xml
@@ -21,10 +21,10 @@
diff --git a/pingen/pingen_task.py b/pingen/pingen_document.py
similarity index 71%
rename from pingen/pingen_task.py
rename to pingen/pingen_document.py
index 3166fac..11afd76 100644
--- a/pingen/pingen_task.py
+++ b/pingen/pingen_document.py
@@ -35,20 +35,22 @@ STAGING = True
_logger = logging.getLogger(__name__)
-class pingen_task(orm.Model):
- """ A pingen task is the state of the synchronization of
+class pingen_document(orm.Model):
+ """ A pingen document is the state of the synchronization of
an attachment with pingen.com
It stores the configuration and the current state of the synchronization.
It also serves as a queue of documents to push to pingen.com
"""
- _name = 'pingen.task'
+ _name = 'pingen.document'
_inherits = {'ir.attachment': 'attachment_id'}
_columns = {
'attachment_id': fields.many2one(
- 'ir.attachment', 'Document', required=True, readonly=True, ondelete='cascade'),
+ 'ir.attachment', 'Document',
+ required=True, readonly=True,
+ ondelete='cascade'),
'state': fields.selection(
[('pending', 'Pending'),
('pushed', 'Pushed'),
@@ -87,9 +89,9 @@ class pingen_task(orm.Model):
}
_sql_constraints = [
- ('pingen_task_attachment_uniq',
+ ('pingen_document_attachment_uniq',
'unique (attachment_id)',
- 'Only one Pingen task is allowed per attachment.'),
+ 'Only one Pingen document is allowed per attachment.'),
]
def _pingen(self, cr, uid, ids, context=None):
@@ -98,41 +100,41 @@ class pingen_task(orm.Model):
# TODO parameterize
return Pingen(TOKEN, staging=STAGING)
- def _push_to_pingen(self, cr, uid, task, context=None):
+ def _push_to_pingen(self, cr, uid, document, context=None):
""" Push a document to pingen.com """
attachment_obj = self.pool.get('ir.attachment')
decoded_document = attachment_obj._decoded_content(
- cr, uid, task.attachment_id, context=context)
+ cr, uid, document.attachment_id, context=context)
pingen = self._pingen(cr, uid, [], context=context)
try:
doc_id, post_id, infos = pingen.push_document(
- task.datas_fname,
+ document.datas_fname,
StringIO(decoded_document),
- task.pingen_send,
- task.pingen_speed,
- task.pingen_color)
+ document.pingen_send,
+ document.pingen_speed,
+ document.pingen_color)
except ConnectionError as e:
_logger.exception(
- 'Connection Error when pushing Pingen Task %s to %s.' %
- (task.id, pingen.url))
+ 'Connection Error when pushing Pingen Document %s to %s.' %
+ (document.id, pingen.url))
raise
except APIError as e:
_logger.error(
- 'API Error when pushing Pingen Task %s to %s.' %
- (task.id, pingen.url))
+ 'API Error when pushing Pingen Document %s to %s.' %
+ (document.id, pingen.url))
raise
- task.write(
+ document.write(
{'last_error_message': False,
'state': 'sendcenter' if post_id else 'pushed',
'push_date': infos['date'],
'pingen_id': doc_id,
'post_id': post_id},
context=context)
- _logger.info('Pingen Task %s: pushed to %s' % (task.id, pingen.url))
+ _logger.info('Pingen Document %s: pushed to %s' % (document.id, pingen.url))
def push_to_pingen(self, cr, uid, ids, context=None):
""" Push a document to pingen.com
@@ -142,19 +144,19 @@ class pingen_task(orm.Model):
Wrapper method for multiple ids (when triggered from button for
instance) for public interface.
"""
- for task in self.browse(cr, uid, ids, context=context):
+ for document in self.browse(cr, uid, ids, context=context):
try:
- self._push_to_pingen(cr, uid, task, context=context)
+ self._push_to_pingen(cr, uid, document, context=context)
except ConnectionError as e:
raise osv.except_osv(
_('Pingen Connection Error'),
- _('Connection Error when asking for sending the document %s to Pingen') % task.name)
+ _('Connection Error when asking for sending the document %s to Pingen') % document.name)
except APIError as e:
raise osv.except_osv(
_('Pingen Error'),
_('Error when asking Pingen to send the document %s: '
- '\n%s') % (task.name, e))
+ '\n%s') % (document.name, e))
return True
def _push_and_send_to_pingen_silent(self, cr, uid, ids, context=None):
@@ -168,48 +170,48 @@ class pingen_task(orm.Model):
# do not retry pingen_error, they should be treated manually
[('state', 'in', ['pending', 'pushed', 'error'])],
context=context)
- for task in self.browse(cr, uid, ids, context=context):
+ for document in self.browse(cr, uid, ids, context=context):
try:
- if not task.pingen_id:
- self._push_to_pingen(cr, uid, task, context=context)
- if not task.post_id and task.pingen_send:
- self._ask_pingen_send(cr, uid, task, context=context)
+ if not document.pingen_id:
+ self._push_to_pingen(cr, uid, document, context=context)
+ if not document.post_id and document.pingen_send:
+ self._ask_pingen_send(cr, uid, document, context=context)
except ConnectionError as e:
- task.write({'last_error_message': e, 'state': 'error'}, context=context)
+ document.write({'last_error_message': e, 'state': 'error'}, context=context)
except APIError as e:
- task.write({'last_error_message': e, 'state': 'pingen_error'}, context=context)
+ document.write({'last_error_message': e, 'state': 'pingen_error'}, context=context)
return True
- def _ask_pingen_send(self, cr, uid, task, context=None):
+ def _ask_pingen_send(self, cr, uid, document, context=None):
""" For a document already pushed to pingen, ask to send it.
"""
# sending has been explicitely asked so we change the option
# for consistency
- if not task.pingen_send:
- task.write({'pingen_send': True}, context=context)
+ if not document.pingen_send:
+ document.write({'pingen_send': True}, context=context)
pingen = self._pingen(cr, uid, [], context=context)
try:
post_id = pingen.send_document(
- task.pingen_id,
- task.pingen_speed,
- task.pingen_color)
+ document.pingen_id,
+ document.pingen_speed,
+ document.pingen_color)
except ConnectionError as e:
- _logger.exception('Connection Error when asking for sending Pingen Task %s to %s.' %
- (task.id, pingen.url))
+ _logger.exception('Connection Error when asking for sending Pingen Document %s to %s.' %
+ (document.id, pingen.url))
raise
except APIError as e:
- _logger.exception('API Error when asking for sending Pingen Task %s to %s.' %
- (task.id, pingen.url))
+ _logger.exception('API Error when asking for sending Pingen Document %s to %s.' %
+ (document.id, pingen.url))
raise
- task.write(
+ document.write(
{'last_error_message': False,
'state': 'sendcenter',
'post_id': post_id},
context=context)
- _logger.info('Pingen Task %s: asked for sending to %s' % (task.id, pingen.url))
+ _logger.info('Pingen Document %s: asked for sending to %s' % (document.id, pingen.url))
return True
@@ -219,37 +221,41 @@ class pingen_task(orm.Model):
Wrapper method for multiple ids (when triggered from button for
instance) for public interface.
"""
- for task in self.browse(cr, uid, ids, context=context):
+ for document in self.browse(cr, uid, ids, context=context):
try:
- self._ask_pingen_send(cr, uid, task, context=context)
+ self._ask_pingen_send(cr, uid, document, context=context)
except ConnectionError as e:
raise osv.except_osv(
_('Pingen Connection Error'),
- _('Connection Error when asking for sending the document %s to Pingen') % task.name)
+ _('Connection Error when asking for '
+ 'sending the document %s to Pingen') % document.name)
except APIError as e:
raise osv.except_osv(
_('Pingen Error'),
_('Error when asking Pingen to send the document %s: '
- '\n%s') % (task.name, e))
+ '\n%s') % (document.name, e))
return True
- def _update_post_infos(self, cr, uid, task, context=None):
+ def _update_post_infos(self, cr, uid, document, context=None):
""" Update the informations from pingen of a document in the Sendcenter
"""
- if not task.post_id:
+ if not document.post_id:
return
pingen = self._pingen(cr, uid, [], context=context)
try:
- post_infos = pingen.post_infos(task.post_id)
+ post_infos = pingen.post_infos(document.post_id)
except ConnectionError as e:
- _logger.exception('Connection Error when asking for sending Pingen Task %s to %s.' %
- (task.id, pingen.url))
+ _logger.exception(
+ 'Connection Error when asking for '
+ 'sending Pingen Document %s to %s.' %
+ (document.id, pingen.url))
raise
except APIError as e:
- _logger.exception('API Error when asking for sending Pingen Task %s to %s.' %
- (task.id, pingen.url))
+ _logger.exception(
+ 'API Error when asking for sending Pingen Document %s to %s.' %
+ (document.id, pingen.url))
raise
currency_ids = self.pool.get('res.currency').search(
@@ -268,8 +274,8 @@ class pingen_task(orm.Model):
if pingen.is_posted(post_infos):
vals['state'] = 'sent'
- task.write(vals, context=context)
- _logger.info('Pingen Task %s: status updated' % task.id)
+ document.write(vals, context=context)
+ _logger.info('Pingen Document %s: status updated' % document.id)
def _update_post_infos_silent(self, cr, uid, ids, context=None):
""" Update the informations from pingen of a document in the Sendcenter
@@ -282,9 +288,9 @@ class pingen_task(orm.Model):
[('state', '=', 'sendcenter')],
context=context)
- for task in self.browse(cr, uid, ids, context=context):
+ for document in self.browse(cr, uid, ids, context=context):
try:
- self._update_post_infos(cr, uid, task, context=context)
+ self._update_post_infos(cr, uid, document, context=context)
except (ConnectionError, APIError):
# Intended silented exception, we can consider that it's not
# important if the update not worked, that's
@@ -299,19 +305,19 @@ class pingen_task(orm.Model):
Wrapper method for multiple ids (when triggered from button for
instance) for public interface.
"""
- for task in self.browse(cr, uid, ids, context=context):
+ for document in self.browse(cr, uid, ids, context=context):
try:
- self._update_post_infos(cr, uid, task, context=context)
+ self._update_post_infos(cr, uid, document, context=context)
except ConnectionError as e:
raise osv.except_osv(
_('Pingen Connection Error'),
_('Connection Error when updating the status of Document %s'
- ' from Pingen') % task.name)
+ ' from Pingen') % document.name)
except APIError as e:
raise osv.except_osv(
_('Pingen Error'),
_('Error when updating the status of Document %s from Pingen: '
- '\n%s') % (task.name, e))
+ '\n%s') % (document.name, e))
return True
diff --git a/pingen/pingen_task_view.xml b/pingen/pingen_document_view.xml
similarity index 84%
rename from pingen/pingen_task_view.xml
rename to pingen/pingen_document_view.xml
index f036d4e..44c6cc9 100644
--- a/pingen/pingen_task_view.xml
+++ b/pingen/pingen_document_view.xml
@@ -2,12 +2,12 @@
-
- pingen.task.tree
- pingen.task
+
+ pingen.document.tree
+ pingen.document
tree
-
+
@@ -18,12 +18,12 @@
-
- pingen.task.form
- pingen.task
+
+ pingen.document.form
+ pingen.document
form
-
-
- pingen.task.search
- pingen.task
+
+ pingen.document.search
+ pingen.document
search
-
+
@@ -132,16 +132,16 @@
-
- Pingen Tasks
+
+ Pingen Documents
ir.actions.act_window
- pingen.task
+ pingen.document
form
tree,form
-
+
-
+