[ADD] remote_report_to_printer

This commit is contained in:
Enric Tobella
2018-06-20 13:13:37 +02:00
committed by Olga Marco
parent 0309095e9b
commit c96fbca65d
16 changed files with 564 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
from . import ir_actions_report
from . import res_remote
from . import res_remote_printer
from . import printing_action

View File

@@ -0,0 +1,22 @@
# Copyright (c) 2018 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models
class IrActionsReport(models.Model):
_inherit = 'ir.actions.report'
@api.multi
def _get_user_default_print_behaviour(self):
res = super()._get_user_default_print_behaviour()
if res.get('action', 'unknown') == 'remote_default':
res.update(self.remote.get_printer_behaviour())
return res
@api.multi
def _get_report_default_print_behaviour(self):
res = super()._get_report_default_print_behaviour()
if res.get('action', 'unknown') == 'remote_default':
res.update(self.remote.get_printer_behaviour())
return res

View File

@@ -0,0 +1,18 @@
# Copyright (c) 2018 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class PrintingAction(models.Model):
_inherit = 'printing.action'
@api.model
def _available_action_types(self):
res = super()._available_action_types()
res.append(('remote_default', "Use remote's default"))
return res
action_type = fields.Selection(
selection=_available_action_types,
)

View File

@@ -0,0 +1,28 @@
# Copyright (c) 2018 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ResRemote(models.Model):
_inherit = 'res.remote'
remote_printer_ids = fields.One2many(
'res.remote.printer',
inverse_name='remote_id',
)
@api.multi
def get_printer_behaviour(self):
self.ensure_one()
printer_usage = self.env.context.get('printer_usage', 'standard')
printers = self.remote.remote_printer_ids.filtered(
lambda r: r.printer_usage == printer_usage
).sorted(key='is_default', reverse=True)
if printers:
printer = printers[0]
return {
'action': 'server',
'printer': printer.printer_id,
'tray': printer.printer_tray_id.system_name
}
return {'action': 'client'}

View File

@@ -0,0 +1,48 @@
# Copyright (c) 2018 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
class ResRemotePrinter(models.Model):
_name = 'res.remote.printer'
remote_id = fields.Many2one(
'res.remote',
ondelete='cascade',
readonly=True,
)
printer_id = fields.Many2one(
'printing.printer',
ondelete='cascade',
)
printer_tray_id = fields.Many2one(
'printing.tray',
ondelete='cascade',
domain="[('printer_id', '=', printer_id)]",
)
is_default = fields.Boolean(default=False)
printer_usage = fields.Selection([
('standard', 'Standard')
], default='standard')
_sql_constraints = [
('unique_printer_remote_usage',
'unique(remote_id,printer_id,printer_usage)',
'A Remote cannot have the same printer for the same usage')
]
@api.onchange('printer_id')
def _onchange_printing_printer_id(self):
""" Reset the tray when the printer is changed """
self.printer_tray_id = False
@api.multi
@api.constrains('remote_id', 'printer_usage', 'is_default')
def _check_remote_usage(self):
for rec in self.filtered(lambda r: r.is_default):
if rec.remote_id.remote_printer_ids.filtered(
lambda r: r != rec and r.is_default
and r.printer_usage == rec.printer_usage
):
raise ValidationError(_('Only one default printer is allowed'))