mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
[ADD] module printer_tray
This commit is contained in:
24
printer_tray/__init__.py
Normal file
24
printer_tray/__init__.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Author: Yannick Vaucher
|
||||||
|
# Copyright 2013 Camptocamp SA
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
from . import ir_report
|
||||||
|
from . import printer_tray
|
||||||
|
from . import printer
|
||||||
|
from . import users
|
||||||
55
printer_tray/__openerp__.py
Normal file
55
printer_tray/__openerp__.py
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Author: Yannick Vaucher
|
||||||
|
# Copyright 2013 Camptocamp SA
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
{'name' : 'Report to printer - Paper tray selection',
|
||||||
|
'version' : '1.0',
|
||||||
|
'category': 'Printer',
|
||||||
|
'description': """
|
||||||
|
Report to printer - Paper tray selection
|
||||||
|
========================================
|
||||||
|
|
||||||
|
**Author:** Camptocamp SA
|
||||||
|
|
||||||
|
*This module extends `Report to printer` module.*
|
||||||
|
|
||||||
|
It detects trays on printer installation plus permits to select
|
||||||
|
the paper source on which you want to print directly.
|
||||||
|
|
||||||
|
You will find this option on default user config, on default report config
|
||||||
|
and on specific config per user per report.
|
||||||
|
|
||||||
|
This allows you to dedicate a specific paper source for exemple for prepinted
|
||||||
|
paper such as payment slip.
|
||||||
|
""",
|
||||||
|
'author' : 'Camptocamp',
|
||||||
|
'maintainer': 'Camptocamp',
|
||||||
|
'website': 'http://www.camptocamp.com/',
|
||||||
|
'depends' : ['base_report_assembler',
|
||||||
|
'base_report_to_printer',
|
||||||
|
],
|
||||||
|
'data': [
|
||||||
|
'users_view.xml',
|
||||||
|
'ir_report_view.xml',
|
||||||
|
],
|
||||||
|
'test': [],
|
||||||
|
'installable': True,
|
||||||
|
'auto_install': False,
|
||||||
|
'application': True,
|
||||||
|
}
|
||||||
61
printer_tray/ir_report.py
Normal file
61
printer_tray/ir_report.py
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Author: Yannick Vaucher
|
||||||
|
# Copyright 2013 Camptocamp SA
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
from openerp.osv import orm, fields
|
||||||
|
|
||||||
|
class ReportXML(orm.Model):
|
||||||
|
|
||||||
|
_inherit = 'ir.actions.report.xml'
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'printer_tray_id': fields.many2one('printing.tray', 'Paper Source',
|
||||||
|
domain="[('printer_id', '=', printing_printer_id)]"),
|
||||||
|
}
|
||||||
|
|
||||||
|
def set_print_options(self, cr, uid, report_id, format, context=None):
|
||||||
|
"""
|
||||||
|
Hook to define Tray
|
||||||
|
"""
|
||||||
|
printing_act_obj = self.pool.get('printing.report.xml.action')
|
||||||
|
options = super(ReportXML, self).set_print_options(cr, uid, report_id, format, context=context)
|
||||||
|
|
||||||
|
# Retrieve user default values
|
||||||
|
user = self.pool.get('res.users').browse(cr, uid, context)
|
||||||
|
tray = user.printer_tray_id
|
||||||
|
report = self.browse(cr, uid, report_id, context=context)
|
||||||
|
|
||||||
|
# Retrieve report default values
|
||||||
|
if report.printer_tray_id:
|
||||||
|
tray = report.printer_tray_id
|
||||||
|
|
||||||
|
# Retrieve report-user specific values
|
||||||
|
act_ids = printing_act_obj.search(cr, uid,
|
||||||
|
[('report_id', '=', report.id),
|
||||||
|
('user_id', '=', uid),
|
||||||
|
('action', '!=', 'user_default')], context=context)
|
||||||
|
if act_ids:
|
||||||
|
user_action = printing_act_obj.browse(cr, uid, act_ids[0], context=context)
|
||||||
|
if user_action.tray_id:
|
||||||
|
tray = user_action.tray_id
|
||||||
|
|
||||||
|
if tray:
|
||||||
|
options['InputSlot'] = str(tray.system_name)
|
||||||
|
return options
|
||||||
|
|
||||||
18
printer_tray/ir_report_view.xml
Normal file
18
printer_tray/ir_report_view.xml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<!-- ir.report form view -->
|
||||||
|
<record model="ir.ui.view" id="action_report_xml_form">
|
||||||
|
<field name="name">ir.actions.report.xml.add.printer.tray</field>
|
||||||
|
<field name="model">ir.actions.report.xml</field>
|
||||||
|
<field name="inherit_id" ref="base_report_to_printer.action_report_xml_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="printing_printer_id" position="after">
|
||||||
|
<field name="printer_tray_id"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
||||||
100
printer_tray/printer.py
Normal file
100
printer_tray/printer.py
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Author: Yannick Vaucher
|
||||||
|
# Copyright 2013 Camptocamp SA
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
import cups
|
||||||
|
from cups import PPD
|
||||||
|
|
||||||
|
from openerp import pooler
|
||||||
|
from openerp.osv import orm, fields
|
||||||
|
|
||||||
|
class Printer(orm.Model):
|
||||||
|
|
||||||
|
_inherit = 'printing.printer'
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'tray_ids': fields.one2many('printing.tray', 'printer_id', 'Paper Sources'),
|
||||||
|
}
|
||||||
|
|
||||||
|
def _update_tray_option(self, db_name, uid, printer, context=None):
|
||||||
|
"""
|
||||||
|
Create missing tray for a printer
|
||||||
|
"""
|
||||||
|
db, pool = pooler.get_db_and_pool(db_name)
|
||||||
|
cr = db.cursor()
|
||||||
|
tray_obj = pool.get('printing.tray')
|
||||||
|
# get printers options from a PPD file
|
||||||
|
try:
|
||||||
|
connection = cups.Connection()
|
||||||
|
ppd_file_path = connection.getPPD3(printer.system_name)
|
||||||
|
except:
|
||||||
|
return
|
||||||
|
|
||||||
|
if not ppd_file_path[2]:
|
||||||
|
return
|
||||||
|
ppd = PPD(ppd_file_path[2])
|
||||||
|
option = ppd.findOption('InputSlot')
|
||||||
|
if not option:
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
for tray_opt in option.choices:
|
||||||
|
if tray_opt['choice'] not in [t.system_name for t in printer.tray_ids]:
|
||||||
|
tray_vals = {
|
||||||
|
'name': tray_opt['text'],
|
||||||
|
'system_name': tray_opt['choice'],
|
||||||
|
'printer_id': printer.id,
|
||||||
|
}
|
||||||
|
|
||||||
|
tray_obj.create(cr, uid, tray_vals, context=context)
|
||||||
|
|
||||||
|
cr.commit()
|
||||||
|
except:
|
||||||
|
cr.rollback()
|
||||||
|
raise
|
||||||
|
finally:
|
||||||
|
cr.close()
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def update_printers_status(self, db_name, uid, context=None):
|
||||||
|
"""
|
||||||
|
Add creation of tray if no tray are defined
|
||||||
|
"""
|
||||||
|
db, pool = pooler.get_db_and_pool(db_name)
|
||||||
|
cr = db.cursor()
|
||||||
|
res = super(Printer, self).update_printers_status(db_name, uid, context=context)
|
||||||
|
|
||||||
|
try:
|
||||||
|
connection = cups.Connection()
|
||||||
|
printers = connection.getPrinters()
|
||||||
|
server_error = False
|
||||||
|
except:
|
||||||
|
server_error = True
|
||||||
|
|
||||||
|
printer_ids = self.search(cr, uid, [('system_name', 'in', printers.keys())], context=context)
|
||||||
|
printer_list = self.browse(cr, uid, printer_ids, context=context)
|
||||||
|
|
||||||
|
for printer in printer_list:
|
||||||
|
# XXX we consider config of printer won't change
|
||||||
|
if not printer.tray_ids:
|
||||||
|
self._update_tray_option(db_name, uid, printer, context=context)
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
32
printer_tray/printer_tray.py
Normal file
32
printer_tray/printer_tray.py
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Author: Yannick Vaucher
|
||||||
|
# Copyright 2013 Camptocamp SA
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
from openerp.osv import orm, fields
|
||||||
|
|
||||||
|
class PrinterTray(orm.Model):
|
||||||
|
|
||||||
|
_name = 'printing.tray'
|
||||||
|
_description = 'Printer Tray'
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'name': fields.char('Name', size=64, required=True),
|
||||||
|
'system_name': fields.char('System Name', size=64, required=True),
|
||||||
|
'printer_id': fields.many2one('printing.printer', 'Printer', required=True),
|
||||||
|
}
|
||||||
39
printer_tray/report_xml_action.py
Normal file
39
printer_tray/report_xml_action.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Author: Yannick Vaucher
|
||||||
|
# Copyright 2013 Camptocamp SA
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
from openerp.osv import orm, fields
|
||||||
|
|
||||||
|
class ReportXMLAction(orm.Model):
|
||||||
|
_inherit = 'printing.report.xml.action'
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'printer_tray_id': fields.many2one('printing.tray', 'Paper Source',
|
||||||
|
domain="[('printer_id', '=', printer_id)]"),
|
||||||
|
}
|
||||||
|
|
||||||
|
def behaviour(self, cr, uid, act_id, context=None):
|
||||||
|
res = super(ReportXMLAction, self).behaviour(cr, uid, act_id, context=context)
|
||||||
|
action = self.browse(cr, uid, act_id, context=context)
|
||||||
|
res['tray'] = action.printer_tray_id.system_name
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
30
printer_tray/users.py
Normal file
30
printer_tray/users.py
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Author: Yannick Vaucher
|
||||||
|
# Copyright 2013 Camptocamp SA
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
from openerp.osv import orm, fields
|
||||||
|
|
||||||
|
class ResUsers(orm.Model):
|
||||||
|
|
||||||
|
_inherit = "res.users"
|
||||||
|
|
||||||
|
_columns = {
|
||||||
|
'printer_tray_id': fields.many2one('printing.tray', 'Default Printer Paper Source',
|
||||||
|
domain="[('printer_id', '=', printing_printer_id)]"),
|
||||||
|
}
|
||||||
18
printer_tray/users_view.xml
Normal file
18
printer_tray/users_view.xml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<!-- res.users form view -->
|
||||||
|
<record model="ir.ui.view" id="view_users_form">
|
||||||
|
<field name="name">res.users.form.add.printer.tray</field>
|
||||||
|
<field name="model">res.users</field>
|
||||||
|
<field name="inherit_id" ref="base_report_to_printer.view_printing_users_form" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="printing_printer_id" position="after">
|
||||||
|
<field name="printer_tray_id"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</data>
|
||||||
|
</openerp>
|
||||||
Reference in New Issue
Block a user