diff --git a/base_product_mass_addition/README.rst b/base_product_mass_addition/README.rst new file mode 100644 index 00000000000..cee72cb1afe --- /dev/null +++ b/base_product_mass_addition/README.rst @@ -0,0 +1,98 @@ +========================== +Base Product Mass Addition +========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fproduct--attribute-lightgray.png?logo=github + :target: https://github.com/OCA/product-attribute/tree/12.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-12-0/product-attribute-12-0-base_product_mass_addition + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/135/12.0 + :alt: Try me on Runbot + +|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: + - purchase_quick + - stock_picking_quick + +**Table of contents** + +.. contents:: + :local: + +Known issues / Roadmap +====================== + +The module uses Form emulation from backend. +Once onchange_helper is stabilized, we should switch to it +because it is more robust and has better perfs. + +Also adding new implementations would be great: +on sale.order or on stock.picking.batch for instance. + +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 +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +Akretion + +* Sébastien BEAU +* Mourad EL HADJ MIMOUNE +* Pierrick Brun +* David Béal + +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/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 00000000000..0650744f6bc --- /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 00000000000..b98600549e6 --- /dev/null +++ b/base_product_mass_addition/__manifest__.py @@ -0,0 +1,19 @@ +# © 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': '12.0.1.0.0', + 'author': 'Akretion, Odoo Community Association (OCA)', + 'website': 'https://github.com/OCA/product-attribute', + 'license': 'AGPL-3', + 'category': 'Product', + 'depends': [ + 'stock', + ], + '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 00000000000..2a7fadbbb6c --- /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 12.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_mass_addition__display_name +msgid "Display Name" +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:ir.model.fields,field_description:base_product_mass_addition.field_product_mass_addition__id +msgid "ID" +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:ir.model.fields,field_description:base_product_mass_addition.field_product_mass_addition____last_update +msgid "Last Modified on" +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_terms:ir.ui.view,arch_db:base_product_mass_addition.product_product_tree_view +msgid "Products" +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,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/models/__init__.py b/base_product_mass_addition/models/__init__.py new file mode 100644 index 00000000000..35949d16968 --- /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 00000000000..9e8bd91d1f3 --- /dev/null +++ b/base_product_mass_addition/models/product_mass_addition.py @@ -0,0 +1,79 @@ +# © 2019 Today Akretion +# @author Pierrick Brun +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +from odoo import models, api +from odoo.tests.common import Form + + +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 + form_parent = Form(self) + form_line = False + if vals.get('id'): + for index, line in enumerate(self[lines_key]): + if line.id == vals.get('id'): + form_line = getattr(form_parent, lines_key).edit(index) + del vals['id'] + break + init_keys = ['product_id'] + init_vals = [(key, val) for key, val in vals.items() + if key in init_keys] + if not form_line: + form_line = getattr(form_parent, lines_key).new() + form_line._values.update(init_vals) + form_line._perform_onchange(init_keys) + + update_keys = [key for key in vals.keys() if key not in init_keys] + update_vals = [(key, val) for key, val in vals.items() + if key not in init_keys] + form_line._values.update(update_vals) + form_line._perform_onchange(update_keys) + return form_line._values 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 00000000000..a08066cf94c --- /dev/null +++ b/base_product_mass_addition/models/product_product.py @@ -0,0 +1,47 @@ +# © 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 api, fields, models + + +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." + ) + + def _inverse_set_process_qty(self): + parent_model = self.env.context.get('parent_model') + parent_id = self.env.context.get('parent_id') + if parent_model: + parent = self.env[parent_model].browse(parent_id) + 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 _compute_process_qty(self): + if not self.env.context.get('parent_id'): + return + + @api.multi + 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 00000000000..51a402da1ff --- /dev/null +++ b/base_product_mass_addition/readme/CONTRIBUTORS.rst @@ -0,0 +1,6 @@ +Akretion + +* Sébastien BEAU +* Mourad EL HADJ MIMOUNE +* Pierrick Brun +* David Béal diff --git a/base_product_mass_addition/readme/DESCRIPTION.rst b/base_product_mass_addition/readme/DESCRIPTION.rst new file mode 100644 index 00000000000..82b9d5c9cdb --- /dev/null +++ b/base_product_mass_addition/readme/DESCRIPTION.rst @@ -0,0 +1,11 @@ +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: + - purchase_quick + - stock_picking_quick diff --git a/base_product_mass_addition/readme/ROADMAP.rst b/base_product_mass_addition/readme/ROADMAP.rst new file mode 100644 index 00000000000..1d0524259f7 --- /dev/null +++ b/base_product_mass_addition/readme/ROADMAP.rst @@ -0,0 +1,6 @@ +The module uses Form emulation from backend. +Once onchange_helper is stabilized, we should switch to it +because it is more robust and has better perfs. + +Also adding new implementations would be great: +on sale.order or on stock.picking.batch for instance. diff --git a/base_product_mass_addition/static/description/filter.png b/base_product_mass_addition/static/description/filter.png new file mode 100644 index 00000000000..12342418cb0 Binary files /dev/null and b/base_product_mass_addition/static/description/filter.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 00000000000..ebe6493369f --- /dev/null +++ b/base_product_mass_addition/static/description/index.html @@ -0,0 +1,444 @@ + + + + + + +Base Product Mass Addition + + + +
+

Base Product Mass Addition

+ + +

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

+

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:
+
    +
  • purchase_quick
  • +
  • stock_picking_quick
  • +
+
+
+

Table of contents

+ +
+

Known issues / Roadmap

+

The module uses Form emulation from backend. +Once onchange_helper is stabilized, we should switch to it +because it is more robust and has better perfs.

+

Also adding new implementations would be great: +on sale.order or on stock.picking.batch for instance.

+
+
+

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

+
    +
  • Akretion
  • +
+
+
+

Contributors

+

Akretion

+ +
+
+

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/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/static/description/po-product.png b/base_product_mass_addition/static/description/po-product.png new file mode 100644 index 00000000000..14a3d1c50fc Binary files /dev/null and b/base_product_mass_addition/static/description/po-product.png differ diff --git a/base_product_mass_addition/static/description/po.png b/base_product_mass_addition/static/description/po.png new file mode 100644 index 00000000000..e2a5e7d9dc5 Binary files /dev/null and b/base_product_mass_addition/static/description/po.png differ 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 00000000000..e66df42c3cc --- /dev/null +++ b/base_product_mass_addition/views/product_view.xml @@ -0,0 +1,34 @@ + + + + + product.product + + + + + + + + + +