Skip to content

Commit

Permalink
[11.0][ADD] Batch report printing
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhavesh Odedra committed Apr 13, 2020
1 parent cf349bd commit 9d2c669
Show file tree
Hide file tree
Showing 15 changed files with 817 additions and 0 deletions.
132 changes: 132 additions & 0 deletions report_batch/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
=====================
Batch Report Printing
=====================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/11.0/report_batch
:alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-11-0/reporting-engine-11-0-report_batch
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/143/11.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module will allow to to print multiple QWeb reports in a single batch.
For example, picking, packing, reports needs to be printed together
in a single batch.

**Table of contents**

.. contents::
:local:

Configuration
=============

We can configure this module in following two ways:

1st Way
=======

* Create a Report or edit existing report from Settings > Users & Companies >
Batch Reports
* Add sequence number and select parent report or design your own batch report.
* Select subreport to add reports and save it.

2st Way
=======

* Active developer mode. Go to Settings > Technical > Actions > Reports.
* Create or edit report and select related model.
* Jump on "Batch report" tab and add subreport one by one.
* Drag up and down and arrange a sequence of report. Save it.

Usage
=====

If we configure it like following values:

* Name = Picking Batch Report
* Model = Transfer
* Template Name = my.picking_batch_report
* Add subreport = Delivery Slip and Picking Operations
* Save it.

To get results:

* Go to Inventory > Operations > Transfers
* Open one record or select multi records.
* Click on "Print" option near by "Action".
* Print "Picking Batch Report"
* We will get delivery slip and picking operations report together.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_batch%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Open Source Integrators

Contributors
~~~~~~~~~~~~

* Bhavesh Odedra <bodedra@opensourceintegrators.com>
* Balaji Kannan <bkannan@opensourceintegrators.com>
* Daniel Reis <dreis@opensourceintegrators.com>

Other credits
~~~~~~~~~~~~~

The development of this module has been financially supported by:

* Open Source Integrators

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-bodedra| image:: https://github.com/bodedra.png?size=40px
:target: https://github.com/bodedra
:alt: bodedra

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-bodedra|

This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/11.0/report_batch>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
5 changes: 5 additions & 0 deletions report_batch/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2019 IBM Corp.
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import models
22 changes: 22 additions & 0 deletions report_batch/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright (C) 2019 IBM Corp.
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
'name': 'Batch Report Printing',
'summary': 'Ability to print multiple QWeb reports in a single batch.',
'version': '11.0.1.0.0',
'license': 'AGPL-3',
'author': 'Open Source Integrators, Odoo Community Association (OCA)',
'category': 'Reporting',
'website': 'http://www.opensourceintegrators.com',
'depends': [
'stock',
],
'data': [
'security/ir.model.access.csv',
'views/ir_action_report_view.xml',
],
'installable': True,
'maintainers': ['bodedra'],
}
5 changes: 5 additions & 0 deletions report_batch/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Copyright (C) 2019 IBM Corp.
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import ir_action_report
103 changes: 103 additions & 0 deletions report_batch/models/ir_action_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Copyright (C) 2019 IBM Corp.
# Copyright (C) 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
import random


class IrActionsReportSubreport(models.Model):
_name = 'ir.actions.report.subreport'
_description = 'Report Subreport'
_order = 'sequence'

parent_report_id = fields.Many2one('ir.actions.report', ondelete='cascade')
sequence = fields.Integer(default=10)
model = fields.Char(related='parent_report_id.model')
subreport_id = fields.Many2one(
'ir.actions.report', string='Subreport', required=True)


class IrActionsReport(models.Model):
_inherit = 'ir.actions.report'

subreport_ids = fields.One2many(
'ir.actions.report.subreport', 'parent_report_id')
model_id = fields.Many2one('ir.model', string='Model')

@api.onchange('model_id')
def onchange_model_id(self):
if self.model_id:
self.model = self.model_id.model

def generate_top_part(self):
return """<?xml version="1.0"?>\n\t<t t-name="%s">\n\t
""" % self.report_name

