mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
Merge pull request #13 from guewen/8.0-printer_tray-migr
Migration of printer_tray to 8.0
This commit is contained in:
@@ -1,63 +0,0 @@
|
||||
# -*- 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
|
||||
@@ -1,99 +0,0 @@
|
||||
# -*- 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)
|
||||
if server_error:
|
||||
vals = {'status': 'server_error'}
|
||||
self.write(cr, uid, printer_ids, vals, context=context)
|
||||
return res
|
||||
|
||||
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
|
||||
67
printer_tray/README.rst
Normal file
67
printer_tray/README.rst
Normal file
@@ -0,0 +1,67 @@
|
||||
Report to printer - Paper tray selection
|
||||
========================================
|
||||
|
||||
Extends the module **Report to printer** (``base_report_to_printer``)
|
||||
to add the printers trays.
|
||||
|
||||
It detects trays on printers 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 example for
|
||||
preprinted paper such as payment slip.
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
Considering that you already use the module **Report to printer**, you
|
||||
just have to install this extension.
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
To configure this module, you need to:
|
||||
|
||||
* Update the CUPS printers in *Settings > Printing > Update Printers
|
||||
from CUPS*
|
||||
* If you want to print a report on a specific tray, you can change
|
||||
their "Paper Source" in *Settings > Printing > Reports*
|
||||
* If you want to print a report on a specific tray for a user, you can
|
||||
change their "Paper Source" in *Settings > Printing > Reports* in
|
||||
*Specific actions per user*
|
||||
* Users may also select a default tray in their preferences
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
There is no special usage, once configured, reports are printed in the
|
||||
select tray. When no tray is configured for a report and a user, the
|
||||
default tray setup on the CUPS server is used.
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Yannick Vaucher <yannick.vaucher@camptocamp.com>
|
||||
* Guewen Baconnier <guewen.baconnier@camptocamp.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
.. image:: http://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: http://odoo-community.org
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
|
||||
|
||||
To contribute to this module, please visit http://odoo-community.org.
|
||||
@@ -22,3 +22,4 @@ from . import ir_report
|
||||
from . import printer_tray
|
||||
from . import printer
|
||||
from . import users
|
||||
from . import report_xml_action
|
||||
@@ -21,35 +21,20 @@
|
||||
{'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',
|
||||
'depends': ['base_report_to_printer',
|
||||
],
|
||||
'data': [
|
||||
'users_view.xml',
|
||||
'ir_report_view.xml',
|
||||
'printer_view.xml',
|
||||
'report_xml_action_view.xml',
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'test': [],
|
||||
'installable': False,
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
'application': True,
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# Translation of OpenERP Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * printer_tray
|
||||
# * printer_tray
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
@@ -10,15 +10,56 @@ msgstr ""
|
||||
"PO-Revision-Date: 2014-01-31 16:48+0100\n"
|
||||
"Last-Translator: Yannick Vaucher <yannick.vaucher@camptocamp.com>\n"
|
||||
"Language-Team: \n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: printer_tray
|
||||
#: model:ir.model,name:printer_tray.model_printing_tray
|
||||
msgid "Printer Tray"
|
||||
msgstr "Bac d'impression"
|
||||
#: field:printing.tray,create_uid:0
|
||||
msgid "Created by"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,create_date:0
|
||||
msgid "Created on"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:res.users,printer_tray_id:0
|
||||
msgid "Default Printer Paper Source"
|
||||
msgstr "Source de papier par défaut"
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,id:0
|
||||
msgid "ID"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,write_uid:0
|
||||
msgid "Last Updated by"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,write_date:0
|
||||
msgid "Last Updated on"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,name:0
|
||||
msgid "Name"
|
||||
msgstr "Nom"
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:ir.actions.report.xml,printer_tray_id:0
|
||||
msgid "Paper Source"
|
||||
msgstr "Source de papier"
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.printer,tray_ids:0
|
||||
msgid "Paper Sources"
|
||||
msgstr "Sources de papier"
|
||||
|
||||
#. module: printer_tray
|
||||
#: model:ir.model,name:printer_tray.model_printing_printer
|
||||
@@ -27,37 +68,21 @@ msgid "Printer"
|
||||
msgstr "Imprimante"
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:res.users,printer_tray_id:0
|
||||
msgid "Default Printer Paper Source"
|
||||
msgstr "Source de papier par défaut"
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,name:0
|
||||
msgid "Name"
|
||||
msgstr "Nom"
|
||||
#: model:ir.model,name:printer_tray.model_printing_tray
|
||||
msgid "Printer Tray"
|
||||
msgstr "Bac d'impression"
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,system_name:0
|
||||
msgid "System Name"
|
||||
msgid "System name"
|
||||
msgstr "Nom système"
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.printer,tray_ids:0
|
||||
msgid "Paper Sources"
|
||||
msgstr "Sources de papier"
|
||||
#: view:printing.printer:printer_tray.view_printing_printer_form
|
||||
msgid "Trays"
|
||||
msgstr "Bacs d'impression"
|
||||
|
||||
#. module: printer_tray
|
||||
#: model:ir.model,name:printer_tray.model_res_users
|
||||
msgid "Users"
|
||||
msgstr "Utilisateur"
|
||||
|
||||
#. module: printer_tray
|
||||
#: model:ir.model,name:printer_tray.model_ir_actions_report_xml
|
||||
msgid "ir.actions.report.xml"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:ir.actions.report.xml,printer_tray_id:0
|
||||
msgid "Paper Source"
|
||||
msgstr "Source de papier"
|
||||
|
||||
@@ -1,23 +1,64 @@
|
||||
# Translation of OpenERP Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * printer_tray
|
||||
# * printer_tray
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: OpenERP Server 7.0\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2014-01-31 15:44+0000\n"
|
||||
"PO-Revision-Date: 2014-01-31 16:48+0100\n"
|
||||
"PO-Revision-Date: 2014-11-18 08:58+0000\n"
|
||||
"Last-Translator: Yannick Vaucher <yannick.vaucher@camptocamp.com>\n"
|
||||
"Language-Team: \n"
|
||||
"Language: \n"
|
||||
"MIME-Version: 1.0\n"
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
"Plural-Forms: \n"
|
||||
|
||||
#. module: printer_tray
|
||||
#: model:ir.model,name:printer_tray.model_printing_tray
|
||||
msgid "Printer Tray"
|
||||
#: field:printing.tray,create_uid:0
|
||||
msgid "Created by"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,create_date:0
|
||||
msgid "Created on"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:res.users,printer_tray_id:0
|
||||
msgid "Default Printer Paper Source"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,id:0
|
||||
msgid "ID"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,write_uid:0
|
||||
msgid "Last Updated by"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,write_date:0
|
||||
msgid "Last Updated on"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,name:0
|
||||
msgid "Name"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:ir.actions.report.xml,printer_tray_id:0
|
||||
msgid "Paper Source"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.printer,tray_ids:0
|
||||
msgid "Paper Sources"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
@@ -27,37 +68,21 @@ msgid "Printer"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:res.users,printer_tray_id:0
|
||||
msgid "Default Printer Paper Source"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,name:0
|
||||
msgid "Name"
|
||||
#: model:ir.model,name:printer_tray.model_printing_tray
|
||||
msgid "Printer Tray"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.tray,system_name:0
|
||||
msgid "System Name"
|
||||
msgid "System name"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:printing.printer,tray_ids:0
|
||||
msgid "Paper Sources"
|
||||
#: view:printing.printer:printer_tray.view_printing_printer_form
|
||||
msgid "Trays"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: model:ir.model,name:printer_tray.model_res_users
|
||||
msgid "Users"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: model:ir.model,name:printer_tray.model_ir_actions_report_xml
|
||||
msgid "ir.actions.report.xml"
|
||||
msgstr ""
|
||||
|
||||
#. module: printer_tray
|
||||
#: field:ir.actions.report.xml,printer_tray_id:0
|
||||
msgid "Paper Source"
|
||||
msgstr ""
|
||||
|
||||
37
printer_tray/ir_report.py
Normal file
37
printer_tray/ir_report.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# -*- 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 import models, fields, api
|
||||
|
||||
|
||||
class IrActionsReportXml(models.Model):
|
||||
|
||||
_inherit = 'ir.actions.report.xml'
|
||||
|
||||
printer_tray_id = fields.Many2one(
|
||||
comodel_name='printing.tray',
|
||||
string='Paper Source',
|
||||
domain="[('printer_id', '=', printing_printer_id)]",
|
||||
)
|
||||
|
||||
@api.onchange('printing_printer_id')
|
||||
def onchange_printing_printer_id(self):
|
||||
""" Reset the tray when the printer is changed """
|
||||
self.printer_tray_id = False
|
||||
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
|
||||
import errno
|
||||
import os
|
||||
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class Printer(models.Model):
|
||||
_inherit = 'printing.printer'
|
||||
|
||||
tray_ids = fields.One2many(comodel_name='printing.tray',
|
||||
inverse_name='printer_id',
|
||||
string='Paper Sources')
|
||||
|
||||
@api.multi
|
||||
def _prepare_update_from_cups(self, cups_connection, cups_printer):
|
||||
vals = super(Printer, self)._prepare_update_from_cups(cups_connection,
|
||||
cups_printer)
|
||||
|
||||
ppd_info = cups_connection.getPPD3(self.system_name)
|
||||
ppd_path = ppd_info[2]
|
||||
if not ppd_path:
|
||||
return vals
|
||||
|
||||
ppd = cups.PPD(ppd_path)
|
||||
option = ppd.findOption('InputSlot')
|
||||
try:
|
||||
os.unlink(ppd_path)
|
||||
except OSError as err:
|
||||
if err.errno == errno.ENOENT:
|
||||
pass
|
||||
raise
|
||||
if not option:
|
||||
return vals
|
||||
|
||||
vals_trays = []
|
||||
|
||||
tray_names = set(tray.system_name for tray in self.tray_ids)
|
||||
for tray_option in option.choices:
|
||||
if tray_option['choice'] not in tray_names:
|
||||
tray_vals = {
|
||||
'name': tray_option['text'],
|
||||
'system_name': tray_option['choice'],
|
||||
}
|
||||
vals_trays.append((0, 0, tray_vals))
|
||||
|
||||
cups_trays = set(tray_option['choice'] for tray_option
|
||||
in option.choices)
|
||||
for tray in self.tray_ids:
|
||||
if tray.system_name not in cups_trays:
|
||||
vals_trays.append((2, tray.id))
|
||||
|
||||
vals['tray_ids'] = vals_trays
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def print_options(self, report, format):
|
||||
""" Hook to define Tray """
|
||||
printing_act_obj = self.env['printing.report.xml.action']
|
||||
options = super(Printer, self).print_options(report, format)
|
||||
|
||||
# Retrieve user default values
|
||||
user = self.env.user
|
||||
tray = user.printer_tray_id
|
||||
|
||||
# Retrieve report default values
|
||||
if report.printer_tray_id:
|
||||
tray = report.printer_tray_id
|
||||
|
||||
# Retrieve report-user specific values
|
||||
action = printing_act_obj.search([('report_id', '=', report.id),
|
||||
('user_id', '=', self.env.uid),
|
||||
('action', '!=', 'user_default')],
|
||||
limit=1)
|
||||
if action and action.printer_tray_id:
|
||||
tray = action.tray_id
|
||||
|
||||
if tray:
|
||||
options['InputSlot'] = str(tray.system_name)
|
||||
return options
|
||||
@@ -18,16 +18,20 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from openerp.osv import orm, fields
|
||||
from openerp import models, fields
|
||||
|
||||
|
||||
class PrinterTray(orm.Model):
|
||||
class PrinterTray(models.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),
|
||||
}
|
||||
name = fields.Char(required=True)
|
||||
system_name = fields.Char(required=True, readonly=True)
|
||||
printer_id = fields.Many2one(
|
||||
comodel_name='printing.printer',
|
||||
string='Printer',
|
||||
required=True,
|
||||
readonly=True,
|
||||
ondelete='cascade',
|
||||
)
|
||||
25
printer_tray/printer_view.xml
Normal file
25
printer_tray/printer_view.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="0">
|
||||
<record model="ir.ui.view" id="view_printing_printer_form">
|
||||
<field name="name">printing.printer.form</field>
|
||||
<field name="model">printing.printer</field>
|
||||
<field name="inherit_id" ref="base_report_to_printer.view_printing_printer_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//sheet/group[3]" position="after">
|
||||
<group string="Trays">
|
||||
<field name="tray_ids" nolabel="1">
|
||||
<form>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="system_name"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</group>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -19,20 +19,26 @@
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import orm, fields
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class ReportXMLAction(orm.Model):
|
||||
class ReportXMLAction(models.Model):
|
||||
_inherit = 'printing.report.xml.action'
|
||||
|
||||
_columns = {
|
||||
'printer_tray_id': fields.many2one(
|
||||
'printing.tray', 'Paper Source',
|
||||
domain="[('printer_id', '=', printer_id)]"),
|
||||
}
|
||||
printer_tray_id = fields.Many2one(
|
||||
comodel_name='printing.tray',
|
||||
string='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
|
||||
@api.multi
|
||||
def behaviour(self):
|
||||
self.ensure_one()
|
||||
res = super(ReportXMLAction, self).behaviour()
|
||||
res['tray'] = self.printer_tray_id.system_name
|
||||
return res
|
||||
|
||||
@api.onchange('printer_id')
|
||||
def onchange_printer_id(self):
|
||||
""" Reset the tray when the printer is changed """
|
||||
self.printer_tray_id = False
|
||||
25
printer_tray/report_xml_action_view.xml
Normal file
25
printer_tray/report_xml_action_view.xml
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="0">
|
||||
<record id="view_printing_report_xml_action_form" model="ir.ui.view">
|
||||
<field name="name">printing.report.xml.action.form</field>
|
||||
<field name="model">printing.report.xml.action</field>
|
||||
<field name="inherit_id" ref="base_report_to_printer.printing_report_xml_action_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='printer_id']" position="after">
|
||||
<field name="printer_tray_id"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_printing_report_xml_action_tree" model="ir.ui.view">
|
||||
<field name="name">printing.report.xml.action.form</field>
|
||||
<field name="model">printing.report.xml.action</field>
|
||||
<field name="inherit_id" ref="base_report_to_printer.printing_report_xml_action_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='printer_id']" position="after">
|
||||
<field name="printer_tray_id"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -18,15 +18,20 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from openerp.osv import orm, fields
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class ResUsers(orm.Model):
|
||||
class ResUsers(models.Model):
|
||||
|
||||
_inherit = "res.users"
|
||||
|
||||
_columns = {
|
||||
'printer_tray_id': fields.many2one(
|
||||
'printing.tray', 'Default Printer Paper Source',
|
||||
domain="[('printer_id', '=', printing_printer_id)]"),
|
||||
}
|
||||
printer_tray_id = fields.Many2one(
|
||||
comodel_name='printing.tray',
|
||||
string='Default Printer Paper Source',
|
||||
domain="[('printer_id', '=', printing_printer_id)]",
|
||||
)
|
||||
|
||||
@api.onchange('printing_printer_id')
|
||||
def onchange_printing_printer_id(self):
|
||||
""" Reset the tray when the printer is changed """
|
||||
self.printer_tray_id = False
|
||||
@@ -14,5 +14,17 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- res.users form view (My preferences popup) -->
|
||||
<record model="ir.ui.view" id="view_users_form">
|
||||
<field name="name">res.users.form.printing.tray</field>
|
||||
<field name="model">res.users</field>
|
||||
<field name="inherit_id" ref="base_report_to_printer.view_printing_users_prefs" />
|
||||
<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