diff --git a/purchase_order_product_recommendation/README.rst b/purchase_order_product_recommendation/README.rst new file mode 100644 index 00000000000..d058467ec9f --- /dev/null +++ b/purchase_order_product_recommendation/README.rst @@ -0,0 +1,110 @@ +===================================== +Purchase Order Product Recommendation +===================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/13.0/purchase_order_product_recommendation + :alt: OCA/purchase-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/purchase-workflow-13-0/purchase-workflow-13-0-purchase_order_product_recommendation + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/142/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a recommended products wizard to current purchase order. + +It is based on delivered products to customer locations in a given range of +dates, and allows the purchase manager to quickly know the most sold products +for the current supplier, which results in an easy to use hint to improve +the purchase workflow. + +If you want a better mobile usability, the module is ready to use with the +'web_widget_numeric_step' module. Just install it and you will get a better +numeric input experience. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +#. Create a new purchase order. +#. Assign its supplier. +#. Press *Recommended Products* button. +#. Set or adjust hinted quantities to order. +#. Press *Accept*. + +The wizard filters products those with supplier infos set for the current order +supplier. Then it computes how many times those products have been delivered to +customer locations, and finally it makes a simple estimation of how many +quantites would be necesary to order given the forcasted stock and the computed +demand. + +If you want to constrain results to only some categories, you can also select +them in the wizard. + +If you have multiple warehouses, you can also constrain the recommendations to +the deliveries of specific ones. + +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 +~~~~~~~ + +* Tecnativa + +Contributors +~~~~~~~~~~~~ + +* `Tecnativa `_: + + * David Vidal + * Ernesto Tejeda + * Manuel Calero + * Pedro M. Baeza + +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/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_order_product_recommendation/__init__.py b/purchase_order_product_recommendation/__init__.py new file mode 100644 index 00000000000..5cb1c49143f --- /dev/null +++ b/purchase_order_product_recommendation/__init__.py @@ -0,0 +1 @@ +from . import wizards diff --git a/purchase_order_product_recommendation/__manifest__.py b/purchase_order_product_recommendation/__manifest__.py new file mode 100644 index 00000000000..2a23acaee14 --- /dev/null +++ b/purchase_order_product_recommendation/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2019 David Vidal +# Copyright 2020 Manuel Calero - Tecnativa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + "name": "Purchase Order Product Recommendation", + "summary": "Recommend products to buy to supplier based on history", + "version": "15.0.1.0.0", + "category": "Purchases", + "website": "https://github.com/OCA/purchase-workflow", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["purchase_stock"], + "data": [ + "security/ir.model.access.csv", + "wizards/purchase_order_recommendation_view.xml", + "views/purchase_order_view.xml", + ], +} diff --git a/purchase_order_product_recommendation/i18n/es.po b/purchase_order_product_recommendation/i18n/es.po new file mode 100644 index 00000000000..011e972a6b1 --- /dev/null +++ b/purchase_order_product_recommendation/i18n/es.po @@ -0,0 +1,303 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_product_recommendation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2021-05-04 15:19+0000\n" +"PO-Revision-Date: 2021-05-04 17:19+0200\n" +"Last-Translator: Carlos \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 2.0.6\n" + +#. module: purchase_order_product_recommendation +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Accept" +msgstr "Aceptar" + +#. module: purchase_order_product_recommendation +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Cancel" +msgstr "Cancelar" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__warehouse_ids +msgid "Constrain search to an specific warehouse" +msgstr "Restringir búsqueda a un almacén concreto" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__create_uid +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__create_date +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__create_date +msgid "Created on" +msgstr "Creado el" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__currency_id +msgid "Currency" +msgstr "Moneda" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__date_begin +msgid "Date Begin" +msgstr "Fecha de inicio" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__date_end +msgid "Date End" +msgstr "Fecha final" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__display_name +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__display_name +msgid "Display Name" +msgstr "Nombre a mostrar" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__product_category_ids +msgid "Filter by product internal category" +msgstr "Filtrar por categoría interna de producto" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__date_end +msgid "Final date to compute recommendations." +msgstr "Fecha has la que se calcularán las recomendaciones." + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_virtual_available +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Forecasted Qty" +msgstr "Ctd Prevista" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__id +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__id +msgid "ID" +msgstr "ID (identificación)" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__date_begin +msgid "Initial date to compute recommendations." +msgstr "Fecha desde la que se calcularán las recomendaciones." + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__is_modified +msgid "Is Modified" +msgstr "Está modificado" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation____last_update +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line____last_update +msgid "Last Modified on" +msgstr "Última modificación en" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__write_uid +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__write_uid +msgid "Last Updated by" +msgstr "Última actualización por" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__write_date +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__write_date +msgid "Last Updated on" +msgstr "Última actualización el" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__line_amount +msgid "Number of recommendations" +msgstr "Número de recomendaciones" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__price_unit +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Price" +msgstr "Precio" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__product_id +msgid "Product" +msgstr "Producto" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__product_category_ids +msgid "Product Categories" +msgstr "Categorías de productos" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__product_name +msgid "Product name" +msgstr "Nombre de producto" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__product_code +msgid "Product reference" +msgstr "Referencia del producto" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__line_ids +msgid "Products" +msgstr "Productos" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__purchase_line_id +msgid "Purchase Line" +msgstr "Línea de compra" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__order_id +msgid "Purchase Order" +msgstr "Pedido de compra" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_included +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Qty" +msgstr "Ctd" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_avg_delivered +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Qty Dlvd./day" +msgstr "Ctd entrg./día" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_available +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Qty On Hand" +msgstr "Ctd a mano" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_received +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Qty Received" +msgstr "Ctd recibida" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_delivered +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Qty delivered" +msgstr "Ctd entregada" + +#. module: purchase_order_product_recommendation +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_form +msgid "Recommended Products" +msgstr "Productos recomendados" + +#. module: purchase_order_product_recommendation +#: model:ir.actions.act_window,name:purchase_order_product_recommendation.purchase_order_recommendation_action +msgid "Recommended Products for this Customer" +msgstr "Productos recomendados para este proveedor" + +#. module: purchase_order_product_recommendation +#: model:ir.model,name:purchase_order_product_recommendation.model_purchase_order_recommendation_line +msgid "Recommended product for current purchase order" +msgstr "Producto recomendado para el pedido de compra en curso" + +#. module: purchase_order_product_recommendation +#: model:ir.model,name:purchase_order_product_recommendation.model_purchase_order_recommendation +msgid "Recommended products for current purchase order" +msgstr "Productos recomendados para el pedido de compra en curso" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__show_all_partner_products +msgid "Show all products with supplier infos for this supplier" +msgstr "Mostrar todos los productos con tarifas de compra para este proveedor" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__show_all_products +msgid "Show all purchasable products" +msgstr "Mostrar todos los productos comprables" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__show_all_partner_products +msgid "Show all supplier products" +msgstr "Mostrar todos los productos del proveedor" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__line_amount +msgid "" +"Stablish a limit on how many recommendations you want to get.Leave it as 0 " +"to set no limit" +msgstr "" +"Establezca un límite de cuántas recomendaciones desea obtener. Déjelo en 0 " +"si no desea límite" + +#. module: purchase_order_product_recommendation +#: code:addons/purchase_order_product_recommendation/wizards/purchase_order_recommendation.py:0 +#, python-format +msgid "This wizard is only valid for purchases" +msgstr "Este asistente solo es válido para compras" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__times_delivered +msgid "Times Delivered" +msgstr "Veces entregado" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__times_received +msgid "Times Received" +msgstr "Veces recibido" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__show_all_products +msgid "Useful if a product hasn't been selled by the partner yet" +msgstr "Resulta útil si un producto aún no ha sido vendido por el proveedor." + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__partner_id +msgid "Vendor" +msgstr "Proveedor" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__warehouse_ids +msgid "Warehouse" +msgstr "Almacén" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__warehouse_count +msgid "Warehouse Count" +msgstr "Nº de Almacenes" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__wizard_id +msgid "Wizard" +msgstr "Asistente" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation_line__partner_id +msgid "You can find a vendor by its Name, TIN, Email or Internal Reference." +msgstr "" + +#~ msgid "Price Unit" +#~ msgstr "Precio unitario" + +#~ msgid "Units Available" +#~ msgstr "Cantidad a mano" + +#~ msgid "Units Avg Delivered" +#~ msgstr "Media de unidades entregadas" + +#~ msgid "Units Delivered" +#~ msgstr "Unidades entregadas" + +#~ msgid "Units Included" +#~ msgstr "Unidades incluídas" + +#~ msgid "Units Received" +#~ msgstr "Unidades recibidas" + +#~ msgid "Units Virtual Available" +#~ msgstr "Cantidad prevista" diff --git a/purchase_order_product_recommendation/i18n/purchase_order_product_recommendation.pot b/purchase_order_product_recommendation/i18n/purchase_order_product_recommendation.pot new file mode 100644 index 00000000000..e141129b42e --- /dev/null +++ b/purchase_order_product_recommendation/i18n/purchase_order_product_recommendation.pot @@ -0,0 +1,276 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_product_recommendation +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.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: purchase_order_product_recommendation +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Accept" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Cancel" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__warehouse_ids +msgid "Constrain search to an specific warehouse" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__create_uid +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__create_uid +msgid "Created by" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__create_date +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__create_date +msgid "Created on" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__currency_id +msgid "Currency" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__date_begin +msgid "Date Begin" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__date_end +msgid "Date End" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__display_name +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__display_name +msgid "Display Name" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__product_category_ids +msgid "Filter by product internal category" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__date_end +msgid "Final date to compute recommendations." +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_virtual_available +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Forecasted Qty" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__id +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__id +msgid "ID" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__date_begin +msgid "Initial date to compute recommendations." +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__is_modified +msgid "Is Modified" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation____last_update +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__write_uid +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__write_date +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__write_date +msgid "Last Updated on" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__line_amount +msgid "Number of recommendations" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__price_unit +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Price" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__product_id +msgid "Product" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__product_category_ids +msgid "Product Categories" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__product_name +msgid "Product name" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__product_code +msgid "Product reference" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__line_ids +msgid "Products" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__purchase_line_id +msgid "Purchase Line" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__order_id +msgid "Purchase Order" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_included +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Qty" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_avg_delivered +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Qty Dlvd./day" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_available +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Qty On Hand" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_received +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Qty Received" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__units_delivered +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_recommendation_view_form +msgid "Qty delivered" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model_terms:ir.ui.view,arch_db:purchase_order_product_recommendation.purchase_order_form +msgid "Recommended Products" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.actions.act_window,name:purchase_order_product_recommendation.purchase_order_recommendation_action +msgid "Recommended Products for this Customer" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model,name:purchase_order_product_recommendation.model_purchase_order_recommendation_line +msgid "Recommended product for current purchase order" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model,name:purchase_order_product_recommendation.model_purchase_order_recommendation +msgid "Recommended products for current purchase order" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__show_all_partner_products +msgid "Show all products with supplier infos for this supplier" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__show_all_products +msgid "Show all purchasable products" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__show_all_partner_products +msgid "Show all supplier products" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__line_amount +msgid "" +"Stablish a limit on how many recommendations you want to get.Leave it as 0 " +"to set no limit" +msgstr "" + +#. module: purchase_order_product_recommendation +#: code:addons/purchase_order_product_recommendation/wizards/purchase_order_recommendation.py:0 +#, python-format +msgid "This wizard is only valid for purchases" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__times_delivered +msgid "Times Delivered" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__times_received +msgid "Times Received" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation__show_all_products +msgid "Useful if a product hasn't been selled by the partner yet" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__partner_id +msgid "Vendor" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__warehouse_ids +msgid "Warehouse" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation__warehouse_count +msgid "Warehouse Count" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,field_description:purchase_order_product_recommendation.field_purchase_order_recommendation_line__wizard_id +msgid "Wizard" +msgstr "" + +#. module: purchase_order_product_recommendation +#: model:ir.model.fields,help:purchase_order_product_recommendation.field_purchase_order_recommendation_line__partner_id +msgid "You can find a vendor by its Name, TIN, Email or Internal Reference." +msgstr "" diff --git a/purchase_order_product_recommendation/readme/CONTRIBUTORS.rst b/purchase_order_product_recommendation/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000000..83f278ca610 --- /dev/null +++ b/purchase_order_product_recommendation/readme/CONTRIBUTORS.rst @@ -0,0 +1,6 @@ +* `Tecnativa `_: + + * David Vidal + * Ernesto Tejeda + * Manuel Calero + * Pedro M. Baeza diff --git a/purchase_order_product_recommendation/readme/DESCRIPTION.rst b/purchase_order_product_recommendation/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..19a79e6d242 --- /dev/null +++ b/purchase_order_product_recommendation/readme/DESCRIPTION.rst @@ -0,0 +1,10 @@ +This module adds a recommended products wizard to current purchase order. + +It is based on delivered products to customer locations in a given range of +dates, and allows the purchase manager to quickly know the most sold products +for the current supplier, which results in an easy to use hint to improve +the purchase workflow. + +If you want a better mobile usability, the module is ready to use with the +'web_widget_numeric_step' module. Just install it and you will get a better +numeric input experience. diff --git a/purchase_order_product_recommendation/readme/USAGE.rst b/purchase_order_product_recommendation/readme/USAGE.rst new file mode 100644 index 00000000000..ba13b5b3df4 --- /dev/null +++ b/purchase_order_product_recommendation/readme/USAGE.rst @@ -0,0 +1,19 @@ +To use this module, you need to: + +#. Create a new purchase order. +#. Assign its supplier. +#. Press *Recommended Products* button. +#. Set or adjust hinted quantities to order. +#. Press *Accept*. + +The wizard filters products those with supplier infos set for the current order +supplier. Then it computes how many times those products have been delivered to +customer locations, and finally it makes a simple estimation of how many +quantites would be necesary to order given the forcasted stock and the computed +demand. + +If you want to constrain results to only some categories, you can also select +them in the wizard. + +If you have multiple warehouses, you can also constrain the recommendations to +the deliveries of specific ones. diff --git a/purchase_order_product_recommendation/security/ir.model.access.csv b/purchase_order_product_recommendation/security/ir.model.access.csv new file mode 100644 index 00000000000..adc03964ef7 --- /dev/null +++ b/purchase_order_product_recommendation/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +purchase_order_recommendation_user,purchase_order_recommendation_user,model_purchase_order_recommendation,purchase.group_purchase_user,1,1,1,1 +purchase_order_recommendation_line_user,purchase_order_recommendation_line_user,model_purchase_order_recommendation_line,purchase.group_purchase_user,1,1,1,1 diff --git a/purchase_order_product_recommendation/static/description/icon.png b/purchase_order_product_recommendation/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_order_product_recommendation/static/description/icon.png differ diff --git a/purchase_order_product_recommendation/static/description/index.html b/purchase_order_product_recommendation/static/description/index.html new file mode 100644 index 00000000000..e270f9b2211 --- /dev/null +++ b/purchase_order_product_recommendation/static/description/index.html @@ -0,0 +1,453 @@ + + + + + + +Purchase Order Product Recommendation + + + +
+

