~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to printjob/wizard/reprint.py

  • Committer: HDA(OpenERP)
  • Author(s): Ferran Pegueroles
  • Date: 2009-10-27 06:16:44 UTC
  • mto: (3909.1.76 extra)
  • mto: This revision was merged to the branch mainline in revision 3912.
  • Revision ID: hda@tinyerp.com-20091027061644-cnu6k7yxw0bmqaln
Added printjob module

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2009 Ferran Pegueroles <ferran@pegueroles.com>
 
5
#
 
6
# WARNING: This program as such is intended to be used by professional
 
7
# programmers who take the whole responsability of assessing all potential
 
8
# consequences resulting from its eventual inadequacies and bugs
 
9
# End users who are looking for a ready-to-use solution with commercial
 
10
# garantees and support are strongly adviced to contract a Free Software
 
11
# Service Company
 
12
#
 
13
# This program is Free Software; you can redistribute it and/or
 
14
# modify it under the terms of the GNU General Public License
 
15
# as published by the Free Software Foundation; either version 2
 
16
# of the License, or (at your option) any later version.
 
17
#
 
18
# This program is distributed in the hope that it will be useful,
 
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
# GNU General Public License for more details.
 
22
#
 
23
# You should have received a copy of the GNU General Public License
 
24
# along with this program; if not, write to the Free Software
 
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
26
#
 
27
##############################################################################
 
28
#
 
29
# Reprint
 
30
#
 
31
import os, base64
 
32
import time
 
33
import wizard
 
34
import pooler 
 
35
from tempfile import mkstemp
 
36
 
 
37
print_form = '''<?xml version="1.0"?>
 
38
<form string="Printing">
 
39
    <field name="printer" />
 
40
</form>'''
 
41
print_fields = {
 
42
    'printer' : {'string':'Printer', 'type':'many2one', 'relation':'printjob.printer','required':True},
 
43
}
 
44
 
 
45
class wizard_reprint(wizard.interface):
 
46
 
 
47
    def _get_default_printer(self, cr, uid, data, context):
 
48
 
 
49
        pool = pooler.get_pool(cr.dbname)
 
50
        printer_ids = pool.get('printjob.printer').search(cr, uid,[('is_default','=',True)])
 
51
        if printer_ids:
 
52
           data['form']['printer'] = printer_ids[0]
 
53
        return data['form']
 
54
 
 
55
    def _print(self, cr, uid, data, context):
 
56
        pool= pooler.get_pool(cr.dbname)
 
57
        printer_obj = pool.get('printjob.printer')
 
58
        printer_reg = printer_obj.read(cr, uid, [data['form']['printer']])[0]
 
59
        job_obj = pool.get('printjob.job')
 
60
        job_reg = job_obj.read(cr, uid, data['ids'])[0]
 
61
        tmpfile=mkstemp()
 
62
        os.write(tmpfile[0],base64.decodestring(job_reg['result']))
 
63
        os.system("lpr -P %s %s" % (printer_reg['system_name'],tmpfile[1]))
 
64
        return {}
 
65
 
 
66
    states = {
 
67
        'init': {
 
68
            'actions': [_get_default_printer],
 
69
            'result': {'type':'form', 'arch':print_form, 'fields':print_fields, 'state':[('end','Cancelar'),('print','Imprimir')]}
 
70
        },
 
71
        'print': {
 
72
            'actions': [_print],
 
73
            'result': {'type':'state', 'state':'end'}
 
74
        }
 
75
    }
 
76
 
 
77
wizard_reprint('printjob.job.reprint')
 
78
 
 
79
class wizard_preview(wizard.interface):
 
80
 
 
81
    def _get_id(self, cr, uid, data, context):
 
82
        
 
83
        data['form']['ids'] = [ data['id'] ]
 
84
        return data['form']
 
85
 
 
86
    states = {
 
87
        'init': {
 
88
            'actions': [_get_id],
 
89
            'result': {'type':'print', 'report':'printjob.reprint', 'get_id_from_action':True ,'state':'end'}
 
90
        }
 
91
    }
 
92
 
 
93
wizard_preview('printjob.job.preview')