From 85bca05c0e05740210fed3c792e22057d89b0228 Mon Sep 17 00:00:00 2001 From: Quentin Dupont Date: Wed, 24 Aug 2022 11:56:55 +0200 Subject: [PATCH 01/30] [WIP] MRP Bom Print - button, models. Todo : empty report for BoM allergens --- mrp_bom_print/README.rst | 66 +++ mrp_bom_print/__init__.py | 3 + mrp_bom_print/__manifest__.py | 26 ++ mrp_bom_print/data/report_paperformat.xml | 25 ++ mrp_bom_print/i18n/fr.po | 0 mrp_bom_print/models/__init__.py | 0 mrp_bom_print/readme/CONFIGURE.rst | 0 mrp_bom_print/readme/CONTRIBUTORS.rst | 1 + mrp_bom_print/readme/DESCRIPTION.rst | 1 + mrp_bom_print/report/__init__.py | 1 + mrp_bom_print/report/ir_actions_report.xml | 25 ++ mrp_bom_print/report/report_bom_allergens.py | 42 ++ mrp_bom_print/report/report_bom_allergens.xml | 20 + mrp_bom_print/static/description/index.html | 425 ++++++++++++++++++ mrp_bom_print/views/menu.xml | 13 + mrp_bom_print/wizard/__init__.py | 2 + mrp_bom_print/wizard/bom_print_wizard.py | 66 +++ mrp_bom_print/wizard/bom_print_wizard_line.py | 25 ++ .../wizard/view_bom_print_wizard.xml | 41 ++ 19 files changed, 782 insertions(+) create mode 100644 mrp_bom_print/README.rst create mode 100644 mrp_bom_print/__init__.py create mode 100644 mrp_bom_print/__manifest__.py create mode 100644 mrp_bom_print/data/report_paperformat.xml create mode 100644 mrp_bom_print/i18n/fr.po create mode 100644 mrp_bom_print/models/__init__.py create mode 100644 mrp_bom_print/readme/CONFIGURE.rst create mode 100644 mrp_bom_print/readme/CONTRIBUTORS.rst create mode 100644 mrp_bom_print/readme/DESCRIPTION.rst create mode 100644 mrp_bom_print/report/__init__.py create mode 100644 mrp_bom_print/report/ir_actions_report.xml create mode 100644 mrp_bom_print/report/report_bom_allergens.py create mode 100644 mrp_bom_print/report/report_bom_allergens.xml create mode 100644 mrp_bom_print/static/description/index.html create mode 100644 mrp_bom_print/views/menu.xml create mode 100644 mrp_bom_print/wizard/__init__.py create mode 100644 mrp_bom_print/wizard/bom_print_wizard.py create mode 100644 mrp_bom_print/wizard/bom_print_wizard_line.py create mode 100644 mrp_bom_print/wizard/view_bom_print_wizard.xml diff --git a/mrp_bom_print/README.rst b/mrp_bom_print/README.rst new file mode 100644 index 00000000..2b631f3c --- /dev/null +++ b/mrp_bom_print/README.rst @@ -0,0 +1,66 @@ +=========== +MRP BoM Tag +=========== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-quentinDupont%2Fgrap--odoo--custom-lightgray.png?logo=github + :target: https://github.com/quentinDupont/grap-odoo-custom/tree/12.0_MRP_Grap_prod/mrp_bom_tag + :alt: quentinDupont/grap-odoo-custom + +|badge1| |badge2| |badge3| + +Add Tags in Bill Of Materials in ordrer to find them easily with tag as keywords. + +.. figure:: https://raw.githubusercontent.com/quentinDupont/grap-odoo-custom/12.0_MRP_Grap_prod/mrp_bom_tag/static/description/bom_with_tag.png + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +In Configuration / BoM Tags, user can configure its tags and parent's tags. + +.. figure:: https://raw.githubusercontent.com/quentinDupont/grap-odoo-custom/12.0_MRP_Grap_prod/mrp_bom_tag/static/description/bom_tag_configuration.png + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* GRAP + +Contributors +~~~~~~~~~~~~ + +* Quentin Dupont (quentin.dupont@grap.coop) + +Maintainers +~~~~~~~~~~~ + +This module is part of the `quentinDupont/grap-odoo-custom `_ project on GitHub. + +You are welcome to contribute. diff --git a/mrp_bom_print/__init__.py b/mrp_bom_print/__init__.py new file mode 100644 index 00000000..50235cbb --- /dev/null +++ b/mrp_bom_print/__init__.py @@ -0,0 +1,3 @@ +from . import models +from . import wizard +from . import report diff --git a/mrp_bom_print/__manifest__.py b/mrp_bom_print/__manifest__.py new file mode 100644 index 00000000..d449c1da --- /dev/null +++ b/mrp_bom_print/__manifest__.py @@ -0,0 +1,26 @@ +# Copyright (C) 2022 - Today: GRAP (http://www.grap.coop) +# @author: Quentin Dupont (quentin.dupont@grap.coop) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "MRP BoM Print", + "summary": "Manage the various useful prints for Bill of Materials", + "version": "12.0.1.1.0", + "category": "GRAP - Custom", + "author": "GRAP", + "website": "https://github.com/grap/grap-odoo-custom", + "license": "AGPL-3", + "depends": [ + "mrp", + # GRAP + "mrp_food", + ], + "data": [ + "data/report_paperformat.xml", + "views/menu.xml", + "report/report_bom_allergens.xml", + "report/ir_actions_report.xml", + "wizard/view_bom_print_wizard.xml", + ], + "installable": True, +} diff --git a/mrp_bom_print/data/report_paperformat.xml b/mrp_bom_print/data/report_paperformat.xml new file mode 100644 index 00000000..abefbe6d --- /dev/null +++ b/mrp_bom_print/data/report_paperformat.xml @@ -0,0 +1,25 @@ + + + + + + + Products Print Format + A4 + 0 + 0 + Portrait + 5 + 5 + 2 + 2 + + 10 + 90 + + + diff --git a/mrp_bom_print/i18n/fr.po b/mrp_bom_print/i18n/fr.po new file mode 100644 index 00000000..e69de29b diff --git a/mrp_bom_print/models/__init__.py b/mrp_bom_print/models/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/mrp_bom_print/readme/CONFIGURE.rst b/mrp_bom_print/readme/CONFIGURE.rst new file mode 100644 index 00000000..e69de29b diff --git a/mrp_bom_print/readme/CONTRIBUTORS.rst b/mrp_bom_print/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..9ed47062 --- /dev/null +++ b/mrp_bom_print/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Quentin Dupont (quentin.dupont@grap.coop) diff --git a/mrp_bom_print/readme/DESCRIPTION.rst b/mrp_bom_print/readme/DESCRIPTION.rst new file mode 100644 index 00000000..82919243 --- /dev/null +++ b/mrp_bom_print/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Manage the various useful prints for Bill of Materials diff --git a/mrp_bom_print/report/__init__.py b/mrp_bom_print/report/__init__.py new file mode 100644 index 00000000..b1107eb7 --- /dev/null +++ b/mrp_bom_print/report/__init__.py @@ -0,0 +1 @@ +from . import report_bom_allergens diff --git a/mrp_bom_print/report/ir_actions_report.xml b/mrp_bom_print/report/ir_actions_report.xml new file mode 100644 index 00000000..ffa0fd60 --- /dev/null +++ b/mrp_bom_print/report/ir_actions_report.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + diff --git a/mrp_bom_print/report/report_bom_allergens.py b/mrp_bom_print/report/report_bom_allergens.py new file mode 100644 index 00000000..b9a383ae --- /dev/null +++ b/mrp_bom_print/report/report_bom_allergens.py @@ -0,0 +1,42 @@ +from odoo import models + + +class ReportBomAllergens(models.AbstractModel): + _name = "report.bom.allergens" + _description = "BoM Allergens report" + + # @api.model + # def _get_report_values(self, docids, data=None): + # + # # mark the selected products as Up To Date if print succeed + # line_obj = self.env["bom.print.wizard.line"] + # lines = line_obj.browse([int(x) for x in data["line_data"]]) + # return { + # 'doc_ids': docs.ids, + # 'docs': docs, + # } + # + # @api.model + # def _get_report_values(self, docids, data=None): + # AccountPaymentOrderObj = self.env['account.payment.order'] + # docs = AccountPaymentOrderObj.browse(docids) + # + # return { + # 'doc_ids': docids, + # 'doc_model': 'account.payment.order', + # 'docs': docs, + # 'data': data, + # 'env': self.env, + # 'get_bank_account_name': self.get_bank_account_name, + # 'formatLang': formatLang, + # } + # + # @api.multi + # def _get_report_values(self, docids, data=None): + # docs = self.env['sale.order'].browse(docids) + # return { + # 'doc_ids': docs.ids, + # 'doc_model': 'sale.order', + # 'docs': docs, + # 'proforma': True + # } diff --git a/mrp_bom_print/report/report_bom_allergens.xml b/mrp_bom_print/report/report_bom_allergens.xml new file mode 100644 index 00000000..23baddbe --- /dev/null +++ b/mrp_bom_print/report/report_bom_allergens.xml @@ -0,0 +1,20 @@ + + + + + + + + diff --git a/mrp_bom_print/static/description/index.html b/mrp_bom_print/static/description/index.html new file mode 100644 index 00000000..c906b5f7 --- /dev/null +++ b/mrp_bom_print/static/description/index.html @@ -0,0 +1,425 @@ + + + + + + +MRP BoM Tag + + + +
+

