Merge PR #650 into 12.0

Signed-off-by dreispt
This commit is contained in:
OCA-git-bot
2021-10-23 13:36:00 +00:00
18 changed files with 1529 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
============================
Bill of Materials comparison
============================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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-lightgray.png?logo=github
:target: https://github.com/OCA/manufacture/tree/12.0/mrp_bom_comparison
:alt: OCA/manufacture
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/manufacture-12-0/manufacture-12-0-mrp_bom_comparison
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/129/12.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
This module allows you to compare two Bill of Materials to view the differences.
**Table of contents**
.. contents::
:local:
Usage
=====
First, create two (or more) Bill of Materials on the same product.
Then, open the first Bill of Materials, and launch the wizard with `Action / Compare Bill of Materials`.
In the `BoM v2` field, select a BoM to compare against the current one,
and click on `Compare`. The result of the comparaison is returned as
a PDF report with three sections:
- products updated
- products added
- products removed
Development
===========
If you want to compare two Bill of Materials not linked to the same product,
you can override the `_domain_bom_id` method from the
`wizard.mrp.bom.comparison` wizard.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/manufacture/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/issues/new?body=module:%20mrp_bom_comparison%0Aversion:%2012.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
~~~~~~~
* ABF OSIELL
Contributors
~~~~~~~~~~~~
* Sébastien Alix <sebastien.alix@osiell.com> (https://osiell.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 <https://github.com/OCA/manufacture/tree/12.0/mrp_bom_comparison>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import wizards

View File

@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2018 ABF OSIELL <http://osiell.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Bill of Materials comparison",
"summary": "Compare two Bill of Materials to view the differences",
"version": "12.0.1.0.0",
"category": "Manufacturing",
"website": "https://github.com/OCA/manufacture",
"author": "ABF OSIELL, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"mrp",
],
"data": [
"wizards/mrp_bom_comparison.xml",
"reports/mrp_bom_comparison.xml",
"views/reports.xml",
],
}

View File

@@ -0,0 +1,210 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mrp_bom_comparison
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2018-12-13 09:58+0000\n"
"Last-Translator: Maria Sparenberg <maria.sparenberg@gmx.net>\n"
"Language-Team: none\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 3.3\n"
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "<br/>Products added to BoM v2"
msgstr "<br/>zur Stückliste V2 hinzugefügte Produkte"
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "<br/>Products removed from BoM v2"
msgstr "<br/>aus Stückliste V2 entfernte Produkte"
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "<br/>Products updated"
msgstr "<br/>Produkte aktualisiert"
#. module: mrp_bom_comparison
#: selection:wizard.mrp.bom.comparison.line,state:0
msgid "Added"
msgstr "Hinzugefügt"
#. module: mrp_bom_comparison
#: model:ir.actions.report.xml,name:mrp_bom_comparison.action_report_mrp_bom_comparison
msgid "BoM Differences"
msgstr "Stücklisten-Unterschiede"
#. module: mrp_bom_comparison
#: model:ir.model,name:mrp_bom_comparison.model_wizard_mrp_bom_comparison_line
msgid "BoM line difference"
msgstr "Unterschiede in Stücklistenpositionen"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_bom1_id
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "BoM v1"
msgstr "Stückliste V1"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_bom2_id
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "BoM v2"
msgstr "Stückliste V2"
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.view_wizard_bom_comparison_form
msgid "Cancel"
msgstr "Abbrechen"
#. module: mrp_bom_comparison
#: selection:wizard.mrp.bom.comparison.line,state:0
msgid "Changed"
msgstr "Geändert"
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.view_wizard_bom_comparison_form
msgid "Compare"
msgstr "Vergleichen"
#. module: mrp_bom_comparison
#: model:ir.actions.act_window,name:mrp_bom_comparison.act_wizard_mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.view_wizard_bom_comparison_form
msgid "Compare Bill of Materials"
msgstr "Stückliste vergleichen"
#. module: mrp_bom_comparison
#: model:ir.model,name:mrp_bom_comparison.model_wizard_mrp_bom_comparison
msgid "Compare two BoM"
msgstr "zwei Stücklisten vergleichen"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_create_uid
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_create_uid
msgid "Created by"
msgstr "Erstellt von"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_create_date
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_create_date
msgid "Created on"
msgstr "Erstellt am"
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "Designation"
msgstr "Bezeichnung"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_ids
msgid "Differences"
msgstr "Unterschiede"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_display_name
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_display_name
msgid "Display Name"
msgstr "Anzeigename"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_id
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_id
msgid "ID"
msgstr "ID"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison___last_update
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line___last_update
msgid "Last Modified on"
msgstr "Zuletzt geändert am"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_write_uid
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_write_uid
msgid "Last Updated by"
msgstr "Zuletzt aktualisiert von"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_write_date
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_write_date
msgid "Last Updated on"
msgstr "Zuletzt aktualisiert am"
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "NO DIFFERENCE DETECTED"
msgstr "KEINE UNTERSCHIEDE ERKANNT"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_product_id
msgid "Product"
msgstr "Produkt"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_added_ids
msgid "Products added"
msgstr "Produkte wurden hinzugefügt"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_removed_ids
msgid "Products removed"
msgstr "Produkte wurden entfernt"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_changed_ids
msgid "Products updated"
msgstr "Produkte wurden aktualisiert"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_diff_qty
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "Qty gap"
msgstr "Mengenunterschied"
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "Ref."
msgstr "Ref."
#. module: mrp_bom_comparison
#: selection:wizard.mrp.bom.comparison.line,state:0
msgid "Removed"
msgstr "Entfernt"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_state
msgid "State"
msgstr "Status"
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "TOTAL"
msgstr "GESAMT"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_total_qty
msgid "Total qty"
msgstr "Gesamtmenge"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_wiz_id
msgid "Wizard"
msgstr "Assistent"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_bom1_qty
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "v1-Qty"
msgstr "V1-Menge"
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_bom2_qty
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "v2-Qty"
msgstr "V2-Menge"

