diff --git a/setup/web_widget_one2many_product_picker_sale_secondary_unit/odoo/addons/web_widget_one2many_product_picker_sale_secondary_unit b/setup/web_widget_one2many_product_picker_sale_secondary_unit/odoo/addons/web_widget_one2many_product_picker_sale_secondary_unit new file mode 120000 index 000000000..5894f0525 --- /dev/null +++ b/setup/web_widget_one2many_product_picker_sale_secondary_unit/odoo/addons/web_widget_one2many_product_picker_sale_secondary_unit @@ -0,0 +1 @@ +../../../../web_widget_one2many_product_picker_sale_secondary_unit \ No newline at end of file diff --git a/setup/web_widget_one2many_product_picker_sale_secondary_unit/setup.py b/setup/web_widget_one2many_product_picker_sale_secondary_unit/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/web_widget_one2many_product_picker_sale_secondary_unit/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/README.rst b/web_widget_one2many_product_picker_sale_secondary_unit/README.rst new file mode 100644 index 000000000..2b4323e62 --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/README.rst @@ -0,0 +1,76 @@ +====================================================== +Web Widget One2Many Product Picker Sale Secondary Unit +====================================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/12.0/web_widget_one2many_product_picker_sale_secondary_unit + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-12-0/web-12-0-web_widget_one2many_product_picker_sale_secondary_unit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/162/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Adds support for 'sale_order_secondary_unit' in the product picker + +**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 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 `_: + + * Alexandre D. Díaz + * 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/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/__init__.py b/web_widget_one2many_product_picker_sale_secondary_unit/__init__.py new file mode 100644 index 000000000..28345b82a --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2020 Tecnativa - Alexandre Díaz +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import models diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/__manifest__.py b/web_widget_one2many_product_picker_sale_secondary_unit/__manifest__.py new file mode 100644 index 000000000..e605a7ce9 --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright 2020 Tecnativa - Alexandre D. Díaz +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Web Widget One2Many Product Picker Sale Secondary Unit", + "summary": """ + Adds support for sale secondary unit in the one2many product picker + widget + """, + "version": "13.0.1.0.0", + "category": "Website", + "author": "Tecnativa, " "Odoo Community Association (OCA)", + "website": "https://www.tecnativa.com", + "license": "AGPL-3", + "depends": ["web_widget_one2many_product_picker", "sale_order_secondary_unit"], + "data": ["templates/assets.xml"], + "qweb": ["static/src/xml/one2many_product_picker.xml"], + "installable": True, + "auto_install": False, +} diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/models/__init__.py b/web_widget_one2many_product_picker_sale_secondary_unit/models/__init__.py new file mode 100644 index 000000000..6ea67bbd7 --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/models/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2020 Tecnactiva - Alexandre Díaz +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import sale_order_line diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/models/sale_order_line.py b/web_widget_one2many_product_picker_sale_secondary_unit/models/sale_order_line.py new file mode 100644 index 000000000..8c3ac2f3f --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/models/sale_order_line.py @@ -0,0 +1,16 @@ +# Copyright 2020 Tecnactiva - Alexandre Díaz +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from odoo import api, fields, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + @api.depends("product_id", "product_id.secondary_uom_ids") + def _compute_has_secondary_uom(self): + for record in self: + record.has_secondary_uom = any(record.product_id.secondary_uom_ids.ids) + + has_secondary_uom = fields.Boolean( + "Has Secondary UoM", compute="_compute_has_secondary_uom", store=False + ) diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/readme/CONTRIBUTORS.rst b/web_widget_one2many_product_picker_sale_secondary_unit/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..f3d7389e1 --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/readme/CONTRIBUTORS.rst @@ -0,0 +1,4 @@ +* `Tecnativa `_: + + * Alexandre D. Díaz + * Pedro M. Baeza diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/readme/DESCRIPTION.rst b/web_widget_one2many_product_picker_sale_secondary_unit/readme/DESCRIPTION.rst new file mode 100644 index 000000000..09f51602f --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Adds support for 'sale_order_secondary_unit' in the product picker diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/static/description/index.html b/web_widget_one2many_product_picker_sale_secondary_unit/static/description/index.html new file mode 100644 index 000000000..000d513f3 --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/static/description/index.html @@ -0,0 +1,426 @@ + + + + + + +Web Widget One2Many Product Picker Sale Secondary Unit + + + +
+

Web Widget One2Many Product Picker Sale Secondary Unit

+ + +

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

+

Adds support for ‘sale_order_secondary_unit’ in the product picker

+

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 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:

    +
    +
      +
    • Alexandre D. Díaz
    • +
    • 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/web project on GitHub.

+

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

+
+
+
+ + diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/static/src/js/views/abstract_view.js b/web_widget_one2many_product_picker_sale_secondary_unit/static/src/js/views/abstract_view.js new file mode 100644 index 000000000..80061e430 --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/static/src/js/views/abstract_view.js @@ -0,0 +1,145 @@ +// Copyright 2020 Tecnativa - Alexandre Díaz +// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +odoo.define( + "web_widget_one2many_product_picker_sale_secondary_unit.AbstractView", + function(require) { + "use strict"; + + const core = require("web.core"); + const AbstractView = require("web.AbstractView"); + + const _t = core._t; + + /** + * Helper function to create field view definitions + * + * @private + * @param {Object} params + * @returns {Object} + */ + function _constructFakeFieldDef(params) { + return _.extend( + { + change_default: false, + company_dependent: false, + manual: false, + views: {}, + searchable: true, + store: false, + readonly: true, + required: false, + sortable: false, + }, + params + ); + } + + /** + * This is pure hard-coded magic. Adds new fields to the widget form view. + */ + AbstractView.include({ + /** + * @override + */ + init: function(viewInfo, params) { + if (viewInfo.model === "sale.order") { + const widget_name = $(viewInfo.arch) + .find("field[name='order_line']") + .attr("widget"); + if (widget_name === "one2many_product_picker") { + this._injectSaleSecondaryUnitFields(viewInfo); + } + return this._super(viewInfo, params); + } + this._super.apply(this, arguments); + }, + + /** + * @private + * @param {Object} viewInfo + */ + _injectSaleSecondaryUnitFields: function(viewInfo) { + const to_inject = { + has_secondary_uom: _constructFakeFieldDef({ + depends: ["product_id", "product_id.secondary_uom_ids"], + type: "boolean", + }), + secondary_uom_qty: _constructFakeFieldDef({ + depends: [], + string: _t("Secondary Qty"), + group_operator: "sum", + digits: [16, 3], + store: true, + sortable: false, + readonly: false, + type: "float", + }), + secondary_uom_id: _constructFakeFieldDef({ + depends: [], + relation: "product.secondary.unit", + string: _t("Secondary uom"), + store: true, + sortable: false, + readonly: false, + type: "many2one", + }), + }; + viewInfo.viewFields.order_line.views.form.fields = _.extend( + {}, + to_inject, + viewInfo.viewFields.order_line.views.form.fields + ); + + // Add fields to arch + const $arch = $(viewInfo.viewFields.order_line.views.form.arch); + + // Add has_secondary_uom? + let $field = $arch.find("field[name='has_secondary_uom']"); + if (!$field.length) { + $("", { + name: "has_secondary_uom", + invisible: 1, + modifiers: '{"invisible": true, "readonly": true}', + }).prependTo($arch); + } + // Add secondary_uom_id? + $field = $arch.find("field[name='secondary_uom_id']"); + if (!$field.length) { + $("", { + name: "secondary_uom_id", + options: + "{'no_open': True, 'no_create': True, 'no_edit': True}", + "t-attf-domain": + "[['product_tmpl_id.product_variant_ids', 'in', [{{record_search.id}}]]]", + class: "mb-1", + on_change: 1, + can_create: "true", + can_write: "true", + store: true, + sortable: false, + readonly: false, + attrs: '{"invisible": [["has_secondary_uom", "!=", True]]}', + modifiers: '{"invisible": [["has_secondary_uom", "!=", true]]}', + }).prependTo($arch); + } + // Add secondary_uom_qty? + $field = $arch.find("field[name='secondary_uom_qty']"); + if (!$field.length) { + $("", { + name: "secondary_uom_qty", + on_change: 1, + class: "mb-1", + widget: "numeric_step", + attrs: '{"invisible": [["has_secondary_uom", "!=", True]]}', + modifiers: '{"invisible": [["has_secondary_uom", "!=", true]]}', + store: true, + sortable: false, + readonly: false, + }).prependTo($arch); + } + + viewInfo.viewFields.order_line.views.form.arch = $arch[0].outerHTML; + }, + }); + } +); diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/static/src/scss/_variables.scss b/web_widget_one2many_product_picker_sale_secondary_unit/static/src/scss/_variables.scss new file mode 100644 index 000000000..9006a1e85 --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/static/src/scss/_variables.scss @@ -0,0 +1 @@ +$one2many-product-picker-card-max-height: $one2many-product-picker-card-max-height + 15; diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/static/src/xml/one2many_product_picker.xml b/web_widget_one2many_product_picker_sale_secondary_unit/static/src/xml/one2many_product_picker.xml new file mode 100644 index 000000000..1ebbe7637 --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/static/src/xml/one2many_product_picker.xml @@ -0,0 +1,19 @@ + + diff --git a/web_widget_one2many_product_picker_sale_secondary_unit/templates/assets.xml b/web_widget_one2many_product_picker_sale_secondary_unit/templates/assets.xml new file mode 100644 index 000000000..7c1a7d28d --- /dev/null +++ b/web_widget_one2many_product_picker_sale_secondary_unit/templates/assets.xml @@ -0,0 +1,27 @@ + + +