def generate_bottom_part(self):
return """\n
\t\t</t>\n\t\t"""

def generate_custom_content(self, report_name):
return """\n
\t<t t-call="%s"/>""" % report_name

def _generate_batch_qweb_report(self, update_batch_qweb=False):
report_name = self.report_name
if '.' in report_name:
module = self.report_name.split('.')[0]
report_name = self.report_name.split('.')[1]
else:
# Generate random number to avoid IntegrityError
module = random.randint(1, 1000000)
self.report_name = "%s.%s" % (module, report_name)
if self.subreport_ids:
if update_batch_qweb:
report_name = self.report_name.split('.')[1]
# Delete old Qweb batch report
model_data = self.env['ir.model.data'].search(
[('res_id', '=', self.id)])
model_data.unlink()
ui_view = self.env['ir.ui.view'].search(
[('name', '=', report_name)])
ui_view.unlink()
template_header = self.generate_top_part()
template_footer = self.generate_bottom_part()
template_content = ''

for subreport in self.subreport_ids:
template_content += self.generate_custom_content(
subreport.subreport_id.report_name
)
data = "%s%s%s" % (
template_header, template_content, template_footer)
ui_view = self.env['ir.ui.view'].create(
{'name': report_name,
'type': 'qweb',
'model': self.model,
'mode': 'primary',
'arch_base': data})
self.env['ir.model.data'].create(
{'module': module,
'name': report_name,
'res_id': ui_view.id,
'model': 'ir.ui.view'})
# Register batch report option
if not self.binding_model_id:
self.create_action()
return True

@api.model
def create(self, vals):
res = super(IrActionsReport, self).create(vals)
for report in res:
report._generate_batch_qweb_report()
return res

@api.multi
def write(self, vals):
res = super(IrActionsReport, self).write(vals)
if 'subreport_ids' in vals or 'model' in vals:
for report in self:
report._generate_batch_qweb_report(update_batch_qweb=True)
return res
17 changes: 17 additions & 0 deletions report_batch/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
We can configure this module in following two ways:

1st Way
=======

* Create a Report or edit existing report from Settings > Users & Companies >
Batch Reports
* Add sequence number and select parent report or design your own batch report.
* Select subreport to add reports and save it.

2st Way
=======

* Active developer mode. Go to Settings > Technical > Actions > Reports.
* Create or edit report and select related model.
* Jump on "Batch report" tab and add subreport one by one.
* Drag up and down and arrange a sequence of report. Save it.
3 changes: 3 additions & 0 deletions report_batch/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Bhavesh Odedra <bodedra@opensourceintegrators.com>
* Balaji Kannan <bkannan@opensourceintegrators.com>
* Daniel Reis <dreis@opensourceintegrators.com>
3 changes: 3 additions & 0 deletions report_batch/readme/CREDITS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

* Open Source Integrators
3 changes: 3 additions & 0 deletions report_batch/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module will allow to to print multiple QWeb reports in a single batch.
For example, picking, packing, reports needs to be printed together
in a single batch.
Empty file added report_batch/readme/ROADMAP.rst
Empty file.
15 changes: 15 additions & 0 deletions report_batch/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
If we configure it like following values:

* Name = Picking Batch Report
* Model = Transfer
* Template Name = my.picking_batch_report
* Add subreport = Delivery Slip and Picking Operations
* Save it.

To get results:

* Go to Inventory > Operations > Transfers
* Open one record or select multi records.
* Click on "Print" option near by "Action".
* Print "Picking Batch Report"
* We will get delivery slip and picking operations report together.
3 changes: 3 additions & 0 deletions report_batch/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_ir_actions_subreport_all,ir_actions_report_subreport,model_ir_actions_report_subreport,,1,0,0,0
access_ir_actions_subreport_group_system,ir_actions_report_subreport_group_system,model_ir_actions_report_subreport,base.group_system,1,1,1,1
Binary file added report_batch/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9d2c669

Please sign in to comment.