View File

@@ -0,0 +1,208 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mrp_bom_comparison
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 10.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_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "<br/>Products added to BoM v2"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "<br/>Products removed from BoM v2"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "<br/>Products updated"
msgstr ""
#. module: mrp_bom_comparison
#: selection:wizard.mrp.bom.comparison.line,state:0
msgid "Added"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.actions.report.xml,name:mrp_bom_comparison.action_report_mrp_bom_comparison
msgid "BoM Differences"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model,name:mrp_bom_comparison.model_wizard_mrp_bom_comparison_line
msgid "BoM line difference"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_bom1_id
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "BoM v1"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_bom2_id
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "BoM v2"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.view_wizard_bom_comparison_form
msgid "Cancel"
msgstr ""
#. module: mrp_bom_comparison
#: selection:wizard.mrp.bom.comparison.line,state:0
msgid "Changed"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.view_wizard_bom_comparison_form
msgid "Compare"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.actions.act_window,name:mrp_bom_comparison.act_wizard_mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.view_wizard_bom_comparison_form
msgid "Compare Bill of Materials"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model,name:mrp_bom_comparison.model_wizard_mrp_bom_comparison
msgid "Compare two BoM"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_create_uid
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_create_uid
msgid "Created by"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_create_date
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_create_date
msgid "Created on"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "Designation"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_ids
msgid "Differences"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_display_name
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_display_name
msgid "Display Name"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_id
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_id
msgid "ID"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison___last_update
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line___last_update
msgid "Last Modified on"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_write_uid
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_write_uid
msgid "Last Updated by"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_write_date
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_write_date
msgid "Last Updated on"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "NO DIFFERENCE DETECTED"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_product_id
msgid "Product"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_added_ids
msgid "Products added"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_removed_ids
msgid "Products removed"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_changed_ids
msgid "Products updated"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_diff_qty
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "Qty gap"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "Ref."
msgstr ""
#. module: mrp_bom_comparison
#: selection:wizard.mrp.bom.comparison.line,state:0
msgid "Removed"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_state
msgid "State"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "TOTAL"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_total_qty
msgid "Total qty"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_wiz_id
msgid "Wizard"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_bom1_qty
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "v1-Qty"
msgstr ""
#. module: mrp_bom_comparison
#: model:ir.model.fields,field_description:mrp_bom_comparison.field_wizard_mrp_bom_comparison_line_bom2_qty
#: model:ir.ui.view,arch_db:mrp_bom_comparison.report_mrp_bom_comparison
msgid "v2-Qty"
msgstr ""

View File

@@ -0,0 +1,2 @@
* Sébastien Alix <sebastien.alix@osiell.com> (https://osiell.com)
* Adrià Gil Sorribes <adria.gil@forgeflow.com> (https://www.forgeflow.com)

View File

@@ -0,0 +1 @@
This module allows you to compare two Bill of Materials to view the differences.

View File

@@ -0,0 +1,3 @@
If you want to compare two Bill of Materials not linked to the same product,
you can override the `_domain_bom_id` method from the
`wizard.mrp.bom.comparison` wizard.

View File

@@ -0,0 +1,9 @@
First, create two (or more) Bill of Materials on the same product.
Then, open the first Bill of Materials, and launch the wizard with `Action / Compare Bill of Materials`.
In the `BoM v2` field, select a BoM to compare against the current one,
and click on `Compare`. The result of the comparaison is returned as
a PDF report with three sections:
- products updated
- products added
- products removed

View File

@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 ABF OSIELL <http://osiell.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<template id="report_mrp_bom_comparison">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="web.internal_layout">
<div class="page">
<table class="table table-condensed">
<thead>
<tr>
<th>BoM v1</th>
<th>BoM v2</th>
</tr>
</thead>
<tbody>
<tr>
<td><span t-field="o.bom1_id"/></td>
<td><span t-field="o.bom2_id"/></td>
</tr>
</tbody>
</table>
<br/>
<table class="table table-condensed">
<thead>
<tr class="border-black">
<th>Ref.</th>
<th>Designation</th>
<th>v1-Qty</th>
<th>v2-Qty</th>
<th>Qty gap</th>
</tr>
</thead>
<tbody t-if="not o.line_changed_ids and not o.line_added_ids and not o.line_removed_ids">
<tr>
<td colspan="5" class="text-center">NO DIFFERENCE DETECTED</td>
</tr>
</tbody>
<tbody t-if="o.line_changed_ids">
<tr>
<th colspan="5"><br/>Products updated</th>
</tr>
<t t-foreach="o.line_changed_ids" t-as="line">
<tr>
<td class="text-warning"><span t-field="line.product_id.default_code"/></td>
<td><span t-field="line.product_id.name"/></td>
<td class="text-right"><span t-field="line.bom1_qty"/></td>
<td class="text-right"><span t-field="line.bom2_qty"/></td>
<td class="text-right text-warning"><span t-field="line.diff_qty"/></td>
</tr>
</t>
</tbody>
<tbody t-if="o.line_added_ids">
<tr>
<th colspan="5"><br/>Products added to BoM v2</th>
</tr>
<t t-foreach="o.line_added_ids" t-as="line">
<tr>
<td class="text-success"><span t-field="line.product_id.default_code"/></td>
<td><span t-field="line.product_id.name"/></td>
<td class="text-right"><span t-field="line.bom1_qty"/></td>
<td class="text-right"><span t-field="line.bom2_qty"/></td>
<td class="text-right text-success"><span t-field="line.diff_qty"/></td>
</tr>
</t>
</tbody>
<tbody t-if="o.line_removed_ids">
<tr>
<th colspan="5"><br/>Products removed from BoM v2</th>
</tr>
<t t-foreach="o.line_removed_ids" t-as="line">
<tr>
<td class="text-danger"><span t-field="line.product_id.default_code"/></td>
<td><span t-field="line.product_id.name"/></td>
<td class="text-right"><span t-field="line.bom1_qty"/></td>
<td class="text-right"><span t-field="line.bom2_qty"/></td>
<td class="text-right text-danger"><span t-field="line.diff_qty"/></td>
</tr>
</t>
</tbody>
<tfoot t-if="o.line_changed_ids or o.line_added_ids or o.line_removed_ids">
<tr class="no_border">
<th class="text-right" colspan="4">TOTAL</th>
<td class="text-right"><span t-field="o.total_qty"/></td>
</tr>
</tfoot>
</table>
</div>
</t>
</t>
</t>
</template>
</odoo>

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

View File

@@ -0,0 +1,440 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<title>Bill of Materials comparison</title>
<style type="text/css">
/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/
/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
border: 0 }
table.borderless td, table.borderless th {
/* Override padding for "table.docutils td" with "! important".
The right padding separates the table cells. */
padding: 0 0.5em 0 0 ! important }
.first {
/* Override more specific margin styles with "! important". */
margin-top: 0 ! important }
.last, .with-subtitle {
margin-bottom: 0 ! important }
.hidden {
display: none }
.subscript {
vertical-align: sub;
font-size: smaller }
.superscript {
vertical-align: super;
font-size: smaller }
a.toc-backref {
text-decoration: none ;
color: black }
blockquote.epigraph {
margin: 2em 5em ; }
dl.docutils dd {
margin-bottom: 0.5em }
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
overflow: hidden;
}
/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
font-weight: bold }
*/
div.abstract {
margin: 2em 5em }
div.abstract p.topic-title {
font-weight: bold ;
text-align: center }
div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
margin: 2em ;
border: medium outset ;
padding: 1em }
div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
font-weight: bold ;
font-family: sans-serif }
div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title, .code .error {
color: red ;
font-weight: bold ;
font-family: sans-serif }
/* Uncomment (and remove this text!) to get reduced vertical space in
compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
margin-bottom: 0.5em }
div.compound .compound-last, div.compound .compound-middle {
margin-top: 0.5em }
*/
div.dedication {
margin: 2em 5em ;
text-align: center ;
font-style: italic }
div.dedication p.topic-title {
font-weight: bold ;
font-style: normal }
div.figure {
margin-left: 2em ;
margin-right: 2em }
div.footer, div.header {
clear: both;
font-size: smaller }
div.line-block {
display: block ;
margin-top: 1em ;
margin-bottom: 1em }
div.line-block div.line-block {
margin-top: 0 ;
margin-bottom: 0 ;
margin-left: 1.5em }
div.sidebar {
margin: 0 0 0.5em 1em ;
border: medium outset ;
padding: 1em ;
background-color: #ffffee ;
width: 40% ;
float: right ;
clear: right }
div.sidebar p.rubric {
font-family: sans-serif ;
font-size: medium }
div.system-messages {
margin: 5em }
div.system-messages h1 {
color: red }
div.system-message {
border: medium outset ;
padding: 1em }
div.system-message p.system-message-title {
color: red ;
font-weight: bold }
div.topic {
margin: 2em }
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
margin-top: 0.4em }
h1.title {
text-align: center }
h2.subtitle {
text-align: center }
hr.docutils {
width: 75% }
img.align-left, .figure.align-left, object.align-left, table.align-left {
clear: left ;
float: left ;
margin-right: 1em }
img.align-right, .figure.align-right, object.align-right, table.align-right {
clear: right ;
float: right ;
margin-left: 1em }
img.align-center, .figure.align-center, object.align-center {
display: block;
margin-left: auto;
margin-right: auto;
}
table.align-center {
margin-left: auto;
margin-right: auto;
}
.align-left {
text-align: left }
.align-center {
clear: both ;
text-align: center }
.align-right {
text-align: right }
/* reset inner alignment in figures */
div.align-right {
text-align: inherit }
/* div.align-center * { */
/* text-align: left } */
.align-top {
vertical-align: top }
.align-middle {
vertical-align: middle }
.align-bottom {
vertical-align: bottom }
ol.simple, ul.simple {
margin-bottom: 1em }
ol.arabic {
list-style: decimal }
ol.loweralpha {
list-style: lower-alpha }
ol.upperalpha {
list-style: upper-alpha }
ol.lowerroman {
list-style: lower-roman }
ol.upperroman {
list-style: upper-roman }
p.attribution {
text-align: right ;
margin-left: 50% }
p.caption {
font-style: italic }
p.credits {
font-style: italic ;
font-size: smaller }
p.label {
white-space: nowrap }
p.rubric {
font-weight: bold ;
font-size: larger ;
color: maroon ;
text-align: center }
p.sidebar-title {
font-family: sans-serif ;
font-weight: bold ;
font-size: larger }
p.sidebar-subtitle {
font-family: sans-serif ;
font-weight: bold }
p.topic-title {
font-weight: bold }
pre.address {
margin-bottom: 0 ;
margin-top: 0 ;
font: inherit }
pre.literal-block, pre.doctest-block, pre.math, pre.code {
margin-left: 2em ;
margin-right: 2em }
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
pre.code .literal.string, code .literal.string { color: #0C5404 }
pre.code .name.builtin, code .name.builtin { color: #352B84 }
pre.code .deleted, code .deleted { background-color: #DEB0A1}
pre.code .inserted, code .inserted { background-color: #A3D289}
span.classifier {
font-family: sans-serif ;
font-style: oblique }
span.classifier-delimiter {
font-family: sans-serif ;
font-weight: bold }
span.interpreted {
font-family: sans-serif }
span.option {
white-space: nowrap }
span.pre {
white-space: pre }
span.problematic {
color: red }
span.section-subtitle {
/* font-size relative to parent (h1..h6 element) */
font-size: 80% }
table.citation {
border-left: solid 1px gray;
margin-left: 1px }
table.docinfo {
margin: 2em 4em }
table.docutils {
margin-top: 0.5em ;
margin-bottom: 0.5em }
table.footnote {
border-left: solid 1px black;
margin-left: 1px }
table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
padding-left: 0.5em ;
padding-right: 0.5em ;
vertical-align: top }
table.docutils th.field-name, table.docinfo th.docinfo-name {
font-weight: bold ;
text-align: left ;
white-space: nowrap ;
padding-left: 0 }
/* "booktabs" style (no vertical lines) */
table.docutils.booktabs {
border: 0px;
border-top: 2px solid;
border-bottom: 2px solid;
border-collapse: collapse;
}
table.docutils.booktabs * {
border: 0px;
}
table.docutils.booktabs th {
border-bottom: thin solid;
text-align: left;
}
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
font-size: 100% }
ul.auto-toc {
list-style-type: none }
</style>
</head>
<body>
<div class="document" id="bill-of-materials-comparison">
<h1 class="title">Bill of Materials comparison</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/manufacture/tree/10.0/mrp_bom_comparison"><img alt="OCA/manufacture" src="https://img.shields.io/badge/github-OCA%2Fmanufacture-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/manufacture-10-0/manufacture-10-0-mrp_bom_comparison"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/129/10.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows you to compare two Bill of Materials to view the differences.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
<li><a class="reference internal" href="#development" id="id2">Development</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="usage">
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>First, create two (or more) Bill of Materials on the same product.
Then, open the first Bill of Materials, and launch the wizard with <cite>Action / Compare Bill of Materials</cite>.
In the <cite>BoM v2</cite> field, select a BoM to compare against the current one,
and click on <cite>Compare</cite>. The result of the comparaison is returned as
a PDF report with three sections:</p>
<ul class="simple">
<li>products updated</li>
<li>products added</li>
<li>products removed</li>
</ul>
</div>
<div class="section" id="development">
<h1><a class="toc-backref" href="#id2">Development</a></h1>
<p>If you want to compare two Bill of Materials not linked to the same product,
you can override the <cite>_domain_bom_id</cite> method from the
<cite>wizard.mrp.bom.comparison</cite> wizard.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/manufacture/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/manufacture/issues/new?body=module:%20mrp_bom_comparison%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
<ul class="simple">
<li>ABF OSIELL</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<ul class="simple">
<li>Sébastien Alix &lt;<a class="reference external" href="mailto:sebastien.alix&#64;osiell.com">sebastien.alix&#64;osiell.com</a>&gt; (<a class="reference external" href="https://osiell.com">https://osiell.com</a>)</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/manufacture/tree/10.0/mrp_bom_comparison">OCA/manufacture</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
</div>
</body>
</html>

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2018 ABF OSIELL <http://osiell.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_mrp_bom_comparison

View File

@@ -0,0 +1,141 @@
# -*- coding: utf-8 -*-
# Copyright 2018 ABF OSIELL <http://osiell.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo.addons.mrp.tests.common import TestMrpCommon
class TestMrpBomComparison(TestMrpCommon):
def setUp(self):
super(TestMrpBomComparison, self).setUp()
# bom_3 (product_6) -> bom_2 (product_5) -> bom_1 (product_4)
self.wiz_model = self.env['wizard.mrp.bom.comparison']
self.product_1.default_code = "P1"
self.product_2.default_code = "P2"
self.product_3.default_code = "P3"
self.product_4.default_code = "P4-BOM_1"
self.product_5.default_code = "P5-BOM_2"
self.product_6.default_code = "P6-BOM_3"
# Create a 'new_bom_1' from 'bom_1'
self.new_product_4 = self.product_4.copy(
{'default_code': "P4-NEW_BOM_1"})
self.new_bom_1 = self.bom_1.copy({
'product_id': self.new_product_4.id,
'product_tmpl_id': self.new_product_4.product_tmpl_id.id,
})
# Change a component qty on 'new_bom_1':
# product_2: 2 => 1
self.new_bom_1.bom_line_ids.filtered(
lambda l: l.product_id == self.product_2).product_qty = 1
# Create a 'new_bom_2' from 'bom_2'
self.new_product_5 = self.product_5.copy(
{'default_code': "P5-NEW_BOM_2"})
self.new_bom_2 = self.bom_2.copy({
'product_id': self.new_product_5.id,
'product_tmpl_id': self.new_product_5.product_tmpl_id.id,
})
self.new_bom_2.bom_line_ids.filtered(
lambda l: l.product_id == self.product_4).write(
{'product_id': self.new_product_4.id})
# Change a component qty on 'new_bom_2':
# product_3: 3 => 4
# new_product_4: 2 => 6
self.new_bom_2.bom_line_ids.filtered(
lambda l: l.product_id == self.product_3).product_qty = 4
self.new_bom_2.bom_line_ids.filtered(
lambda l: l.product_id == self.new_product_4).product_qty = 6
# Create a 'new_bom_3' from 'bom_3'
self.new_bom_3 = self.bom_3.copy()
self.new_bom_3.bom_line_ids.filtered(
lambda l: l.product_id == self.product_4).write(
{'product_id': self.new_product_4.id})
self.new_bom_3.bom_line_ids.filtered(
lambda l: l.product_id == self.product_5).write(
{'product_id': self.new_product_5.id})
# Change a component qty on 'new_bom_3':
# product_2: 12 => 10
self.new_bom_3.bom_line_ids.filtered(
lambda l: l.product_id == self.product_2).product_qty = 10
# Make a comparison between the original BoM and the new one
vals = {
'bom1_id': self.bom_3.id,
'bom2_id': self.new_bom_3.id,
}
self.wiz = self.wiz_model.create(vals)
self.wiz.run()
def test_line_changed_ids(self):
self.assertTrue(self.wiz.line_changed_ids)
self.assertEqual(len(self.wiz.line_changed_ids), 3)
changed_products = self.wiz.line_changed_ids.mapped('product_id')
self.assertIn(self.product_1, changed_products)
self.assertIn(self.product_2, changed_products)
self.assertIn(self.product_3, changed_products)
# product_1 qty:
# v1: 8*4/4 + 2*2*4/4 = 12
# v2: 8*4/4 + 2*6*4/4 = 20
# diff = +8
line_product_1 = self.wiz.line_changed_ids.filtered(
lambda l: l.product_id == self.product_1)
self.assertEqual(line_product_1.diff_qty, 8)
# product_2 qty:
# v1: 12 + 8*2/4 + 2*2*2/4 = 18
# v2: 10 + 8*1/4 + 2*6*1/4 = 15
# diff = -3
line_product_2 = self.wiz.line_changed_ids.filtered(
lambda l: l.product_id == self.product_2)
self.assertEqual(line_product_2.diff_qty, -3)
# product_3 qty:
# v1: 2*3 = 6
# v2: 2*4 = 8
# diff = +2
line_product_3 = self.wiz.line_changed_ids.filtered(
lambda l: l.product_id == self.product_3)
self.assertEqual(line_product_3.diff_qty, 2)
def test_line_added_ids(self):
self.assertTrue(self.wiz.line_added_ids)
self.assertEqual(len(self.wiz.line_added_ids), 2)
added_products = self.wiz.line_added_ids.mapped('product_id')
self.assertIn(self.new_product_4, added_products)
self.assertIn(self.new_product_5, added_products)
# new_product4 qty:
# v1: 0
# v2: 8 + 2*6 = 20
# diff = +20
line_new_product_4 = self.wiz.line_added_ids.filtered(
lambda l: l.product_id == self.new_product_4)
self.assertEqual(line_new_product_4.diff_qty, 20)
# new_product5 qty:
# v1: 0
# v2: 2
# diff = +2
line_new_product_5 = self.wiz.line_added_ids.filtered(
lambda l: l.product_id == self.new_product_5)
self.assertEqual(line_new_product_5.diff_qty, 2)
def test_line_removed_ids(self):
self.assertTrue(self.wiz.line_removed_ids)
self.assertEqual(len(self.wiz.line_removed_ids), 2)
removed_products = self.wiz.line_removed_ids.mapped('product_id')
self.assertIn(self.product_4, removed_products)
self.assertIn(self.product_5, removed_products)
# product4 qty:
# v1: 12
# v2: 0
# diff = -12
line_product_4 = self.wiz.line_removed_ids.filtered(
lambda l: l.product_id == self.product_4)
self.assertEqual(line_product_4.diff_qty, -12)
# product5 qty:
# v1: 2
# v2: 0
# diff = -2
line_product_5 = self.wiz.line_removed_ids.filtered(
lambda l: l.product_id == self.product_5)
self.assertEqual(line_product_5.diff_qty, -2)

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 ABF OSIELL <http://osiell.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<report id="action_report_mrp_bom_comparison"
name="mrp_bom_comparison.report_mrp_bom_comparison"
model="wizard.mrp.bom.comparison"
string="BoM Differences"
report_type="qweb-pdf"/>
</odoo>

View File

@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import mrp_bom_comparison

View File

@@ -0,0 +1,247 @@
# -*- coding: utf-8 -*-
# Copyright 2018 ABF OSIELL <http://osiell.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from odoo import api, fields, models
from odoo.addons import decimal_precision as dp
_logger = logging.getLogger(__name__)
class DictDiffer(object):
"""Calculate the difference between two dictionaries as:
(1) items added
(2) items removed
(3) keys same in both but changed values
(4) keys same in both and unchanged values
"""
def __init__(self, current_dict, past_dict):
self.current_dict, self.past_dict = current_dict, past_dict
self.set_current = set(current_dict.keys())
self.set_past = set(past_dict.keys())
self.intersect = self.set_current.intersection(self.set_past)
def added(self):
return self.set_current - self.intersect
def removed(self):
return self.set_past - self.intersect
def changed(self):
return set(o for o in self.intersect
if self.past_dict[o] != self.current_dict[o])
def unchanged(self):
return set(o for o in self.intersect
if self.past_dict[o] == self.current_dict[o])
class WizardMrpBomComparison(models.TransientModel):
_name = 'wizard.mrp.bom.comparison'
_description = "Compare two BoM"
@api.model
def _func_domain_bom_id(self):
return self._domain_bom_id()
@api.model
def _domain_bom_id(self):
"""Returns the domain used to select the BoMs to compare."""
bom_id = self.env.context.get('active_id', False)
bom = self.env['mrp.bom'].browse(bom_id)
return [('product_tmpl_id', '=', bom.product_tmpl_id.id)]
@api.multi
@api.depends('line_ids.diff_qty')
def _compute_total_qty(self):
for wiz in self:
wiz.total_qty = sum([
sum([line.diff_qty for line in wiz.line_changed_ids]),
sum([line.diff_qty for line in wiz.line_added_ids]),
sum([line.diff_qty for line in wiz.line_removed_ids]),
])
bom1_id = fields.Many2one(
'mrp.bom', "BoM v1", required=True,
domain=_func_domain_bom_id)
bom2_id = fields.Many2one(
'mrp.bom', "BoM v2", required=True,
domain=_func_domain_bom_id)
line_ids = fields.One2many(
'wizard.mrp.bom.comparison.line', 'wiz_id', "Differences")
line_changed_ids = fields.One2many(
'wizard.mrp.bom.comparison.line', 'wiz_id', "Products updated",
domain=[('state', '=', 'changed')])
line_added_ids = fields.One2many(
'wizard.mrp.bom.comparison.line', 'wiz_id', "Products added",
domain=[('state', '=', 'added')])
line_removed_ids = fields.One2many(
'wizard.mrp.bom.comparison.line', 'wiz_id', "Products removed",
domain=[('state', '=', 'removed')])
total_qty = fields.Float(
"Total qty",
digits=dp.get_precision('Product Unit of Measure'),
compute='_compute_total_qty')
@api.model
def default_get(self, fields_list):
"""'default_get' method overridden."""
res = super(WizardMrpBomComparison, self).default_get(fields_list)
res['bom1_id'] = self.env.context.get('active_id', False)
return res
@api.model
def _get_bom_line_data(self, root_bom, bom_line, factor=1):
"""Return a dictionary representation of the `bom_line` record.
:return: a dictionary
"""
data = {
'product_id': bom_line.product_id.id,
'product_code': bom_line.product_id.default_code or '-',
'product_name': bom_line.product_id.name or '-',
'bom_qty': (
bom_line.product_qty / float(bom_line.bom_id.product_qty)
* factor),
}
if bom_line.bom_id == root_bom:
data['bom_qty'] = bom_line.product_qty * factor
return data
@api.model
def _merge_bom_line_data(self, bom1_line_data, bom2_line_data):
"""Merge two bom lines (dictionaries with same keys).
:return: a dictionary
"""
new_bom_line_data = bom1_line_data.copy()
new_bom_line_data['bom_qty'] += bom2_line_data['bom_qty']
return new_bom_line_data
@api.model
def _get_all_data(self, root_bom):
"""Get all BoM data composing the BoM identified by `bom_id`.
:return: a dictionary
"""
products = {}
def recurse(start_bom, products, factor=1):
for bom_line in start_bom.bom_line_ids:
if bom_line.product_id.bom_ids:
bom = self._get_bom_from_product(bom_line.product_id)
bom_factor = bom_line.product_qty * factor
recurse(bom, products, factor=bom_factor)
if not bom_line.product_id:
continue
p_id = bom_line.product_id.id
bom_line_data = self._get_bom_line_data(
root_bom, bom_line, factor)
# New product
if p_id not in products:
products[p_id] = bom_line_data
# Merge bom data with the existing one
else:
products[p_id] = self._merge_bom_line_data(
products[p_id], bom_line_data)
return products
recurse(root_bom, products)
return products
def _get_bom_from_product(self, product):
return product.bom_ids[0]
@api.multi
def run(self):
"""Make a comparison between two BoMs.
:return: a report
"""
self.ensure_one()
# Ensure that no line exists if we make 2 comparisons
# from the same wizard
self.line_ids.unlink()
_logger.info(
"BoM comparison between '%s' and '%s'...",
self.bom1_id.product_tmpl_id.default_code,
self.bom2_id.product_tmpl_id.default_code)
comparison_line_model = self.env['wizard.mrp.bom.comparison.line']
# Get all data for each BoM
bom1_data = self._get_all_data(self.bom1_id)
bom2_data = self._get_all_data(self.bom2_id)
# Make the comparison between them
diff = DictDiffer(bom2_data, bom1_data)
# Iterate over data to generate lines to display on the report
for p_id in diff.changed():
v1 = bom1_data[p_id]
v2 = bom2_data[p_id]
vals = {
'wiz_id': self.id,
'product_id': p_id,
'bom1_qty': v1['bom_qty'],
'bom2_qty': v2['bom_qty'],
'diff_qty': v2['bom_qty'] - v1['bom_qty'],
'state': 'changed',
}
_logger.info(
"\tProduct updated: %s (ID=%s) %s -> %s",
v1['product_code'], p_id,
v1['bom_qty'], v2['bom_qty'])
comparison_line_model.create(vals)
for p_id in diff.added():
v2 = bom2_data[p_id]
vals = {
'wiz_id': self.id,
'product_id': p_id,
'bom1_qty': 0.0,
'bom2_qty': v2['bom_qty'],
'diff_qty': v2['bom_qty'],
'state': 'added',
}
_logger.info(
"\tProduct added: %s (ID=%s) -> %s",
v2['product_code'], p_id, vals['diff_qty'])
comparison_line_model.create(vals)
for p_id in diff.removed():
v1 = bom1_data[p_id]
vals = {
'wiz_id': self.id,
'product_id': p_id,
'bom1_qty': v1['bom_qty'],
'bom2_qty': 0.0,
'diff_qty': -v1['bom_qty'],
'state': 'removed',
}
_logger.info(
"\tProduct removed: %s (ID=%s) -> %s",
v1['product_code'], p_id, vals['diff_qty'])
comparison_line_model.create(vals)
_logger.info(
"BoM comparison between '%s' and '%s': printing report...",
self.bom1_id.product_tmpl_id.default_code,
self.bom2_id.product_tmpl_id.default_code)
# Return the report
return self.env.ref(
'mrp_bom_comparison.action_report_mrp_bom_comparison').report_action(self)
class WizardMrpBomComparisonLine(models.TransientModel):
_name = 'wizard.mrp.bom.comparison.line'
_description = "BoM line difference"
wiz_id = fields.Many2one('wizard.mrp.bom.comparison', "Wizard")
product_id = fields.Many2one('product.product', "Product")
bom1_qty = fields.Float(
"v1-Qty", digits=dp.get_precision('Product Unit of Measure'))
bom2_qty = fields.Float(
"v2-Qty", digits=dp.get_precision('Product Unit of Measure'))
diff_qty = fields.Float(
"Qty gap", digits=dp.get_precision('Product Unit of Measure'))
state = fields.Selection(
[('changed', "Changed"),
('added', "Added"),
('removed', "Removed"),
],
"State")

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 ABF OSIELL <http://osiell.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="view_wizard_bom_comparison_form" model="ir.ui.view">
<field name="name">Compare Bill of Materials</field>
<field name="model">wizard.mrp.bom.comparison</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Compare Bill of Materials">
<group col="4">
<field name="bom1_id"/>
<field name="bom2_id"/>
</group>
<footer>
<button name="run" type="object"
string="Compare" class="btn-primary"/>
<button special="cancel"
string="Cancel" class="btn-default"/>
</footer>
</form>
</field>
</record>
<act_window name="Compare Bill of Materials"
res_model="wizard.mrp.bom.comparison"
src_model="mrp.bom"
view_mode="form"
target="new"
id="act_wizard_mrp_bom_comparison"/>
</odoo>