Purchase Order Product Recommendation

+ + +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runbot

+

This module adds a recommended products wizard to current purchase order.

+

It is based on delivered products to customer locations in a given range of +dates, and allows the purchase manager to quickly know the most sold products +for the current supplier, which results in an easy to use hint to improve +the purchase workflow.

+

If you want a better mobile usability, the module is ready to use with the +‘web_widget_numeric_step’ module. Just install it and you will get a better +numeric input experience.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Create a new purchase order.
  2. +
  3. Assign its supplier.
  4. +
  5. Press Recommended Products button.
  6. +
  7. Set or adjust hinted quantities to order.
  8. +
  9. Press Accept.
  10. +
+

The wizard filters products those with supplier infos set for the current order +supplier. Then it computes how many times those products have been delivered to +customer locations, and finally it makes a simple estimation of how many +quantites would be necesary to order given the forcasted stock and the computed +demand.

+

If you want to constrain results to only some categories, you can also select +them in the wizard.

+

If you have multiple warehouses, you can also constrain the recommendations to +the deliveries of specific ones.

+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • David Vidal
    • +
    • Ernesto Tejeda
    • +
    • Manuel Calero
    • +
    • Pedro M. Baeza
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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/purchase-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/purchase_order_product_recommendation/tests/__init__.py b/purchase_order_product_recommendation/tests/__init__.py new file mode 100644 index 00000000000..52cc49c16ce --- /dev/null +++ b/purchase_order_product_recommendation/tests/__init__.py @@ -0,0 +1 @@ +from . import test_recommendation diff --git a/purchase_order_product_recommendation/tests/test_recommendation.py b/purchase_order_product_recommendation/tests/test_recommendation.py new file mode 100644 index 00000000000..ac6385610ba --- /dev/null +++ b/purchase_order_product_recommendation/tests/test_recommendation.py @@ -0,0 +1,321 @@ +# Copyright 2019 David Vidal +# Copyright 2020 Manuel Calero - Tecnativa +# Copyright 2020 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import fields +from odoo.tests.common import SavepointCase + + +class RecommendationCase(SavepointCase): + @classmethod + def setUpClass(cls): + super(RecommendationCase, cls).setUpClass() + cls.partner = cls.env["res.partner"].create({"name": "Mr. Odoo"}) + cls.category_obj = cls.env["product.category"] + cls.categ1 = cls.category_obj.create({"name": "Test Cat 1"}) + cls.categ2 = cls.category_obj.create({"name": "Test Cat 2"}) + cls.product_obj = cls.env["product.product"] + cls.prod_1 = cls.product_obj.create( + { + "default_code": "product-1", + "name": "Test Product 1", + "categ_id": cls.categ1.id, + "type": "product", + "seller_ids": [(0, 0, {"name": cls.partner.id, "price": 5})], + } + ) + cls.prod_2 = cls.product_obj.create( + { + "default_code": "product-2", + "name": "Test Product 2", + "categ_id": cls.categ2.id, + "type": "product", + "seller_ids": [(0, 0, {"name": cls.partner.id, "price": 10})], + } + ) + cls.prod_3 = cls.product_obj.create( + { + "default_code": "product-3", + "name": "Test Product 3", + "categ_id": cls.categ2.id, + "type": "product", + "seller_ids": [(0, 0, {"name": cls.partner.id, "price": 7})], + } + ) + # Warehouses + cls.wh1 = cls.env["stock.warehouse"].create( + {"name": "TEST WH1", "code": "TST1"} + ) + cls.wh2 = cls.env["stock.warehouse"].create( + {"name": "TEST WH2", "code": "TST2"} + ) + # Locations + location_obj = cls.env["stock.location"] + cls.supplier_loc = location_obj.create( + {"name": "Test supplier location", "usage": "supplier"} + ) + cls.customer_loc = location_obj.create( + {"name": "Test customer location", "usage": "customer"} + ) + # Create deliveries and receipts orders to have a history + cls.picking_obj = cls.env["stock.picking"] + cls.picking_1 = cls.picking_obj.create( + { + "location_id": cls.wh1.lot_stock_id.id, + "location_dest_id": cls.customer_loc.id, + "partner_id": cls.partner.id, + "picking_type_id": cls.wh1.out_type_id.id, + } + ) + cls.picking_2 = cls.picking_obj.create( + { + "location_id": cls.wh2.lot_stock_id.id, + "location_dest_id": cls.customer_loc.id, + "partner_id": cls.partner.id, + "picking_type_id": cls.wh2.out_type_id.id, + } + ) + cls.picking_3 = cls.picking_obj.create( + { + "location_id": cls.supplier_loc.id, + "location_dest_id": cls.wh1.lot_stock_id.id, + "partner_id": cls.partner.id, + "picking_type_id": cls.wh1.in_type_id.id, + } + ) + cls.move_line = cls.env["stock.move.line"] + cls.move_line |= cls.move_line.create( + { + "product_id": cls.prod_1.id, + "product_uom_id": cls.prod_1.uom_id.id, + "qty_done": 1, + "date": fields.Datetime.from_string("2018-01-11 15:05:00"), + "location_id": cls.wh1.lot_stock_id.id, + "location_dest_id": cls.customer_loc.id, + "picking_id": cls.picking_1.id, + } + ) + cls.move_line |= cls.move_line.create( + { + "product_id": cls.prod_2.id, + "product_uom_id": cls.prod_2.uom_id.id, + "qty_done": 38, + "date": fields.Datetime.from_string("2019-02-01 00:05:00"), + "location_id": cls.wh1.lot_stock_id.id, + "location_dest_id": cls.customer_loc.id, + "picking_id": cls.picking_1.id, + } + ) + cls.move_line |= cls.move_line.create( + { + "product_id": cls.prod_2.id, + "product_uom_id": cls.prod_2.uom_id.id, + "qty_done": 4, + "date": fields.Datetime.from_string("2019-02-01 00:05:00"), + "location_id": cls.wh2.lot_stock_id.id, + "location_dest_id": cls.customer_loc.id, + "picking_id": cls.picking_2.id, + } + ) + cls.move_line |= cls.move_line.create( + { + "product_id": cls.prod_3.id, + "product_uom_id": cls.prod_3.uom_id.id, + "qty_done": 13, + "date": fields.Datetime.from_string("2019-02-01 00:06:00"), + "location_id": cls.wh2.lot_stock_id.id, + "location_dest_id": cls.customer_loc.id, + "picking_id": cls.picking_2.id, + } + ) + cls.move_line |= cls.move_line.create( + { + "product_id": cls.prod_3.id, + "product_uom_id": cls.prod_3.uom_id.id, + "qty_done": 7, + "date": fields.Datetime.from_string("2019-02-01 00:00:00"), + "location_id": cls.supplier_loc.id, + "location_dest_id": cls.wh1.lot_stock_id.id, + "picking_id": cls.picking_3.id, + } + ) + cls.move_line.write({"state": "done"}) + # Total stock available for prod3 is 5 units split in two warehouses + quant_obj = cls.env["stock.quant"] + quant_obj.create( + { + "product_id": cls.prod_3.id, + "location_id": cls.wh1.lot_stock_id.id, + "quantity": 2.0, + } + ) + quant_obj.create( + { + "product_id": cls.prod_3.id, + "location_id": cls.wh2.lot_stock_id.id, + "quantity": 3.0, + } + ) + # Create a purchase order for the same customer + cls.new_po = cls.env["purchase.order"].create({"partner_id": cls.partner.id}) + + def wizard(self): + """Get a wizard.""" + wizard = ( + self.env["purchase.order.recommendation"] + .with_context(active_id=self.new_po.id, active_model="purchase.order") + .create({}) + ) + wizard._generate_recommendations() + return wizard + + +class RecommendationCaseTests(RecommendationCase): + def test_recommendations(self): + """Recommendations are OK.""" + wizard = self.wizard() + # Order came in from context + self.assertEqual(wizard.order_id, self.new_po) + # All our moves are in the past + self.assertFalse(wizard.line_ids) + wizard.date_begin = wizard.date_end = fields.Date.from_string("2019-02-01") + wizard._generate_recommendations() + line_prod_2 = wizard.line_ids.filtered(lambda x: x.product_id == self.prod_2) + self.assertEqual(line_prod_2.times_delivered, 2) + self.assertEqual(line_prod_2.units_delivered, 42) + self.assertEqual(line_prod_2.units_included, 42) + line_prod_3 = wizard.line_ids.filtered(lambda x: x.product_id == self.prod_3) + self.assertEqual(line_prod_3.times_delivered, 1) + self.assertEqual(line_prod_3.units_delivered, 13) + self.assertEqual(line_prod_3.units_included, 8) + self.assertEqual(line_prod_3.units_available, 5) + self.assertEqual(line_prod_3.units_virtual_available, 5) + # Only 1 product if limited as such + wizard.line_amount = 1 + wizard._generate_recommendations() + self.assertEqual(len(wizard.line_ids), 1) + + def test_recommendations_by_warehouse(self): + """We can split recommendations by delivery warehouse""" + wizard = self.wizard() + wizard.date_begin = wizard.date_end = fields.Date.from_string("2019-02-01") + # Just delivered to WH2 + wizard.warehouse_ids = self.wh2 + wizard._generate_recommendations() + line_prod_2 = wizard.line_ids.filtered(lambda x: x.product_id == self.prod_2) + self.assertEqual(line_prod_2.times_delivered, 1) + self.assertEqual(line_prod_2.units_delivered, 4) + self.assertEqual(line_prod_2.units_included, 4) + line_prod_3 = wizard.line_ids.filtered(lambda x: x.product_id == self.prod_3) + self.assertEqual(line_prod_3.times_delivered, 1) + self.assertEqual(line_prod_3.units_delivered, 13) + self.assertEqual(line_prod_3.units_included, 10) + self.assertEqual(line_prod_3.units_available, 3) + self.assertEqual(line_prod_3.units_virtual_available, 3) + # Just delivered to WH1 + wizard.warehouse_ids = self.wh1 + wizard._generate_recommendations() + self.assertEqual(len(wizard.line_ids), 2) + line_prod_2 = wizard.line_ids.filtered(lambda x: x.product_id == self.prod_2) + self.assertEqual(line_prod_2.times_delivered, 1) + self.assertEqual(line_prod_2.units_delivered, 38) + self.assertEqual(line_prod_2.units_included, 38) + line_prod_3 = wizard.line_ids.filtered(lambda x: x.product_id == self.prod_3) + self.assertEqual(line_prod_3.times_delivered, 0) + self.assertEqual(line_prod_3.units_delivered, 0) + self.assertEqual(line_prod_3.units_received, 7) + self.assertEqual(line_prod_3.units_included, 0) + self.assertEqual(line_prod_3.units_available, 2) + self.assertEqual(line_prod_3.units_virtual_available, 2) + # Delivered to both warehouses + wizard.warehouse_ids |= self.wh2 + wizard._generate_recommendations() + line_prod_2 = wizard.line_ids.filtered(lambda x: x.product_id == self.prod_2) + self.assertEqual(line_prod_2.times_delivered, 2) + self.assertEqual(line_prod_2.units_delivered, 42) + self.assertEqual(line_prod_2.units_included, 42) + line_prod_3 = wizard.line_ids.filtered(lambda x: x.product_id == self.prod_3) + self.assertEqual(line_prod_3.times_delivered, 1) + self.assertEqual(line_prod_3.units_delivered, 13) + self.assertEqual(line_prod_3.units_included, 8) + self.assertEqual(line_prod_3.units_available, 5) + self.assertEqual(line_prod_3.units_virtual_available, 5) + + def test_action_accept(self): + """Open wizard when there are PO Lines and click on Accept""" + po_line = self.env["purchase.order.line"].new( + {"sequence": 1, "order_id": self.new_po.id, "product_id": self.prod_2.id} + ) + po_line.onchange_product_id() + po_line.product_qty = 10 + po_line._onchange_quantity() + self.new_po.order_line = po_line + # Create wizard and set dates + wizard = self.wizard() + wizard.date_begin = wizard.date_end = fields.Date.from_string("2019-02-01") + wizard._generate_recommendations() + # After change dates, in the recommendation line corresponding to the + # self.prod_2 Units Included must be 10 + line_prod_2 = wizard.line_ids.filtered(lambda x: x.product_id == self.prod_2) + self.assertEqual(line_prod_2.units_included, 10) + line_prod_3 = wizard.line_ids.filtered(lambda x: x.product_id == self.prod_3) + self.assertEqual(line_prod_3.units_included, 8) + # Change Units Included amount to 20 and accept, then the product_qty + # of the PO Line corresponding to the self.prod_2 must change to 20 + line_prod_2.units_included = 20 + wizard.action_accept() + self.assertEqual(len(self.new_po.order_line), 2) + po_line_prod_2 = self.new_po.order_line.filtered( + lambda x: x.product_id == self.prod_2 + ) + self.assertEqual(po_line_prod_2.product_qty, 20) + po_line_prod_3 = self.new_po.order_line.filtered( + lambda x: x.product_id == self.prod_3 + ) + self.assertEqual(po_line_prod_3.product_qty, 8) + + def test_recommendations_by_category(self): + """We can split recommendations by delivery warehouse""" + wizard = self.wizard() + wizard.date_begin = wizard.date_end = fields.Date.from_string( + "2019-02-01" + ) # "2019-02-01" + # Just delivered from category 1 + wizard.product_category_ids = self.categ1 + wizard.show_all_partner_products = True + wizard._generate_recommendations() + # Just one line with products from category 1 + self.assertEqual(wizard.line_ids.product_id, self.prod_1) + # Just delivered from category 2 + wizard.product_category_ids = self.categ2 + wizard._generate_recommendations() + self.assertEqual(len(wizard.line_ids), 2) + # All categorys + wizard.product_category_ids += self.categ1 + wizard._generate_recommendations() + self.assertEqual(len(wizard.line_ids), 3) + # No category set + wizard.product_category_ids = False + wizard._generate_recommendations() + self.assertEqual(len(wizard.line_ids), 3) + # All products + wizard.show_all_products = True + wizard.line_amount = 0 + wizard._generate_recommendations() + purchase_products_number = self.product_obj.search_count( + [("purchase_ok", "!=", False)] + ) + self.assertEqual(len(wizard.line_ids), purchase_products_number) + + def test_recommendations_inactive_product(self): + """Recommendations are OK.""" + self.prod_2.active = False + wizard = self.wizard() + wizard.date_begin = wizard.date_end = fields.Date.from_string("2019-02-01") + wizard._generate_recommendations() + # The first recommendation line is the prod_3, as prod_2 is archived + self.assertEqual(wizard.line_ids[0].product_id, self.prod_3) + self.prod_3.purchase_ok = False + wizard._generate_recommendations() + # No recommendations as both elegible products are excluded + self.assertFalse(wizard.line_ids) diff --git a/purchase_order_product_recommendation/views/purchase_order_view.xml b/purchase_order_product_recommendation/views/purchase_order_view.xml new file mode 100644 index 00000000000..1d070119a8a --- /dev/null +++ b/purchase_order_product_recommendation/views/purchase_order_view.xml @@ -0,0 +1,18 @@ + + + + Recommended products button + purchase.order + + +
+
+
+
+
diff --git a/purchase_order_product_recommendation/wizards/__init__.py b/purchase_order_product_recommendation/wizards/__init__.py new file mode 100644 index 00000000000..f0ed6f15abb --- /dev/null +++ b/purchase_order_product_recommendation/wizards/__init__.py @@ -0,0 +1 @@ +from . import purchase_order_recommendation diff --git a/purchase_order_product_recommendation/wizards/purchase_order_recommendation.py b/purchase_order_product_recommendation/wizards/purchase_order_recommendation.py new file mode 100644 index 00000000000..287f96a5e83 --- /dev/null +++ b/purchase_order_product_recommendation/wizards/purchase_order_recommendation.py @@ -0,0 +1,395 @@ +# Copyright 2019 David Vidal +# Copyright 2020 Manuel Calero - Tecnativa +# Copyright 2020 Tecnativa - Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from datetime import datetime, timedelta + +from odoo import _, api, fields, models +from odoo.exceptions import UserError + + +class PurchaseOrderRecommendation(models.TransientModel): + _name = "purchase.order.recommendation" + _description = "Recommended products for current purchase order" + + order_id = fields.Many2one( + comodel_name="purchase.order", + string="Purchase Order", + default=lambda self: self._default_order_id(), + required=True, + readonly=True, + ondelete="cascade", + ) + date_begin = fields.Date( + default=fields.Date.context_today, + required=True, + help="Initial date to compute recommendations.", + ) + date_end = fields.Date( + default=fields.Date.context_today, + required=True, + help="Final date to compute recommendations.", + ) + line_ids = fields.One2many( + comodel_name="purchase.order.recommendation.line", + inverse_name="wizard_id", + string="Products", + ) + line_amount = fields.Integer( + string="Number of recommendations", + default=15, + required=True, + help="Stablish a limit on how many recommendations you want to get." + "Leave it as 0 to set no limit", + ) + show_all_partner_products = fields.Boolean( + string="Show all supplier products", + default=False, + help="Show all products with supplier infos for this supplier", + ) + show_all_products = fields.Boolean( + string="Show all purchasable products", + default=False, + help="Useful if a product hasn't been selled by the partner yet", + ) + product_category_ids = fields.Many2many( + comodel_name="product.category", + string="Product Categories", + help="Filter by product internal category", + ) + warehouse_ids = fields.Many2many( + comodel_name="stock.warehouse", + string="Warehouse", + help="Constrain search to an specific warehouse", + ) + warehouse_count = fields.Integer( + default=lambda self: len(self.env["stock.warehouse"].search([])), + ) + + @api.model + def _default_order_id(self): + if self.env.context.get("active_model", False) != "purchase.order": + raise UserError(_("This wizard is only valid for purchases")) + return self.env.context.get("active_id", False) + + def _get_total_days(self): + """Compute days between the initial and the end date""" + day = (self.date_end + timedelta(days=1) - self.date_begin).days + return day + + def _get_supplier_products(self): + """Common method to be used for field domain filters""" + supplierinfo_obj = self.env["product.supplierinfo"].with_context( + prefetch_fields=False + ) + partner = self.order_id.partner_id.commercial_partner_id + supplierinfos = supplierinfo_obj.search([("name", "=", partner.id)]) + product_tmpls = supplierinfos.mapped("product_tmpl_id").filtered( + lambda x: x.active and x.purchase_ok + ) + products = supplierinfos.mapped("product_id").filtered( + lambda x: x.active and x.purchase_ok + ) + products += product_tmpls.mapped("product_variant_ids") + return products + + def _get_products(self): + """Override to filter products show_all_partner_products is set""" + products = self._get_supplier_products() + # Filter products by category if set. + # It will apply to show_all_partner_products as well + if self.product_category_ids: + products = products.filtered( + lambda x: x.categ_id in self.product_category_ids + ) + return products + + def _get_move_line_domain(self, products, src, dst): + """Allows to easily extend the domain by third modules""" + combine = datetime.combine + # We can receive a context to be able to get different dates with + # the same wizard attributes, for example comparing periods + date_begin = self.env.context.get("period_date_begin", self.date_begin) + date_end = self.env.context.get("period_date_end", self.date_end) + domain = [ + ("product_id", "in", products.ids), + ("date", ">=", combine(date_begin, datetime.min.time())), + ("date", "<=", combine(date_end, datetime.max.time())), + ("location_id.usage", "=", src), + ("location_dest_id.usage", "=", dst), + ("state", "=", "done"), + ] + if self.warehouse_ids: + domain += [ + ( + "picking_id.picking_type_id.warehouse_id", + "in", + self.warehouse_ids.ids, + ) + ] + return domain + + def _get_all_products_domain(self): + """Override to add more product filters if show_all_products is set""" + domain = [ + ("purchase_ok", "=", True), + ] + if self.product_category_ids: + domain += [("categ_id", "in", self.product_category_ids.ids)] + return domain + + def _find_move_line(self, src="internal", dst="customer"): + """ "Returns a dictionary from the move lines in a range of dates + from and to given location types""" + products = self._get_products() + domain = self._get_move_line_domain(products, src, dst) + found_lines = self.env["stock.move.line"].read_group( + domain, ["product_id", "qty_done"], ["product_id"] + ) + # Manual ordering that circumvents ORM limitations + found_lines = sorted( + found_lines, + key=lambda res: ( + res["product_id_count"], + res["qty_done"], + ), + reverse=True, + ) + product_dict = {p.id: p for p in products} + found_lines = [ + { + "id": x["product_id"][0], + "product_id": product_dict[x["product_id"][0]], + "product_id_count": x["product_id_count"], + "qty_done": x["qty_done"], + } + for x in found_lines + ] + found_lines = {line["id"]: line for line in found_lines} + # Show every purchaseable product + if self.show_all_products: + products += self.env["product.product"].search( + self._get_all_products_domain() + ) + # Show all products with supplier infos belonging to a partner + if self.show_all_partner_products or self.show_all_products: + for product in products.filtered(lambda p: p.id not in found_lines.keys()): + found_lines.update({product.id: {"product_id": product}}) + return found_lines + + def _prepare_wizard_line_from_seller(self, vals, seller): + """Allow to add values coming from the selected seller, which will have + more priority than existing prepared values. + + :param vals: Existing wizard line dictionary vals. + :param seller: Selected seller for this line. + """ + self.ensure_one() + return { + "price_unit": seller.price, + } + + def _prepare_wizard_line(self, vals, order_line=False): + """Used to create the wizard line""" + self.ensure_one() + product_id = order_line and order_line.product_id or vals["product_id"] + if self.warehouse_ids: + units_available = sum( + product_id.with_context(warehouse=wh).qty_available + for wh in self.warehouse_ids.ids + ) + units_virtual_available = sum( + product_id.with_context(warehouse=wh).virtual_available + for wh in self.warehouse_ids.ids + ) + else: + units_available = product_id.qty_available + units_virtual_available = product_id.virtual_available + qty_to_order = abs( + min(0, units_virtual_available - vals.get("qty_delivered", 0)) + ) + vals["is_modified"] = bool(qty_to_order) + units_included = order_line and order_line.product_qty or qty_to_order + seller = product_id._select_seller( + partner_id=self.order_id.partner_id, + date=fields.Date.today(), + quantity=units_included, + uom_id=product_id.uom_po_id, + ) + res = { + "purchase_line_id": order_line and order_line.id, + "product_id": product_id.id, + "product_name": product_id.name, + "product_code": product_id.code, + "times_delivered": vals.get("times_delivered", 0), + "times_received": vals.get("times_received", 0), + "units_received": vals.get("qty_received", 0), + "units_available": units_available, + "units_virtual_available": units_virtual_available, + "units_avg_delivered": ( + vals.get("qty_delivered", 0) / self._get_total_days() + ), + "units_delivered": vals.get("qty_delivered", 0), + "units_included": units_included, + "is_modified": vals.get("is_modified", False), + } + res.update(self._prepare_wizard_line_from_seller(res, seller)) + return res + + @api.onchange( + "order_id", + "date_begin", + "date_end", + "line_amount", + "show_all_partner_products", + "show_all_products", + "product_category_ids", + "warehouse_ids", + ) + def _generate_recommendations(self): + """Generate lines according to received and delivered items""" + self.line_ids = False + # Get quantities received from suppliers + found_dict = self._find_move_line(src="supplier", dst="internal") + for product, line in found_dict.items(): + found_dict[product]["qty_received"] = line.get("qty_done", 0) + found_dict[product]["times_received"] = line.get("product_id_count", 0) + # Get quantities delivered to customers + found_delivered_dict = self._find_move_line(src="internal", dst="customer") + # Merge the two dicts + for product, line in found_delivered_dict.items(): + if not found_dict.get(product): + found_dict[product] = line + found_dict[product]["qty_delivered"] = line.get("qty_done", 0) + found_dict[product]["times_delivered"] = line.get("product_id_count", 0) + found_dict[product].update( + {k: v for k, v in line.items() if k not in found_dict[product].keys()} + ) + RecomendationLine = self.env["purchase.order.recommendation.line"] + existing_product_ids = [] + # Add products from purchase order lines + for order_line in self.order_id.order_line: + found_line = found_dict.get(order_line.product_id.id, {}) + new_line = RecomendationLine.new( + self._prepare_wizard_line(found_line, order_line) + ) + self.line_ids += new_line + existing_product_ids.append(order_line.product_id.id) + # Add those recommendations too + i = 0 + for product, line in found_dict.items(): + if product in existing_product_ids: + continue + new_line = RecomendationLine.new(self._prepare_wizard_line(line)) + self.line_ids += new_line + # Limit number of results. It has to be done here, as we need to + # populate all results first, for being able to select best matches + i += 1 + if i == self.line_amount: + break + self.line_ids = self.line_ids.sorted(key=lambda x: x.product_id.name) + + def action_accept(self): + """Propagate recommendations to purchase order.""" + po_lines = self.env["purchase.order.line"] + sequence = max(self.order_id.mapped("order_line.sequence") or [0]) + for wiz_line in self.line_ids.filtered("is_modified"): + # Use preexisting line if any + if wiz_line.purchase_line_id: + if wiz_line.units_included: + wiz_line.purchase_line_id.update(wiz_line._prepare_update_po_line()) + wiz_line.purchase_line_id._onchange_quantity() + else: + wiz_line.purchase_line_id.unlink() + continue + sequence += 1 + # Use a new in-memory line otherwise + po_line = po_lines.new(wiz_line._prepare_new_po_line(sequence)) + po_line.onchange_product_id() + po_line.product_qty = wiz_line.units_included + po_line._onchange_quantity() + po_lines |= po_line + self.order_id.order_line |= po_lines + + +class PurchaseOrderRecommendationLine(models.TransientModel): + _name = "purchase.order.recommendation.line" + _description = "Recommended product for current purchase order" + _order = "id" + + currency_id = fields.Many2one( + related="product_id.currency_id", + readonly=True, + ) + partner_id = fields.Many2one( + related="wizard_id.order_id.partner_id", + readonly=True, + ) + product_id = fields.Many2one( + comodel_name="product.product", + string="Product", + ) + product_name = fields.Char() + product_code = fields.Char(string="Product reference") + price_unit = fields.Monetary( + readonly=True, + ) + times_delivered = fields.Integer( + readonly=True, + ) + times_received = fields.Integer( + readonly=True, + ) + units_received = fields.Float( + readonly=True, + ) + units_delivered = fields.Float( + readonly=True, + ) + units_avg_delivered = fields.Float( + digits="Product Unit of Measure", + readonly=True, + ) + units_available = fields.Float( + readonly=True, + ) + units_virtual_available = fields.Float( + readonly=True, + ) + units_included = fields.Float() + wizard_id = fields.Many2one( + comodel_name="purchase.order.recommendation", + string="Wizard", + ondelete="cascade", + required=True, + readonly=True, + ) + purchase_line_id = fields.Many2one( + comodel_name="purchase.order.line", + ) + is_modified = fields.Boolean() + + @api.onchange("units_included") + def _onchange_units_included(self): + self.is_modified = bool(self.purchase_line_id or self.units_included) + self.price_unit = self.product_id._select_seller( + partner_id=self.partner_id, + date=fields.Date.today(), + quantity=self.units_included, + uom_id=self.product_id.uom_po_id, + ).price + + def _prepare_update_po_line(self): + """So we can extend PO update""" + return { + "product_qty": self.units_included, + } + + def _prepare_new_po_line(self, sequence): + """So we can extend PO create""" + return { + "order_id": self.wizard_id.order_id.id, + "product_id": self.product_id.id, + "sequence": sequence, + } diff --git a/purchase_order_product_recommendation/wizards/purchase_order_recommendation_view.xml b/purchase_order_product_recommendation/wizards/purchase_order_recommendation_view.xml new file mode 100644 index 00000000000..c7723ee7a61 --- /dev/null +++ b/purchase_order_product_recommendation/wizards/purchase_order_recommendation_view.xml @@ -0,0 +1,107 @@ + + + + Recommended Products for this Customer + purchase.order.recommendation + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ + Recommended Products for this Customer + purchase.order.recommendation + form + form + new + +
diff --git a/setup/purchase_order_product_recommendation/odoo/addons/purchase_order_product_recommendation b/setup/purchase_order_product_recommendation/odoo/addons/purchase_order_product_recommendation new file mode 120000 index 00000000000..78bf0ce5a83 --- /dev/null +++ b/setup/purchase_order_product_recommendation/odoo/addons/purchase_order_product_recommendation @@ -0,0 +1 @@ +../../../../purchase_order_product_recommendation \ No newline at end of file diff --git a/setup/purchase_order_product_recommendation/setup.py b/setup/purchase_order_product_recommendation/setup.py new file mode 100644 index 00000000000..28c57bb6403 --- /dev/null +++ b/setup/purchase_order_product_recommendation/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)