Skip to content

Commit

Permalink
Merge PR #70 into 13.0
Browse files Browse the repository at this point in the history
Signed-off-by LoisRForgeFlow
  • Loading branch information
OCA-git-bot committed Jan 16, 2020
2 parents d82190b + 656a19b commit aec6b18
Show file tree
Hide file tree
Showing 16 changed files with 916 additions and 0 deletions.
97 changes: 97 additions & 0 deletions mrp_flattened_bom_xlsx/README.rst
@@ -0,0 +1,97 @@
=============================
Export Flattened BOM to Excel
=============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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%2Fmanufacture--reporting-lightgray.png?logo=github
:target: https://github.com/OCA/manufacture-reporting/tree/13.0/mrp_flattened_bom_xlsx
:alt: OCA/manufacture-reporting
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/manufacture-reporting-13-0/manufacture-reporting-13-0-mrp_flattened_bom_xlsx
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/131/13.0
:alt: Try me on Runbot

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

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

A flattened bill of material removes the intermediate levels in the BOM
and connect the lowest levels directly to the highest level.

A list of the sum of lowest levels will be shown for every
BoM you export using this method.

It also maintains units correctly across all nested BOM's and take units
that have been defined in product Unit of Measure field.

**Table of contents**

.. contents::
:local:

Usage
=====

To use this module, you need to:

#. Go to 'Manufacturing / Products / Bill of Materials'

#. Select a BOM or more BOMS

*(Could be interesting to modify quantities of these BOMs)*

#. Go to 'Print / Export Flattened BOM to Excel'.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture-reporting/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/manufacture-reporting/issues/new?body=module:%20mrp_flattened_bom_xlsx%0Aversion:%2013.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
~~~~~~~

* ForgeFlow

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

* Héctor Villarreal <hector.villarreal@forgeflow.com>
* Lois Rilo <lois.rilo@forgeflow.com>

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.

