[IMP] remote_report_to_printer: black, isort, prettier

This commit is contained in:
Olga Marco
2021-06-17 16:57:44 +02:00
committed by Enric Tobella
parent ae1cc7eb1d
commit d9b68f2e77
10 changed files with 207 additions and 222 deletions

View File

@@ -5,18 +5,18 @@ from odoo import api, models
class IrActionsReport(models.Model):
_inherit = 'ir.actions.report'
_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':
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':
if res.get("action", "unknown") == "remote_default":
res.update(self.remote.get_printer_behaviour())
return res

View File

@@ -5,14 +5,12 @@ from odoo import api, fields, models
class PrintingAction(models.Model):
_inherit = 'printing.action'
_inherit = "printing.action"
@api.model
def _available_action_types(self):
res = super()._available_action_types()
res.append(('remote_default', "Use remote's default"))
res.append(("remote_default", "Use remote's default"))
return res
action_type = fields.Selection(
selection=_available_action_types,
)
action_type = fields.Selection(selection=_available_action_types,)

View File

@@ -4,25 +4,24 @@ from odoo import api, fields, models
class ResRemote(models.Model):
_inherit = 'res.remote'
_inherit = "res.remote"
remote_printer_ids = fields.One2many(
'res.remote.printer',
inverse_name='remote_id',
"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')
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)
).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
"action": "server",
"printer": printer.printer_id,
"tray": printer.printer_tray_id.system_name,
}
return {'action': 'client'}
return {"action": "client"}

View File

@@ -1,49 +1,41 @@
# 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 import _, api, fields, models
from odoo.exceptions import ValidationError
class ResRemotePrinter(models.Model):
_name = 'res.remote.printer'
_description = 'Remote Printer'
_name = "res.remote.printer"
_description = "Remote Printer"
remote_id = fields.Many2one(
'res.remote',
ondelete='cascade',
readonly=True,
)
printer_id = fields.Many2one(
'printing.printer',
ondelete='cascade',
)
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)]",
"printing.tray", ondelete="cascade", domain="[('printer_id', '=', printer_id)]",
)
is_default = fields.Boolean(default=False)
printer_usage = fields.Selection([
('standard', 'Standard')
], default='standard')
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')
(
"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')
@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')
@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
lambda r: r != rec
and r.is_default
and r.printer_usage == rec.printer_usage
):
raise ValidationError(_('Only one default printer is allowed'))
raise ValidationError(_("Only one default printer is allowed"))