Skip to content

Commit

Permalink
Merge 70b4d74 into 3395116
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Jan 25, 2017
2 parents 3395116 + 70b4d74 commit f53d3c9
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 0 deletions.
74 changes: 74 additions & 0 deletions mrp_bom_structure_xlsx/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

===================================
Export BOM Structure to Excel .XLSX
===================================

This module extends the functionality of the MRP capabilities of Odoo,
and to allow you to export the BOM structure to MS Excel .XLSX format.

Installation
============

No additional installation instructions are required.

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

This module does not require any additional configuration.

Usage
=====

To use this module, you need to:

Go to the Bill of Materials form or list views, press 'More > Export BOM
Structure to Excel .XLSX'.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/131/9.0

.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "9.0" for example
Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

Contributors
------------

* Jordi Ballester <jordi.ballester@eficent.com>
* Miquel Raich <miquel.raich@eficent.com>
* Lois Rilo Antelo <lois.rilo@eficent.com>
* Aaron Henriquez <ahenriquez@eficent.com>

Maintainer
----------

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

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
5 changes: 5 additions & 0 deletions mrp_bom_structure_xlsx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import report
20 changes: 20 additions & 0 deletions mrp_bom_structure_xlsx/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
'name': "Export BOM Structure to Excel .XLSX",
'version': '9.0.1.0.0',
'category': 'Manufacturing',
'author': "Eficent, Odoo Community Association (OCA)",
'website': 'https://github.com/OCA/manufacture-reporting',
'license': 'AGPL-3',
"depends": ['report_xlsx', 'mrp'],
"data": [
'report/bom_structure_xlsx.xml',
],
'test': [],
"demo": [],
"installable": True
}
5 changes: 5 additions & 0 deletions mrp_bom_structure_xlsx/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import bom_structure_xlsx
84 changes: 84 additions & 0 deletions mrp_bom_structure_xlsx/report/bom_structure_xlsx.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# (http://www.eficent.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import logging

from openerp.addons.mrp.report.bom_structure \
import bom_structure

from openerp.tools.translate import _

_logger = logging.getLogger(__name__)

try:
from openerp.addons.report_xlsx.report.report_xlsx import ReportXlsx
except ImportError:
_logger.debug("report_xlsx not installed, Excel export non functional")

class ReportXlsx(object):
def __init__(self, *args, **kwargs):
pass


class BomStructureXlsx(ReportXlsx):

def print_bom_children(self, ch, sheet, row, level):
i, j = row, level
j += 1
sheet.write(i, 1, '> '*j)
sheet.write(i, 2, ch.product_id.default_code or '')
sheet.write(i, 3, '[' + ch.product_id.default_code +
'] ' + ch.product_id.name or '')
sheet.write(i, 4, ch.product_qty)
sheet.write(i, 5, ch.product_uom.name or '')
sheet.write(i, 6, ch.bom_id.code or '')
i += 1
for child in ch.child_line_ids:
i = self.print_bom_children(child, sheet, i, j)
j -= 1
return i

def generate_xlsx_report(self, workbook, data, objects):
workbook.set_properties({
'comments': 'Created with Python and XlsxWriter from Odoo 9.0'})
sheet = workbook.add_worksheet(_('BOM Structure'))
sheet.set_landscape()
sheet.fit_to_pages(1, 0)
sheet.set_zoom(80)
sheet.set_column(0, 0, 40)
sheet.set_column(1, 2, 20)
sheet.set_column(3, 3, 40)
sheet.set_column(4, 6, 20)
bold = workbook.add_format({'bold': True})
title_style = workbook.add_format({'bold': True,
'bg_color': '#FFFFCC',
'bottom': 1})
sheet_title = [_('BOM Name'),
_('Level'),
_('Product Reference'),
_('Product Name'),
_('Quantity'),
_('Unit of Measure'),
_('Reference')
]
sheet.set_row(0, None, None, {'collapsed': 1})
sheet.write_row(1, 0, sheet_title, title_style)
sheet.freeze_panes(2, 0)
i = 2
for o in objects:
sheet.write(i, 0, o.product_tmpl_id.name or '', bold)
sheet.write(i, 1, '', bold)
sheet.write(i, 2, o.product_id.default_code or '', bold)
sheet.write(i, 3, o.product_id.name or '', bold)
sheet.write(i, 4, o.product_qty, bold)
sheet.write(i, 5, o.product_uom.name or '', bold)
sheet.write(i, 6, o.code or '', bold)
i += 1
j = 0
for ch in o.bom_line_ids:
i = self.print_bom_children(ch, sheet, i, j)


BomStructureXlsx('report.bom.structure.xlsx', 'mrp.bom', parser=bom_structure)
24 changes: 24 additions & 0 deletions mrp_bom_structure_xlsx/report/bom_structure_xlsx.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<openerp>
<data>

<record id="action_bom_structure_xlsx" model="ir.actions.report.xml">
<field name="name">Export BOM Structure to Excel .XLSX</field>
<field name="model">mrp.bom</field>
<field name="type">ir.actions.report.xml</field>
<field name="report_name">bom.structure.xlsx</field>
<field name="report_type">xlsx</field>
<field name="auto" eval="False"/>
</record>

<record model="ir.values" id="action_bom_structure_xlsx_values">
<field name="name">Export BOM Structure to Excel .XLSX</field>
<field name="key2">client_action_multi</field>
<field name="value" eval="'ir.actions.report.xml,' +str(ref('action_bom_structure_xlsx'))" />
<field name="model">mrp.bom</field>
</record>

</data>
</openerp>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions mrp_bom_structure_xlsx/static/description/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan">Export BOM Structure to Excel .XLSX</h2>
<p>
This module extends the functionality of the MRP capabilities of Odoo,
and to allow you to export the BOM structure to MS Excel .XLSX format.
</p>
</div>
</div>
</section>

<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan">Installation</h2>
</div>
<div class="oe_span6">
<p class="oe_mt32">No additional installation instructions are required.</p>
</div>
</div>
</section>

<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan">Configuration</h2>
</div>
<div class="oe_span6">
<p class="oe_mt32">This module does not require any additional configuration.</p>
</div>
</div>
</section>

<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan">Usage</h2>
</div>
<div class="oe_span6">
<p class="oe_mt32">
To use this module, you need to:

Go to the Bill of Materials form or list views, press 'More > Export BOM
Structure to Excel .XLSX'.
</p>
</div>
</div>
</section>

<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_span12">
<h2 class="oe_slogan">Known issues / Roadmap</h2>
</div>
<div class="oe_span6">
<p class="oe_mt32">No issues have been identified.</p>
</div>
</div>
</section>

<section class="oe_container oe_dark">
<div class="oe_row">
<div class="oe_span12">
<h2 class="oe_slogan">Credits</h2>
</div>
<div class="oe_span12">
<h3>Contributors</h3>
<ul>
<li>Miquel Raich &lt;<a
href="mailto:miquel.raich@eficent.com">miquel.raich@eficent.com</a>&gt;</li>
</ul>
</div>
<div class="oe_span12">
<h3>Maintainer</h3>
<p>
This module is maintained by the OCA.<br/>
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.<br/>
To contribute to this module, please visit <a href="http://odoo-community.org">http://odoo-community.org</a>.<br/>
<a href="http://odoo-community.org"><img class="oe_picture oe_centered" src="http://odoo-community.org/logo.png"></a>
</p>
</div>
</div>
</section>

0 comments on commit f53d3c9

Please sign in to comment.