Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip openfoodfact #250

Draft
wants to merge 1 commit into
base: 12.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions mrp_food_openfoodfacts/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
=============
MRP BoM Print
=============

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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_print
:alt: quentinDupont/grap-odoo-custom

|badge1| |badge2| |badge3|

Manage the various useful prints for Bill of Materials
Printing allergens for selected or all Bill of Materials

.. figure:: https://raw.githubusercontent.com/quentinDupont/grap-odoo-custom/12.0_MRP_Grap_prod/mrp_bom_print/static/description/bom_printing_allergens_with_options.gif

**Table of contents**

.. contents::
:local:

Known issues / Roadmap
======================

Allergens table works only when using product product on Bill Of Material.

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

Bugs are tracked on `GitHub Issues <https://github.com/quentinDupont/grap-odoo-custom/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/quentinDupont/grap-odoo-custom/issues/new?body=module:%20mrp_bom_print%0Aversion:%2012.0_MRP_Grap_prod%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
~~~~~~~

* GRAP

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

* Quentin Dupont ([email protected])

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

This module is part of the `quentinDupont/grap-odoo-custom <https://github.com/quentinDupont/grap-odoo-custom/tree/12.0_MRP_Grap_prod/mrp_bom_print>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions mrp_food_openfoodfacts/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
27 changes: 27 additions & 0 deletions mrp_food_openfoodfacts/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright (C) 2022 - Today: GRAP (http://www.grap.coop)
# @author: Quentin Dupont ([email protected])
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "MRP Food Openfoodfacts",
"summary": "Link Openfoodfact database with Odoo models",
"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",
"mrp_business",
],
"data": [
# "views/menu.xml",
"views/product_product.xml",
],
"external_dependencies": {
"python": ["openfoodfacts"],
},
"installable": True,
}
164 changes: 164 additions & 0 deletions mrp_food_openfoodfacts/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mrp_bom_print
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-09-05 09:01+0000\n"
"PO-Revision-Date: 2022-09-05 09:01+0000\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_print
#: model_terms:ir.ui.view,arch_db:mrp_bom_print.report_bom_allergens
msgid "<span class=\"code_explanation_title\"><b>Allergens: </b></span>"
msgstr "<span class=\"code_explanation_title\"><b>Allergènes : </b></span"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard_line__bom_allergens_ids
msgid "Allergens"
msgstr "Allergènes"

#. module: mrp_bom_print
#: model_terms:ir.ui.view,arch_db:mrp_bom_print.report_bom_allergens
msgid "Allergens table"
msgstr "Tableau des allergènes"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard_line__bom_id
msgid "Bill Of Material"
msgstr "Fiche technique"

#. module: mrp_bom_print
#: model:ir.actions.report,name:mrp_bom_print.bom_allergens
msgid "BoM Allergens"
msgstr ""

#. module: mrp_bom_print
#: model:ir.model,name:mrp_bom_print.model_report_bom_allergens
#: model:ir.model,name:mrp_bom_print.model_report_mrp_bom_print_report_bom_allergens
msgid "BoM Allergens report"
msgstr ""

#. module: mrp_bom_print
#: model_terms:ir.ui.view,arch_db:mrp_bom_print.view_bom_print_wizard_form
msgid "Cancel"
msgstr "Fermer cette fenêtre"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard__create_uid
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard_line__create_uid
msgid "Created by"
msgstr "Créé par"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard__create_date
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard_line__create_date
msgid "Created on"
msgstr "Créé le"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard__display_name
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard_line__display_name
#: model:ir.model.fields,field_description:mrp_bom_print.field_report_mrp_bom_print_report_bom_allergens__display_name
msgid "Display Name"
msgstr "Nom affiché"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard__option_allergens_only_code
msgid "Display allergen code instead of their name"
msgstr "Imprimer les codes allergènes au lieu de leur nom complet"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard__option_group_by_meal_category
msgid "Group BoM by meal category"
msgstr "Grouper par catégorie de repas"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard__id
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard_line__id
#: model:ir.model.fields,field_description:mrp_bom_print.field_report_mrp_bom_print_report_bom_allergens__id
msgid "ID"
msgstr ""

#. module: mrp_bom_print
#: model:ir.model.fields,help:mrp_bom_print.field_bom_print_wizard_line__bom_allergens_ids
msgid "Includes allergens of the product and its components"
msgstr "Inclus les allergènes du produit et de ses composants"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard____last_update
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard_line____last_update
#: model:ir.model.fields,field_description:mrp_bom_print.field_report_mrp_bom_print_report_bom_allergens____last_update
msgid "Last Modified on"
msgstr "Dernière modification le"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard__write_uid
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard_line__write_uid
msgid "Last Updated by"
msgstr "Dernière mise à jour par"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard__write_date
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard_line__write_date
msgid "Last Updated on"
msgstr "Dernière mise à jour le"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard__line_ids
msgid "Lines"
msgstr "Lignes"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard_line__bom_meal_category
msgid "Meal category"
msgstr "Catégorie de repas"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard__option_allergens_only_code_text
msgid "Option Allergens Only Code Text"
msgstr ""