MRP BoM Tag

+ + +

Beta License: AGPL-3 quentinDupont/grap-odoo-custom

+

Add Tags in Bill Of Materials in ordrer to find them easily with tag as keywords.

+
+https://raw.githubusercontent.com/quentinDupont/grap-odoo-custom/12.0_MRP_Grap_prod/mrp_bom_tag/static/description/bom_with_tag.png +
+

Table of contents

+ +
+

Configuration

+

In Configuration / BoM Tags, user can configure its tags and parent’s tags.

+
+https://raw.githubusercontent.com/quentinDupont/grap-odoo-custom/12.0_MRP_Grap_prod/mrp_bom_tag/static/description/bom_tag_configuration.png +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • GRAP
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is part of the quentinDupont/grap-odoo-custom project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/mrp_bom_print/views/menu.xml b/mrp_bom_print/views/menu.xml new file mode 100644 index 00000000..b0c34007 --- /dev/null +++ b/mrp_bom_print/views/menu.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/mrp_bom_print/wizard/__init__.py b/mrp_bom_print/wizard/__init__.py new file mode 100644 index 00000000..dfd775e1 --- /dev/null +++ b/mrp_bom_print/wizard/__init__.py @@ -0,0 +1,2 @@ +from . import bom_print_wizard +from . import bom_print_wizard_line diff --git a/mrp_bom_print/wizard/bom_print_wizard.py b/mrp_bom_print/wizard/bom_print_wizard.py new file mode 100644 index 00000000..931c7992 --- /dev/null +++ b/mrp_bom_print/wizard/bom_print_wizard.py @@ -0,0 +1,66 @@ +# Copyright (C) 2022 - Today: GRAP (http://www.grap.coop) +# @author: Quentin DUPONT (quentin.dupont@grap.coop) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class BomPrintWizard(models.TransientModel): + _name = "bom.print.wizard" + _description = "Wizard for printing bill of materials" + + line_ids = fields.One2many( + comodel_name="bom.print.wizard.line", + inverse_name="wizard_id", + string="Lines", + default=lambda s: s._default_line_ids(), + ) + + @api.model + def _default_line_ids(self): + lines_vals = [] + context = self.env.context + bom_obj = self.env["mrp.bom"] + # Get BoM + bom_ids = context.get("active_ids", []) + boms = bom_obj.browse(bom_ids) + + # Initialize lines + for bom in boms: + lines_vals.append( + ( + 0, + 0, + { + "bom_id": bom.id, + "quantity": 1, + }, + ) + ) + return lines_vals + + # View Section + @api.multi + def print_report(self): + self.ensure_one() + data = self._prepare_data() + return self.env.ref("mrp_bom_print.report_bom_allergens").report_action( + self, data=data + ) + + @api.multi + def _prepare_data(self): + return { + "line_data": [x.id for x in self.line_ids], + } + + @api.multi + def _prepare_product_data(self): + self.ensure_one() + product_data = {} + for line in self.line_ids: + if line.product_id.id not in product_data: + product_data[line.product_id.id] = line.quantity + else: + product_data[line.product_id.id] += line.quantity + return product_data diff --git a/mrp_bom_print/wizard/bom_print_wizard_line.py b/mrp_bom_print/wizard/bom_print_wizard_line.py new file mode 100644 index 00000000..31b47893 --- /dev/null +++ b/mrp_bom_print/wizard/bom_print_wizard_line.py @@ -0,0 +1,25 @@ +# Copyright (C) 2022 - Today: GRAP (http://www.grap.coop) +# @author: Quentin DUPONT (quentin.dupont@grap.coop) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class BomPrintWizardLine(models.TransientModel): + _name = "bom.print.wizard.line" + _description = "Wizard line for printing bill of materials" + + # Columns Section + wizard_id = fields.Many2one(comodel_name="bom.print.wizard") + + bom_id = fields.Many2one( + comodel_name="mrp.bom", string="Bill Of Material", required=True + ) + + bom_allergens_ids = fields.Many2many( + comodel_name="product.allergen", + related="bom_id.bom_allergen_ids", + readonly=False, + ) + + quantity = fields.Integer(string="Quantity", required=True, default=1) diff --git a/mrp_bom_print/wizard/view_bom_print_wizard.xml b/mrp_bom_print/wizard/view_bom_print_wizard.xml new file mode 100644 index 00000000..fbb4ede5 --- /dev/null +++ b/mrp_bom_print/wizard/view_bom_print_wizard.xml @@ -0,0 +1,41 @@ + + + + + + bom.print.wizard + +
+ + + + + + + + + + +
+
+
+
+
+
+ + + Print Bill of Materials + bom.print.wizard + form + form + new + + + +
From d4833f1fc616bb1bbb29861432cc343115f2bdd4 Mon Sep 17 00:00:00 2001 From: Quentin Dupont Date: Tue, 30 Aug 2022 17:36:44 +0200 Subject: [PATCH 02/30] POC Print BoM Allergens OK ! + Option code [WIP] Clean code, ux etc. --- mrp_bom_print/__manifest__.py | 2 +- mrp_bom_print/data/report_paperformat.xml | 6 +- mrp_bom_print/report/ir_actions_report.xml | 7 +- mrp_bom_print/report/report_bom_allergens.py | 71 +++++++++---------- mrp_bom_print/report/report_bom_allergens.xml | 42 +++++++++-- mrp_bom_print/views/menu.xml | 2 +- mrp_bom_print/wizard/bom_print_wizard.py | 9 ++- .../wizard/view_bom_print_wizard.xml | 3 +- 8 files changed, 88 insertions(+), 54 deletions(-) diff --git a/mrp_bom_print/__manifest__.py b/mrp_bom_print/__manifest__.py index d449c1da..00c280f2 100644 --- a/mrp_bom_print/__manifest__.py +++ b/mrp_bom_print/__manifest__.py @@ -17,10 +17,10 @@ ], "data": [ "data/report_paperformat.xml", - "views/menu.xml", "report/report_bom_allergens.xml", "report/ir_actions_report.xml", "wizard/view_bom_print_wizard.xml", + "views/menu.xml", ], "installable": True, } diff --git a/mrp_bom_print/data/report_paperformat.xml b/mrp_bom_print/data/report_paperformat.xml index abefbe6d..fa8c77b6 100644 --- a/mrp_bom_print/data/report_paperformat.xml +++ b/mrp_bom_print/data/report_paperformat.xml @@ -7,12 +7,12 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - - Products Print Format + + BoM Allergens Print Format A4 0 0 - Portrait + Landscape 5 5 2 diff --git a/mrp_bom_print/report/ir_actions_report.xml b/mrp_bom_print/report/ir_actions_report.xml index ffa0fd60..feb0fad7 100644 --- a/mrp_bom_print/report/ir_actions_report.xml +++ b/mrp_bom_print/report/ir_actions_report.xml @@ -8,7 +8,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - - - + + diff --git a/mrp_bom_print/report/report_bom_allergens.py b/mrp_bom_print/report/report_bom_allergens.py index b9a383ae..fa351aa1 100644 --- a/mrp_bom_print/report/report_bom_allergens.py +++ b/mrp_bom_print/report/report_bom_allergens.py @@ -1,42 +1,39 @@ -from odoo import models +from odoo import api, models class ReportBomAllergens(models.AbstractModel): - _name = "report.bom.allergens" + _name = "report.mrp_bom_print.report_bom_allergens" _description = "BoM Allergens report" - # @api.model - # def _get_report_values(self, docids, data=None): - # - # # mark the selected products as Up To Date if print succeed - # line_obj = self.env["bom.print.wizard.line"] - # lines = line_obj.browse([int(x) for x in data["line_data"]]) - # return { - # 'doc_ids': docs.ids, - # 'docs': docs, - # } - # - # @api.model - # def _get_report_values(self, docids, data=None): - # AccountPaymentOrderObj = self.env['account.payment.order'] - # docs = AccountPaymentOrderObj.browse(docids) - # - # return { - # 'doc_ids': docids, - # 'doc_model': 'account.payment.order', - # 'docs': docs, - # 'data': data, - # 'env': self.env, - # 'get_bank_account_name': self.get_bank_account_name, - # 'formatLang': formatLang, - # } - # - # @api.multi - # def _get_report_values(self, docids, data=None): - # docs = self.env['sale.order'].browse(docids) - # return { - # 'doc_ids': docs.ids, - # 'doc_model': 'sale.order', - # 'docs': docs, - # 'proforma': True - # } + @api.model + def _get_report_values(self, docids, data=None): + allergen_obj = self.env["product.allergen"] + allergens_all = allergen_obj.search([]) + + docargs = { + "allergens": allergens_all, + "boms_and_allergens": self._prepare_data(data), + } + return docargs + + @api.model + def _prepare_data(self, data): + line_obj = self.env["bom.print.wizard.line"] + allergen_obj = self.env["product.allergen"] + allergens_all = allergen_obj.search([]) + + # Preparing data for report → list of list + boms = line_obj.browse([int(x) for x in data["line_data"]]) + boms_and_allergens = [] + for bom in boms: + tmpList_allergens = [] + tmpList_allergens.append(bom.bom_id.product_id.name) + for allergen in allergens_all: + if allergen.id in bom.bom_id.bom_allergen_ids.ids: + # we found this allergen + tmpList_allergens.append("x") + else: + tmpList_allergens.append(" ") + boms_and_allergens.append(tmpList_allergens) + + return boms_and_allergens diff --git a/mrp_bom_print/report/report_bom_allergens.xml b/mrp_bom_print/report/report_bom_allergens.xml index 23baddbe..66038a56 100644 --- a/mrp_bom_print/report/report_bom_allergens.xml +++ b/mrp_bom_print/report/report_bom_allergens.xml @@ -7,13 +7,43 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + diff --git a/mrp_bom_print/views/menu.xml b/mrp_bom_print/views/menu.xml index b0c34007..5b56e0f8 100644 --- a/mrp_bom_print/views/menu.xml +++ b/mrp_bom_print/views/menu.xml @@ -7,7 +7,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). diff --git a/mrp_bom_print/wizard/bom_print_wizard.py b/mrp_bom_print/wizard/bom_print_wizard.py index 931c7992..44815c3b 100644 --- a/mrp_bom_print/wizard/bom_print_wizard.py +++ b/mrp_bom_print/wizard/bom_print_wizard.py @@ -16,6 +16,11 @@ class BomPrintWizard(models.TransientModel): default=lambda s: s._default_line_ids(), ) + option_allergens_only_code = fields.Boolean( + string="Display allergen code instead of their name", + default=False, + ) + @api.model def _default_line_ids(self): lines_vals = [] @@ -44,7 +49,8 @@ def _default_line_ids(self): def print_report(self): self.ensure_one() data = self._prepare_data() - return self.env.ref("mrp_bom_print.report_bom_allergens").report_action( + # Get ir_actions_report bom_allergens + return self.env.ref("mrp_bom_print.bom_allergens").report_action( self, data=data ) @@ -52,6 +58,7 @@ def print_report(self): def _prepare_data(self): return { "line_data": [x.id for x in self.line_ids], + "option_allergens_only_code": self.option_allergens_only_code, } @api.multi diff --git a/mrp_bom_print/wizard/view_bom_print_wizard.xml b/mrp_bom_print/wizard/view_bom_print_wizard.xml index fbb4ede5..fc89d187 100644 --- a/mrp_bom_print/wizard/view_bom_print_wizard.xml +++ b/mrp_bom_print/wizard/view_bom_print_wizard.xml @@ -10,6 +10,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). bom.print.wizard
+