Files
odoo_source/addons/product/wizard/product_label_layout.py
T
thcl-odoo 11e7954d23 [FIX] product: close 'Labels Printing' wizard after download
Current behavior :
When the download is finished, the wizard stay open

Expected behavior :
Wizard should automatically close after downloading

Reason :
The key `close_on_report_download` wasn't defined during new wizard implementation ( commit d9f45ba694 )

OPW-2710611

closes odoo/odoo#82472

X-original-commit: e50a60573e1f9ad201d4db8607d9ff121cd476c2
Related: odoo/enterprise#23355
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
Signed-off-by: Claude Thibault (thcl) <thcl@odoo.com>
2022-01-11 11:20:59 +00:00

73 lines
2.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import _, api, fields, models
from odoo.exceptions import UserError
class ProductLabelLayout(models.TransientModel):
_name = 'product.label.layout'
_description = 'Choose the sheet layout to print the labels'
print_format = fields.Selection([
('dymo', 'Dymo'),
('2x7xprice', '2 x 7 with price'),
('4x7xprice', '4 x 7 with price'),
('4x12', '4 x 12'),
('4x12xprice', '4 x 12 with price')], string="Format", default='2x7xprice', required=True)
custom_quantity = fields.Integer('Quantity', default=1, required=True)
product_ids = fields.Many2many('product.product')
product_tmpl_ids = fields.Many2many('product.template')
extra_html = fields.Html('Extra Content', default='')
rows = fields.Integer(compute='_compute_dimensions')
columns = fields.Integer(compute='_compute_dimensions')
@api.depends('print_format')
def _compute_dimensions(self):
for wizard in self:
if 'x' in wizard.print_format:
columns, rows = wizard.print_format.split('x')[:2]
wizard.columns = int(columns)
wizard.rows = int(rows)
else:
wizard.columns, wizard.rows = 1, 1
def _prepare_report_data(self):
if self.custom_quantity <= 0:
raise UserError(_('You need to set a positive quantity.'))
# Get layout grid
if self.print_format == 'dymo':
xml_id = 'product.report_product_template_label_dymo'
elif 'x' in self.print_format:
xml_id = 'product.report_product_template_label'
else:
xml_id = ''
active_model = ''
if self.product_tmpl_ids:
products = self.product_tmpl_ids.ids
active_model = 'product.template'
elif self.product_ids:
products = self.product_ids.ids
active_model = 'product.product'
# Build data to pass to the report
data = {
'active_model': active_model,
'quantity_by_product': {p: self.custom_quantity for p in products},
'layout_wizard': self.id,
'price_included': 'xprice' in self.print_format,
}
return xml_id, data
def process(self):
self.ensure_one()
xml_id, data = self._prepare_report_data()
if not xml_id:
raise UserError(_('Unable to find report template for %s format', self.print_format))
report_action = self.env.ref(xml_id).report_action(None, data=data)
report_action.update({'close_on_report_download': True})
return report_action