#. module: mrp_bom_print
#: model_terms:ir.ui.view,arch_db:mrp_bom_print.view_bom_print_wizard_form
msgid "Print"
msgstr "Imprimer"

#. module: mrp_bom_print
#: model:ir.actions.act_window,name:mrp_bom_print.action_mrp_bom_print_wizard
#: model:ir.ui.menu,name:mrp_bom_print.menu_mrp_bom_print
#: model_terms:ir.ui.view,arch_db:mrp_bom_print.view_bom_print_wizard_form
msgid "Print Allergen table"
msgstr "Imprimer le tableau des allergènes"

#. module: mrp_bom_print
#: model:ir.model.fields,field_description:mrp_bom_print.field_bom_print_wizard_line__wizard_id
msgid "Wizard"
msgstr "Assistant"

#. module: mrp_bom_print
#: model:ir.model,name:mrp_bom_print.model_bom_print_wizard
msgid "Wizard for printing bill of materials"
msgstr ""

#. module: mrp_bom_print
#: model:ir.model,name:mrp_bom_print.model_bom_print_wizard_line
msgid "Wizard line for printing bill of materials"
msgstr ""

#. module: mrp_bom_print
#: model_terms:ir.ui.view,arch_db:mrp_bom_print.view_bom_print_wizard_form
msgid "🔧 Choose options"
msgstr "🔧 Choisir les options"

#. module: mrp_bom_print
#: model_terms:ir.ui.view,arch_db:mrp_bom_print.view_bom_print_wizard_form
msgid "🖨️ Choose BoMs to print ↓"
msgstr "🖨️ Choisir les fiches techniques à imprimer ↓"
1 change: 1 addition & 0 deletions mrp_food_openfoodfacts/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_product
72 changes: 72 additions & 0 deletions mrp_food_openfoodfacts/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright (C) 2022 - Today: GRAP (http://www.grap.coop)
# @author: Quentin DUPONT ([email protected])
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import re
from odoo import api, fields, models
from openfoodfacts import openfoodfacts

class ProductProduct(models.Model):
_inherit = "product.product"

# API Documentation https://openfoodfacts.github.io/openfoodfacts-python/Usage
@api.model
def _get_product_in_off_database(self):
query = {}
if self.barcode:
res = openfoodfacts.products.get_product(self.barcode)
res_product = res['product']
res_name = res_product['product_name']
print("======== AVEC CODE BARRE ==========")
else:
query["search_terms"] = self.name
res = openfoodfacts.products.advanced_search(query)
res_product = res['products'][0]
res_name = res_product['product_name']
print("======== AVEC NOM ==========")
# import pdb; pdb.set_trace()
print("=============>>>>>>>>>>>>" + res_name)
return res_product

@api.model
def _set_product_allergens(self, product_off):
# Get product allergens_tags
product_off_allergens = product_off['allergens_tags']
# Get company allergens
allergens_obj = self.env["product.allergen"]
# for each allergens_tags, chercher l'équivalent
for product_off_allergen in product_off_allergens:
# In OFF, allergens sont sous la forme "en:gluten"
# import pdb; pdb.set_trace()
matches = re.search(":([a-zA-Z]+)", product_off_allergen)
if matches and matches.group(1):
# We get the allergen name
# try to find allergen in database fitting ignoring letter case
TODO
allergen_find = allergens_obj.search([('name', '=', matches.group(1))])
print("youîiiiiiiiiiiiiiiii")
# set many to many

@api.multi
def button_fill_product_informations(self):
for product in self:
off_product = self._get_product_in_off_database()

@api.multi
def button_get_allergens_off(self):
for product in self:
off_product = self._get_product_in_off_database()
product._set_product_allergens(off_product)
# login_session_object = openfoodfacts.utils.login_into_OFF()
# allergens = openfoodfacts.facets.get_allergens()

# openfoodfacts.products.get_by_facets({'trace': 'egg','country': 'france'})

# res = openfoodfacts.products.get_product("8019428000105")
# openfoodfacts.products.advanced_search({"search_terms":"lait d'avoine the bridge"})
#
# res['product']
# res['product']['nutriscore_grade']
# # donne une lettre a b c d e
# res['product']['allergens_tags']
# # donne ['en:gluten']
Empty file.
1 change: 1 addition & 0 deletions mrp_food_openfoodfacts/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Quentin Dupont ([email protected])
4 changes: 4 additions & 0 deletions mrp_food_openfoodfacts/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Manage the various useful prints for Bill of Materials
Printing allergens for selected or all Bill of Materials

.. figure:: ../static/description/bom_printing_allergens_with_options.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading