diff --git a/base_product_mass_addition/README.rst b/base_product_mass_addition/README.rst new file mode 100644 index 000000000000..3ad79f7d37f1 --- /dev/null +++ b/base_product_mass_addition/README.rst @@ -0,0 +1,115 @@ +========================== +Base Product Mass Addition +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:0ee726c2fe9ffdca69a717125257afb030860b637273b0e3ec6ffb04621cd4bf + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fproduct--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/16.0/base_product_mass_addition + :alt: OCA/product-attribute +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/product-attribute-16-0/product-attribute-16-0-base_product_mass_addition + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/product-attribute&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is abstract and can't be used as is. + +It provides functions in order to show a product grid from another model. +You can then add products and quantities in batch to the model you are working with. + +It is useful when you don't want to add every product line possible to your object. +From the product grid you only have to set the quantity for each product. + +Example implementations: + + - ``sale_quick`` (https://github.com/OCA/sale-workflow) + - ``purchase_quick`` (https://github.com/OCA/purchase-workflow) + - ``stock_picking_quick`` (https://github.com/OCA/stock-logistics-workflow) + +**Table of contents** + +.. contents:: + :local: + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion +* GRAP + +Contributors +~~~~~~~~~~~~ + +* Akretion + + * Sébastien BEAU + * Mourad EL HADJ MIMOUNE + * Pierrick Brun + * David Béal + * Kevin Khao + +* `Camptocamp `_ + + * Iván Todorovich + +* `Sygel `_: + + * Ángel García de la Chica Herrera + +* GRAP + + * Sylvain LE GAL (https://twitter.com/legalsylvain) + +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. + +.. |maintainer-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px + :target: https://github.com/legalsylvain + :alt: legalsylvain + +Current `maintainer `__: + +|maintainer-legalsylvain| + +This module is part of the `OCA/product-attribute `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_product_mass_addition/__init__.py b/base_product_mass_addition/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/base_product_mass_addition/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/base_product_mass_addition/__manifest__.py b/base_product_mass_addition/__manifest__.py new file mode 100644 index 000000000000..47e0d97928cb --- /dev/null +++ b/base_product_mass_addition/__manifest__.py @@ -0,0 +1,16 @@ +# © 2019 Today Akretion +# @author Pierrick Brun +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Base Product Mass Addition", + "version": "16.0.1.0.0", + "author": "Akretion, GRAP, Odoo Community Association (OCA)", + "maintainers": ["legalsylvain"], + "website": "https://github.com/OCA/product-attribute", + "license": "AGPL-3", + "category": "Product", + "depends": ["stock", "onchange_helper"], + "data": ["views/product_view.xml"], + "installable": True, +} diff --git a/base_product_mass_addition/i18n/base_product_mass_addition.pot b/base_product_mass_addition/i18n/base_product_mass_addition.pot new file mode 100644 index 000000000000..d0bfda19bb3b --- /dev/null +++ b/base_product_mass_addition/i18n/base_product_mass_addition.pot @@ -0,0 +1,70 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_product_mass_addition +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.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: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__quick_uom_category_id +msgid "Category" +msgstr "" + +#. module: base_product_mass_addition +#: model:ir.model.fields,help:base_product_mass_addition.field_product_product__quick_uom_category_id +msgid "" +"Conversion between Units of Measure can only occur if they belong to the " +"same category. The conversion will be made based on the ratios." +msgstr "" + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_search_form_view +msgid "Filter products in current parent" +msgstr "" + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_search_form_view +msgid "In current parent" +msgstr "" + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_product_tree_view +msgid "Open" +msgstr "" + +#. module: base_product_mass_addition +#: model:ir.model,name:base_product_mass_addition.model_product_product +msgid "Product" +msgstr "" + +#. module: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__qty_to_process +msgid "Qty To Process" +msgstr "" + +#. module: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__quick_uom_id +msgid "Quick Uom" +msgstr "" + +#. module: base_product_mass_addition +#: model:ir.model.fields,help:base_product_mass_addition.field_product_product__qty_to_process +msgid "" +"Set this quantity to create a new line for this product or update the " +"existing one." +msgstr "" + +#. module: base_product_mass_addition +#: model:ir.model,name:base_product_mass_addition.model_product_mass_addition +msgid "" +"inherit this to add a mass product addition function to " +"your model" +msgstr "" diff --git a/base_product_mass_addition/i18n/es.po b/base_product_mass_addition/i18n/es.po new file mode 100644 index 000000000000..1d127914f13c --- /dev/null +++ b/base_product_mass_addition/i18n/es.po @@ -0,0 +1,79 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_product_mass_addition +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-04-12 16:32+0000\n" +"Last-Translator: luis-ron \n" +"Language-Team: none\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.14.1\n" + +#. module: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__quick_uom_category_id +msgid "Category" +msgstr "Categoría" + +#. module: base_product_mass_addition +#: model:ir.model.fields,help:base_product_mass_addition.field_product_product__quick_uom_category_id +msgid "" +"Conversion between Units of Measure can only occur if they belong to the " +"same category. The conversion will be made based on the ratios." +msgstr "" +"La conversión entre Unidades de Medida sólo puede ocurrir si pertenecen a la " +"misma categoría. La conversión se realizará en función de los ratios." + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_search_form_view +msgid "Filter products in current parent" +msgstr "Filtrar productos en padre actual" + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_search_form_view +msgid "In current parent" +msgstr "En padre actual" + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_product_tree_view +msgid "Open" +msgstr "Abrir" + +#. module: base_product_mass_addition +#: model:ir.model,name:base_product_mass_addition.model_product_product +msgid "Product" +msgstr "Producto" + +#. module: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__qty_to_process +msgid "Qty To Process" +msgstr "Cantidad a procesar" + +#. module: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__quick_uom_id +msgid "Quick Uom" +msgstr "UdM rápida" + +#. module: base_product_mass_addition +#: model:ir.model.fields,help:base_product_mass_addition.field_product_product__qty_to_process +msgid "" +"Set this quantity to create a new line for this product or update the " +"existing one." +msgstr "" +"Establezca esta cantidad para crear una nueva línea para este producto o " +"actualizar la existente." + +#. module: base_product_mass_addition +#: model:ir.model,name:base_product_mass_addition.model_product_mass_addition +msgid "" +"inherit this to add a mass product addition function to " +"your model" +msgstr "" +"hereda esto para añadir una función de adición de producto " +"masiva a tu modelo" diff --git a/base_product_mass_addition/i18n/fr.po b/base_product_mass_addition/i18n/fr.po new file mode 100644 index 000000000000..e2810ed667f2 --- /dev/null +++ b/base_product_mass_addition/i18n/fr.po @@ -0,0 +1,85 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_product_mass_addition +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-11-30 16:36+0000\n" +"Last-Translator: Kévin Roche \n" +"Language-Team: none\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__quick_uom_category_id +msgid "Category" +msgstr "Catégorie" + +#. module: base_product_mass_addition +#: model:ir.model.fields,help:base_product_mass_addition.field_product_product__quick_uom_category_id +msgid "" +"Conversion between Units of Measure can only occur if they belong to the " +"same category. The conversion will be made based on the ratios." +msgstr "" +"Seule une conversion entre Unités de Mesure de la même catégorie est " +"possible. La conversion se base sur les ratios." + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_search_form_view +msgid "Filter products in current parent" +msgstr "" + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_search_form_view +msgid "In current parent" +msgstr "" + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_product_tree_view +msgid "Open" +msgstr "Ouvrir" + +#. module: base_product_mass_addition +#: model:ir.model,name:base_product_mass_addition.model_product_product +msgid "Product" +msgstr "Produit" + +#. module: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__qty_to_process +msgid "Qty To Process" +msgstr "Qté à Traiter" + +#. module: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__quick_uom_id +msgid "Quick Uom" +msgstr "UdM rapide" + +#. module: base_product_mass_addition +#: model:ir.model.fields,help:base_product_mass_addition.field_product_product__qty_to_process +msgid "" +"Set this quantity to create a new line for this product or update the " +"existing one." +msgstr "" +"Une quantité est nécessaire pour créer ou modifier une ligne de commande." + +#. module: base_product_mass_addition +#: model:ir.model,name:base_product_mass_addition.model_product_mass_addition +msgid "" +"inherit this to add a mass product addition function to " +"your model" +msgstr "" + +#~ msgid "Display Name" +#~ msgstr "Nom" + +#~ msgid "Last Modified on" +#~ msgstr "Dernière Modification" + +#~ msgid "Products" +#~ msgstr "Produits" diff --git a/base_product_mass_addition/i18n/it.po b/base_product_mass_addition/i18n/it.po new file mode 100644 index 000000000000..9520c5b69e1e --- /dev/null +++ b/base_product_mass_addition/i18n/it.po @@ -0,0 +1,80 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_product_mass_addition +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-01 14:37+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__quick_uom_category_id +msgid "Category" +msgstr "Categoria" + +#. module: base_product_mass_addition +#: model:ir.model.fields,help:base_product_mass_addition.field_product_product__quick_uom_category_id +msgid "" +"Conversion between Units of Measure can only occur if they belong to the " +"same category. The conversion will be made based on the ratios." +msgstr "" +"Le conversioni tra unità di misura possono avvenire solo se appartengono " +"alla stessa categoria. La conversione verrà effettuata in base alle " +"proporzioni." + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_search_form_view +msgid "Filter products in current parent" +msgstr "Filtra prodotti con padre attuale" + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_search_form_view +msgid "In current parent" +msgstr "Nel padre attuale" + +#. module: base_product_mass_addition +#: model_terms:ir.ui.view,arch_db:base_product_mass_addition.product_product_tree_view +msgid "Open" +msgstr "Apri" + +#. module: base_product_mass_addition +#: model:ir.model,name:base_product_mass_addition.model_product_product +msgid "Product" +msgstr "Prodotto" + +#. module: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__qty_to_process +msgid "Qty To Process" +msgstr "Q.tà da gestire" + +#. module: base_product_mass_addition +#: model:ir.model.fields,field_description:base_product_mass_addition.field_product_product__quick_uom_id +msgid "Quick Uom" +msgstr "UdM rapida" + +#. module: base_product_mass_addition +#: model:ir.model.fields,help:base_product_mass_addition.field_product_product__qty_to_process +msgid "" +"Set this quantity to create a new line for this product or update the " +"existing one." +msgstr "" +"Imposta questa quantità per creare una nuova riga per questo prodotto o " +"aggiornare quella esistente." + +#. module: base_product_mass_addition +#: model:ir.model,name:base_product_mass_addition.model_product_mass_addition +msgid "" +"inherit this to add a mass product addition function to " +"your model" +msgstr "" +"eredita questo per aggiungere la funzione aggiunta massiva " +"prodotti al tuo modello" diff --git a/base_product_mass_addition/models/__init__.py b/base_product_mass_addition/models/__init__.py new file mode 100644 index 000000000000..35949d169681 --- /dev/null +++ b/base_product_mass_addition/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_product +from . import product_mass_addition diff --git a/base_product_mass_addition/models/product_mass_addition.py b/base_product_mass_addition/models/product_mass_addition.py new file mode 100644 index 000000000000..eaf2e332589d --- /dev/null +++ b/base_product_mass_addition/models/product_mass_addition.py @@ -0,0 +1,73 @@ +# © 2019 Today Akretion +# @author Pierrick Brun +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +import logging + +from odoo import api, models + +_logger = logging.getLogger(__name__) + + +class ProductMassAddition(models.AbstractModel): + _name = "product.mass.addition" + _description = "inherit this to add a mass product addition function\ + to your model" + + @api.model + def _common_action_keys(self): + """Call it in your own child module""" + return { + "type": "ir.actions.act_window", + "res_model": "product.product", + "target": "current", + "context": { + "parent_id": self.id, + "parent_model": self._name, + }, + "view_mode": "tree", + } + + def _prepare_quick_line(self, product): + res = self._get_quick_line_qty_vals(product) + res.update({"product_id": product.id}) + return res + + def _get_quick_line(self, product): + raise NotImplementedError + + def _add_quick_line(self, product, lines_key=""): + if not lines_key: + raise NotImplementedError + vals = self._prepare_quick_line(product) + vals = self._complete_quick_line_vals(vals) + self.write({lines_key: [(0, 0, vals)]}) + + def _update_quick_line(self, product, line): + if product.qty_to_process: + # apply the on change to update price unit if depends on qty + vals = self._get_quick_line_qty_vals(product) + vals["id"] = line.id + vals = self._complete_quick_line_vals(vals) + line.write(vals) + else: + line.unlink() + + def _get_quick_line_qty_vals(self, product): + raise NotImplementedError + + def _complete_quick_line_vals(self, vals, lines_key=""): + if not lines_key: + raise NotImplementedError + init_keys = ["product_id"] + update_vals = {key: val for key, val in vals.items() if key not in init_keys} + lines = getattr(self, lines_key) + if "id" in vals: + line = lines.filtered(lambda x: x.id == vals["id"]) + return line.play_onchanges(update_vals, list(update_vals.keys())) + else: + line = lines + if len(lines) > 1: + line = lines[0] + return line.play_onchanges(vals, list(vals.keys())) diff --git a/base_product_mass_addition/models/product_product.py b/base_product_mass_addition/models/product_product.py new file mode 100644 index 000000000000..4e03c6050416 --- /dev/null +++ b/base_product_mass_addition/models/product_product.py @@ -0,0 +1,101 @@ +# © 2014 Today Akretion +# @author Sébastien BEAU +# @author Mourad EL HADJ MIMOUNE +# @author Pierrick Brun +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from odoo import fields, models +from odoo.models import LOG_ACCESS_COLUMNS + + +class ProductProduct(models.Model): + _inherit = "product.product" + + qty_to_process = fields.Float( + compute="_compute_process_qty", + inverse="_inverse_set_process_qty", + help="Set this quantity to create a new line " + "for this product or update the existing one.", + ) + quick_uom_category_id = fields.Many2one( + "uom.category", compute="_compute_quick_uom_info" + ) + quick_uom_id = fields.Many2one( + "uom.uom", + domain="[('category_id', '=', quick_uom_category_id)]", + compute="_compute_quick_uom_info", + inverse="_inverse_set_process_qty", + ) + + def _inverse_set_process_qty(self): + parent = self.pma_parent + if parent: + for product in self: + quick_line = parent._get_quick_line(product) + if quick_line: + parent._update_quick_line(product, quick_line) + else: + parent._add_quick_line(product, quick_line._name) + + def modified(self, fnames, create=False, before=False): + # OVERRIDE to supress LOG_ACCESS_COLUMNS writes if we're only writing on quick + # magic fields, as they could lead to concurrency issues. + # + # Moreover, from a functional perspective, these magic fields aren't really + # modifying the product's data so it doesn't make sense to update its metadata. + # + # Basically, if all we're modifying are quick magic fields, and we don't have + # any other column to flush besides the LOG_ACCESS_COLUMNS, clear it. + quick_fnames = ("qty_to_process", "quick_uom_id") + if ( + self + and fnames + and any(quick_fname in fnames for quick_fname in quick_fnames) + ): + if all( + field.name in LOG_ACCESS_COLUMNS + for field in self.env.cache.get_dirty_fields() + ): + for fname in LOG_ACCESS_COLUMNS: + self.env.cache.clear_dirty_field(self._fields[fname]) + return super().modified(fnames, create=create, before=before) + + @property + def pma_parent(self): + # shorthand for product_mass_addition parent + parent_model = self.env.context.get("parent_model") + parent_id = self.env.context.get("parent_id") + if parent_model and parent_id: + return self.env[parent_model].browse(parent_id) + + def _default_quick_uom_id(self): + raise NotImplementedError + + def _compute_quick_uom_info(self): + parent = self.pma_parent + if not parent: + return + + for product in self: + quick_line = parent._get_quick_line(product) + if quick_line: + product.quick_uom_id = quick_line.product_uom + else: + product.quick_uom_id = product._default_quick_uom_id() + product.quick_uom_category_id = product.quick_uom_id.category_id + + def _compute_process_qty(self): + if not self.pma_parent: + return + + def button_quick_open_product(self): + self.ensure_one() + return { + "name": self.display_name, + "type": "ir.actions.act_window", + "res_model": self._name, + "view_mode": "form", + "res_id": self.id, + "target": "current", + } diff --git a/base_product_mass_addition/readme/CONTRIBUTORS.rst b/base_product_mass_addition/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..3fc1b99207d0 --- /dev/null +++ b/base_product_mass_addition/readme/CONTRIBUTORS.rst @@ -0,0 +1,19 @@ +* Akretion + + * Sébastien BEAU + * Mourad EL HADJ MIMOUNE + * Pierrick Brun + * David Béal + * Kevin Khao + +* `Camptocamp `_ + + * Iván Todorovich + +* `Sygel `_: + + * Ángel García de la Chica Herrera + +* GRAP + + * Sylvain LE GAL (https://twitter.com/legalsylvain) \ No newline at end of file diff --git a/base_product_mass_addition/readme/DESCRIPTION.rst b/base_product_mass_addition/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..3e1e2dfa80ea --- /dev/null +++ b/base_product_mass_addition/readme/DESCRIPTION.rst @@ -0,0 +1,13 @@ +This module is abstract and can't be used as is. + +It provides functions in order to show a product grid from another model. +You can then add products and quantities in batch to the model you are working with. + +It is useful when you don't want to add every product line possible to your object. +From the product grid you only have to set the quantity for each product. + +Example implementations: + + - ``sale_quick`` (https://github.com/OCA/sale-workflow) + - ``purchase_quick`` (https://github.com/OCA/purchase-workflow) + - ``stock_picking_quick`` (https://github.com/OCA/stock-logistics-workflow) diff --git a/base_product_mass_addition/static/description/icon.png b/base_product_mass_addition/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/base_product_mass_addition/static/description/icon.png differ diff --git a/base_product_mass_addition/static/description/index.html b/base_product_mass_addition/static/description/index.html new file mode 100644 index 000000000000..e9c6e9e812e7 --- /dev/null +++ b/base_product_mass_addition/static/description/index.html @@ -0,0 +1,455 @@ + + + + + + +Base Product Mass Addition + + + +
+

Base Product Mass Addition

+ + +

Beta License: AGPL-3 OCA/product-attribute Translate me on Weblate Try me on Runboat

+

This module is abstract and can’t be used as is.

+

It provides functions in order to show a product grid from another model. +You can then add products and quantities in batch to the model you are working with.

+

It is useful when you don’t want to add every product line possible to your object. +From the product grid you only have to set the quantity for each product.

+

Example implementations:

+
+ +
+

Table of contents

+ +
+

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 to smash it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
  • GRAP
  • +
+
+
+

Contributors

+ +
+
+

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.

+

Current maintainer:

+

legalsylvain

+

This module is part of the OCA/product-attribute project on GitHub.

+

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

+
+
+
+ + diff --git a/base_product_mass_addition/tests/__init__.py b/base_product_mass_addition/tests/__init__.py new file mode 100644 index 000000000000..18cd3d5edf61 --- /dev/null +++ b/base_product_mass_addition/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_mass_addition diff --git a/base_product_mass_addition/tests/models/order.py b/base_product_mass_addition/tests/models/order.py new file mode 100644 index 000000000000..b8d940213b0a --- /dev/null +++ b/base_product_mass_addition/tests/models/order.py @@ -0,0 +1,36 @@ +# Copyright 2022 Camptocamp SA (https://www.camptocamp.com). +# @author Iván Todorovich +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ModelOrder(models.Model): + _name = "model.order" + _description = "Test Model Order (base_product_mass_addition)" + _inherit = "product.mass.addition" + + line_ids = fields.One2many("model.order.line", "order_id") + + def _get_quick_line(self, product): + return fields.first( + self.line_ids.filtered(lambda rec: rec.product_id == product) + ) + + def _get_quick_line_qty_vals(self, product): + return {"product_qty": product.qty_to_process} + + def _complete_quick_line_vals(self, vals, lines_key=""): + return super()._complete_quick_line_vals(vals, lines_key="line_ids") + + def _add_quick_line(self, product, lines_key=""): + return super()._add_quick_line(product, lines_key="line_ids") + + +class ModelOrderLine(models.Model): + _name = "model.order.line" + _description = "Test Model Order Line (base_product_mass_addition)" + + order_id = fields.Many2one("model.order") + product_id = fields.Many2one("product.product") + product_qty = fields.Float() diff --git a/base_product_mass_addition/tests/test_product_mass_addition.py b/base_product_mass_addition/tests/test_product_mass_addition.py new file mode 100644 index 000000000000..163245b0eadf --- /dev/null +++ b/base_product_mass_addition/tests/test_product_mass_addition.py @@ -0,0 +1,91 @@ +# Copyright 2022 Camptocamp SA (https://www.camptocamp.com). +# @author Iván Todorovich +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import datetime + +from odoo_test_helper import FakeModelLoader + +from odoo.tests.common import TransactionCase + + +def now(): + return datetime.now() + + +class TestProductMassAddition(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Setup Fake Models + cls.loader = FakeModelLoader(cls.env, cls.__module__) + cls.loader.backup_registry() + from .models.order import ModelOrder, ModelOrderLine + + cls.loader.update_registry( + ( + ModelOrder, + ModelOrderLine, + ) + ) + + # Setup data + cls.order = cls.env["model.order"].create({}) + cls.quick_ctx = dict(parent_model=cls.order._name, parent_id=cls.order.id) + cls.product = cls.env.ref("product.product_product_8").with_context( + **cls.quick_ctx + ) + + def test_quick_line_add(self): + """Test quick lines are added, updated and removed""" + # Case 1: Create new line + self.assertFalse(self.order.line_ids) + self.product.qty_to_process = 5.0 + self.assertEqual(len(self.order.line_ids), 1, "A new line should be created") + self.assertAlmostEqual(self.order.line_ids.product_qty, 5.0) + # Case 2: Update existing line + self.product.qty_to_process = 2.0 + self.assertEqual(len(self.order.line_ids), 1) + self.assertAlmostEqual(self.order.line_ids.product_qty, 2.0) + # Case 3: Set to 0 should remove the line + self.product.qty_to_process = 0.0 + self.assertFalse(self.order.line_ids) + + def test_quick_should_not_write_on_product(self): + """Using quick magic fields shouldn't write on product's metadata""" + # Monkey patch the now method for our testing purpose + # other the now method of cr would return the date of the Transaction + # which is unique for the whole test + self.env.cr.now = now + base_date = self.product.write_date + # Case 1: Updating qty_to_process shouldn't write on products + self.product.qty_to_process = 4.0 + self.env["product.product"].flush_model() + self.assertEqual(base_date, self.product.write_date) + after_update_date = self.product.write_date + # Case 2: Updating quick_uom_id shouldn't write on products + self.product.quick_uom_id = self.env.ref("uom.product_uom_categ_unit").uom_ids[ + 1 + ] + self.env["product.product"].flush_model() + self.assertEqual(after_update_date, self.product.write_date) + + def test_quick_should_write_on_product(self): + """Updating fields that are not magic fields should update + product metadata""" + # Monkey patch the now method for our testing purpose + # other the now method of cr would return the date of the Transaction + # which is unique for the whole test + self.env.cr.now = now + base_date = self.product.write_date + # Case 1: Updating name field should write on product's metadata + self.product.name = "Testing" + self.env["product.product"].flush_model() + self.assertNotEqual(base_date, self.product.write_date) + after_update_date = self.product.write_date + # Case 2: Updating qty_to_process and name before flush should + # write on product's metadata + self.product.qty_to_process = 2.0 + self.product.name = "Testing 2" + self.env["product.product"].flush_model() + self.assertNotEqual(after_update_date, self.product.write_date) diff --git a/base_product_mass_addition/views/product_view.xml b/base_product_mass_addition/views/product_view.xml new file mode 100644 index 000000000000..4e8739fddcb7 --- /dev/null +++ b/base_product_mass_addition/views/product_view.xml @@ -0,0 +1,37 @@ + + + + + product.product + + + + + + + + + +