This module is part of the `OCA/manufacture-reporting <https://github.com/OCA/manufacture-reporting/tree/13.0/mrp_flattened_bom_xlsx>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions mrp_flattened_bom_xlsx/__init__.py
@@ -0,0 +1,2 @@
from . import models
from . import report
15 changes: 15 additions & 0 deletions mrp_flattened_bom_xlsx/__manifest__.py
@@ -0,0 +1,15 @@
# Copyright 2018 ForgeFlow S.L.
# (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Export Flattened BOM to Excel",
"version": "13.0.1.0.0",
"category": "Manufacturing",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/manufacture-reporting",
"license": "AGPL-3",
"depends": ["report_xlsx", "mrp"],
"data": ["report/flattened_bom_xlsx.xml"],
"installable": True,
}
87 changes: 87 additions & 0 deletions mrp_flattened_bom_xlsx/i18n/mrp_flattened_bom_xlsx.pot
@@ -0,0 +1,87 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mrp_flattened_bom_xlsx
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: mrp_flattened_bom_xlsx
#: code:addons/mrp_flattened_bom_xlsx/report/flattened_bom_xlsx.py:48
#, python-format
msgid "BOM Name"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: model:ir.model,name:mrp_flattened_bom_xlsx.model_mrp_bom
msgid "Bill of Material"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: model:ir.model.fields,field_description:mrp_flattened_bom_xlsx.field_report_mrp_flattened_bom_xlsx_flattened_bom_xlsx__display_name
msgid "Display Name"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: model:ir.actions.report,name:mrp_flattened_bom_xlsx.flattened_bom_xlsx
msgid "Export Flattened BOM Structure to Excel"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: code:addons/mrp_flattened_bom_xlsx/report/flattened_bom_xlsx.py:37
#, python-format
msgid "Flattened BOM"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: model:ir.model.fields,field_description:mrp_flattened_bom_xlsx.field_report_mrp_flattened_bom_xlsx_flattened_bom_xlsx__id
msgid "ID"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: model:ir.model.fields,field_description:mrp_flattened_bom_xlsx.field_report_mrp_flattened_bom_xlsx_flattened_bom_xlsx____last_update
msgid "Last Modified on"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: code:addons/mrp_flattened_bom_xlsx/report/flattened_bom_xlsx.py:50
#, python-format
msgid "Product Name"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: code:addons/mrp_flattened_bom_xlsx/report/flattened_bom_xlsx.py:49
#, python-format
msgid "Product Reference"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: code:addons/mrp_flattened_bom_xlsx/report/flattened_bom_xlsx.py:51
#, python-format
msgid "Quantity"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: code:addons/mrp_flattened_bom_xlsx/report/flattened_bom_xlsx.py:53
#, python-format
msgid "Reference"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: code:addons/mrp_flattened_bom_xlsx/report/flattened_bom_xlsx.py:52
#, python-format
msgid "Unit of Measure"
msgstr ""

#. module: mrp_flattened_bom_xlsx
#: model:ir.model,name:mrp_flattened_bom_xlsx.model_report_mrp_flattened_bom_xlsx_flattened_bom_xlsx
msgid "report.mrp_flattened_bom_xlsx.flattened_bom_xlsx"
msgstr ""

1 change: 1 addition & 0 deletions mrp_flattened_bom_xlsx/models/__init__.py
@@ -0,0 +1 @@
from . import mrp_bom
48 changes: 48 additions & 0 deletions mrp_flattened_bom_xlsx/models/mrp_bom.py
@@ -0,0 +1,48 @@
# Copyright 2018 ForgeFlow S.L.
# (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models


class MrpBom(models.Model):
""" Defines bills of material for a product or a product template """

_inherit = "mrp.bom"

def _get_flattened_totals(self, factor=1, totals=None):
"""Calculate the **unitary** product requirements of flattened BOM.
*Unit* means that the requirements are computed for one unit of the
default UoM of the product.
:returns: dict: keys are components and values are aggregated quantity
in the product default UoM.
"""
self.ensure_one()
if totals is None:
totals = {}
factor /= self.product_uom_id._compute_quantity(
self.product_qty, self.product_tmpl_id.uom_id, round=False
)
for line in self.bom_line_ids:
sub_bom = self._bom_find(product=line.product_id)
if sub_bom:
new_factor = factor * line.product_uom_id._compute_quantity(
line.product_qty, line.product_id.uom_id, round=False
)
sub_bom._get_flattened_totals(new_factor, totals)
else:
if totals.get(line.product_id):
totals[line.product_id] += (
factor
* line.product_uom_id._compute_quantity(
line.product_qty, line.product_id.uom_id, round=False
)
)
else:
totals[line.product_id] = (
factor
* line.product_uom_id._compute_quantity(
line.product_qty, line.product_id.uom_id, round=False
)
)
return totals
2 changes: 2 additions & 0 deletions mrp_flattened_bom_xlsx/readme/CONTRIBUTORS.rst
@@ -0,0 +1,2 @@
* Héctor Villarreal <hector.villarreal@forgeflow.com>
* Lois Rilo <lois.rilo@forgeflow.com>
11 changes: 11 additions & 0 deletions mrp_flattened_bom_xlsx/readme/DESCRIPTION.rst
@@ -0,0 +1,11 @@
This module extends the functionality of the MRP capabilities of Odoo,
and allows you to export the flattened BOM to MS Excel .XLSX format.

A flattened bill of material removes the intermediate levels in the BOM
and connect the lowest levels directly to the highest level.

A list of the sum of lowest levels will be shown for every
BoM you export using this method.

It also maintains units correctly across all nested BOM's and take units
that have been defined in product Unit of Measure field.
9 changes: 9 additions & 0 deletions mrp_flattened_bom_xlsx/readme/USAGE.rst
@@ -0,0 +1,9 @@
To use this module, you need to:

#. Go to 'Manufacturing / Products / Bill of Materials'

#. Select a BOM or more BOMS

*(Could be interesting to modify quantities of these BOMs)*

#. Go to 'Print / Export Flattened BOM to Excel'.
2 changes: 2 additions & 0 deletions mrp_flattened_bom_xlsx/report/__init__.py
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import flattened_bom_xlsx
69 changes: 69 additions & 0 deletions mrp_flattened_bom_xlsx/report/flattened_bom_xlsx.py
@@ -0,0 +1,69 @@
# Copyright 2018 ForgeFlow S.L.
# (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

import logging

from odoo import models
from odoo.tools.translate import _

_logger = logging.getLogger(__name__)


class FlattenedBomXlsx(models.AbstractModel):
_name = "report.mrp_flattened_bom_xlsx.flattened_bom_xlsx"
_inherit = "report.report_xlsx.abstract"

def print_flattened_bom_lines(self, bom, requirements, sheet, row):
i = row
sheet.write(i, 0, bom.product_tmpl_id.name or "")
sheet.write(i, 1, bom.code or "")
sheet.write(i, 2, bom.display_name or "")
sheet.write(i, 3, bom.product_qty)
sheet.write(i, 4, bom.product_uom_id.name or "")
sheet.write(i, 5, bom.code or "")
i += 1
for product, total_qty in requirements.items():
sheet.write(i, 1, product.default_code or "")
sheet.write(i, 2, product.display_name or "")
sheet.write(i, 3, total_qty or 0.0)
sheet.write(i, 4, product.uom_id.name or "")
sheet.write(i, 5, product.code or "")
i += 1
return i

def generate_xlsx_report(self, workbook, data, objects):
workbook.set_properties(
{"comments": "Created with Python and XlsxWriter from Odoo 11.0"}
)
sheet = workbook.add_worksheet(_("Flattened BOM"))
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)
title_style = workbook.add_format(
{"bold": True, "bg_color": "#FFFFCC", "bottom": 1}
)
sheet_title = [
_("BOM Name"),
_("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:
# We need to calculate the totals for the BoM qty and UoM:
starting_factor = o.product_uom_id._compute_quantity(
o.product_qty, o.product_tmpl_id.uom_id, round=False
)
totals = o._get_flattened_totals(factor=starting_factor)
i = self.print_flattened_bom_lines(o, totals, sheet, i)
16 changes: 16 additions & 0 deletions mrp_flattened_bom_xlsx/report/flattened_bom_xlsx.xml
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 ForgeFlow S.L.
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<report
id="flattened_bom_xlsx"
model="mrp.bom"
string="Export Flattened BOM Structure to Excel"
report_type="xlsx"
name="mrp_flattened_bom_xlsx.flattened_bom_xlsx"
file="mrp_bom"
attachment_use="False"
/>

</odoo>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aec6b18

Please sign in to comment.