mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[IMP] rename pingen.task to pingen.document
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user