[FIX] Review fixes

This commit is contained in:
Sylvain GARANCHER
2017-10-04 11:54:34 +02:00
parent 49062b590e
commit 9b48d16771
9 changed files with 46 additions and 39 deletions

View File

@@ -8,7 +8,7 @@
{
'name': "Report to printer",
'version': '10.0.1.0.1',
'version': '11.0.1.0.1',
'category': 'Generic Modules/Base',
'author': "Agile Business Group & Domsense, Pegueroles SCP, NaN,"
" LasLabs, Odoo Community Association (OCA)",

View File

@@ -94,8 +94,9 @@ class IrActionsReport(models.Model):
@api.multi
def print_document(self, record_ids, data=None):
""" Print a document, do not return the document file """
document = self.with_context(must_skip_send_to_printer=True).render_qweb_pdf(
record_ids, data=data)
document = self.with_context(
must_skip_send_to_printer=True).render_qweb_pdf(
record_ids, data=data)
behaviour = self.behaviour()[self]
printer = behaviour['printer']
if not printer:
@@ -124,7 +125,7 @@ class IrActionsReport(models.Model):
If the action configured on the report is server, it prints the
generated document as well.
"""
document = super(IrActionsReport, self).render_qweb_pdf(
document, doc_format = super(IrActionsReport, self).render_qweb_pdf(
docids, data=data)
behaviour = self.behaviour()[self]
@@ -134,4 +135,4 @@ class IrActionsReport(models.Model):
if can_print_report:
printer.print_document(self, document, self.report_type)
return document
return document, doc_format

View File

@@ -126,10 +126,15 @@ class PrintingPrinter(models.Model):
return
self.ensure_one()
default_printers = self.search([('default', '=', True)])
default_printers.write({'default': False})
default_printers.unset_default()
self.write({'default': True})
return True
@api.multi
def unset_default(self):
self.write({'default': False})
return True
@api.multi
def get_default(self):
return self.search([('default', '=', True)], limit=1)

View File

@@ -190,13 +190,13 @@ class PrintingServer(models.Model):
datetime.fromtimestamp(job_data.get(
'time-at-creation', False))),
'time_at_processing': job_data.get(
'time-at-processing', False) and fields.Datetime.to_string(
datetime.fromtimestamp(job_data.get(
'time-at-processing', False))),
'time-at-processing', False) and
fields.Datetime.to_string(datetime.fromtimestamp(
job_data.get('time-at-processing', False))),
'time_at_completed': job_data.get(
'time-at-completed', False) and fields.Datetime.to_string(
datetime.fromtimestamp(job_data.get(
'time-at-completed', False))),
'time-at-completed', False) and
fields.Datetime.to_string(datetime.fromtimestamp(
job_data.get('time-at-completed', False))),
}
# Search for the printer in Odoo

View File

@@ -8,27 +8,23 @@ odoo.define('base_report_to_printer.print', function(require) {
ActionManager.include({
ir_actions_report: function(action, options) {
action = _.clone(action);
action_val = _.clone(action);
var _t = core._t;
var self = this;
var _super = this._super;
if ('report_type' in action && action.report_type === 'qweb-pdf') {
if ('report_type' in action_val && action_val.report_type === 'qweb-pdf') {
framework.blockUI();
new Model('ir.actions.report')
.call('print_action_for_report_name', [action.report_name])
.then(function(print_action){
if (print_action && print_action.action === 'server') {
new Model('ir.actions.report').
call('print_action_for_report_name', [action_val.report_name]).
then(function(print_action){
if (print_action && print_action.action_val === 'server') {
framework.unblockUI();
new Model('report')
.call('print_document',
[action.context.active_ids,
action.report_name,
],
{data: action.data || {},
context: action.context || {},
})
.then(function(){
new Model('report').
call('print_document',
[action_val.context.active_ids, action_val.report_name],
{data: action_val.data || {}, context: action_val.context || {}}).
then(function(){
self.do_notify(_t('Report'),
_t('Document sent to the printer ') + print_action.printer_name);
}).fail(function() {
@@ -37,14 +33,12 @@ odoo.define('base_report_to_printer.print', function(require) {
});
} else {
return _super.apply(self, [action, options]);
return _super.apply(self, [action_val, options]);
}
});
} else {
return _super.apply(self, [action, options]);
return _super.apply(self, [action_val, options]);
}
}
});
});

View File

@@ -107,6 +107,13 @@ class TestPrintingPrinter(TransactionCase):
self.Model.set_default()
self.assertEqual(other_printer, self.Model.get_default())
def test_unset_default(self):
""" It should unset the default state of the printer """
printer = self.new_record()
self.assertTrue(printer.default)
printer.unset_default()
self.assertFalse(printer.default)
@mock.patch('%s.cups' % server_model)
def test_cancel_all_jobs(self, cups):
""" It should cancel all jobs """

View File

@@ -88,7 +88,7 @@ class TestReport(HttpCase):
report.property_printing_action_id.action_type = 'server'
report.printing_printer_id = self.new_printer()
records = self.env[report.model].search([], limit=5)
document = report.render_qweb_pdf(records.ids)
document, doc_format = report.render_qweb_pdf(records.ids)
print_document.assert_called_once_with(
report, document, report.report_type)

View File

@@ -2,7 +2,7 @@
<odoo>
<menuitem name="Printing"
id="printing_menu"
id="printing_menu" sequence="1"
parent="base.menu_administration"
groups="printing_group_manager"
/>
@@ -16,20 +16,20 @@
<header>
<button name="enable" type="object" string="Enable" attrs="{'invisible': [('status', 'in', ('available', 'printing'))]}"/>
<button name="disable" type="object" string="Disable" attrs="{'invisible': [('status', '=', 'unavailable')]}"/>
<button name="action_cancel_all_jobs" type="object" string="Cancel all running jobs"/>
<button name="action_cancel_all_jobs" type="object" string="Cancel all running jobs" confirm="Are you sure to want to cancel all jobs of this printer?"/>
</header>
<div class="oe_title">
<h1>
<label for="name"/>
<field name="name"/>
</h1>
</div>
<group>
<field name="system_name"/>
</group>
<group col="3" colspan="4">
<group col="4" colspan="4">
<field name="default"/>
<button name="set_default" string="Set Default" type="object"/>
<button name="set_default" string="Set Default" type="object" attrs="{'invisible': [('default','=', True)]}"/>
<button name="unset_default" string="Unset Default" type="object" attrs="{'invisible': [('default','=', False)]}"/>
</group>
<group>
<field name="uri"/>

View File

@@ -27,9 +27,9 @@
</record>
<!-- Add a shorcut to "Actions/Report" in the Printing menu -->
<!--menuitem id="printing_report_xml_action_menu"
<menuitem id="printing_report_xml_action_menu"
sequence="30"
parent="printing_menu"
action="base.ir_action_report_xml"/-->
action="base.ir_action_report"/>
</odoo>