diff --git a/website_sale_stock_provisioning_date/README.rst b/website_sale_stock_provisioning_date/README.rst new file mode 100644 index 0000000000..6b3fba7cbf --- /dev/null +++ b/website_sale_stock_provisioning_date/README.rst @@ -0,0 +1,103 @@ +==================================== +Website Sale Stock Provisioning Date +==================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9f16c9d75d1639907052e2ceaed6e8c73d1d534fdde872cbd0611f4ddbbebf88 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |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%2Fe--commerce-lightgray.png?logo=github + :target: https://github.com/OCA/e-commerce/tree/17.0/website_sale_stock_provisioning_date + :alt: OCA/e-commerce +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/e-commerce-17-0/e-commerce-17-0-website_sale_stock_provisioning_date + :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/e-commerce&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of website to show you the future +provisioning date closest to the current date for a product in the +eCommerce. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +1. Go to *Sales > Products > Products*, create a new product or edit an + existing one. +2. Check 'Show Next Provisioning Date' field under eCommerce tab. +3. Go to Website Shop. +4. Click on a product that have 'Show Next Provisioning Date' checked. +5. If it is true for that product that 'quantity on hand' - 'outgoing + quantity' <= 0, then you will see the future provisioning date + closest to the current date for this product under the 'Add to Cart' + button (If there is such a date). + +Note: The closest future provisioning date is the date of the future +stock movement and the closest to the current date. This can be +generated after confirming a purchase order to receive the product on a +date after the current date. + +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 +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - Ernesto Tejeda + - Pedro M. Baeza + - Sergio Teruel + - Carlos Roca + +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/e-commerce `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_sale_stock_provisioning_date/__init__.py b/website_sale_stock_provisioning_date/__init__.py new file mode 100644 index 0000000000..3275ac2adf --- /dev/null +++ b/website_sale_stock_provisioning_date/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models diff --git a/website_sale_stock_provisioning_date/__manifest__.py b/website_sale_stock_provisioning_date/__manifest__.py new file mode 100644 index 0000000000..2950226e95 --- /dev/null +++ b/website_sale_stock_provisioning_date/__manifest__.py @@ -0,0 +1,26 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Website Sale Stock Provisioning Date", + "summary": "Display provisioning date for a product in shop online", + "version": "17.0.1.0.0", + "development_status": "Production/Stable", + "category": "Website", + "website": "https://github.com/OCA/e-commerce", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["website_sale_stock"], + "data": ["views/product_template_views.xml"], + "assets": { + "web.assets_frontend": [ + "website_sale_stock_provisioning_date/static/src/xml/" + "website_sale_stock_product_availability.xml", + ], + "web.assets_tests": [ + "/website_sale_stock_provisioning_date/static/src/js/" + "website_sale_stock_provisioning_date_tour.esm.js", + ], + }, +} diff --git a/website_sale_stock_provisioning_date/i18n/es.po b/website_sale_stock_provisioning_date/i18n/es.po new file mode 100644 index 0000000000..177e6f00be --- /dev/null +++ b/website_sale_stock_provisioning_date/i18n/es.po @@ -0,0 +1,58 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_stock_provisioning_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2020-09-23 20:14+0000\n" +"PO-Revision-Date: 2023-10-08 22:54+0000\n" +"Last-Translator: Ivorra78 \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: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: website_sale_stock_provisioning_date +#. odoo-javascript +#: code:addons/website_sale_stock_provisioning_date/static/src/xml/website_sale_stock_product_availability.xml:0 +#, python-format +msgid "Next provisioning date:" +msgstr "Fecha de aprovisionamiento:" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model,name:website_sale_stock_provisioning_date.model_product_template +msgid "Product" +msgstr "Producto" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model,name:website_sale_stock_provisioning_date.model_product_product +msgid "Product Variant" +msgstr "Variante del Producto" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model.fields,field_description:website_sale_stock_provisioning_date.field_product_product__show_next_provisioning_date +#: model:ir.model.fields,field_description:website_sale_stock_provisioning_date.field_product_template__show_next_provisioning_date +msgid "Show Next Provisioning Date" +msgstr "Mostrar fecha de aprovisionamiento" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model.fields,help:website_sale_stock_provisioning_date.field_product_product__show_next_provisioning_date +#: model:ir.model.fields,help:website_sale_stock_provisioning_date.field_product_template__show_next_provisioning_date +msgid "" +"Shows the next provisioning date in the website shop if the product is out " +"of stock. This option may not make sense if you don't select an " +"'Availability' option that shows the inventory of the product in the website " +"shop." +msgstr "" +"Muestra en la tienda online la fecha de aprovisionamiento prevista si el " +"producto está sin existencias. Esta opción puede no tener sentido si usted " +"no selecciona una opción de disponibilidad que muestre el inventario del " +"producto en la tienda online." + +#~ msgid "Product Template" +#~ msgstr "Plantilla de producto" diff --git a/website_sale_stock_provisioning_date/i18n/it.po b/website_sale_stock_provisioning_date/i18n/it.po new file mode 100644 index 0000000000..c4508520e2 --- /dev/null +++ b/website_sale_stock_provisioning_date/i18n/it.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_stock_provisioning_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-05-08 16:34+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: website_sale_stock_provisioning_date +#. odoo-javascript +#: code:addons/website_sale_stock_provisioning_date/static/src/xml/website_sale_stock_product_availability.xml:0 +#, python-format +msgid "Next provisioning date:" +msgstr "Data prossima fornitura:" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model,name:website_sale_stock_provisioning_date.model_product_template +msgid "Product" +msgstr "Prodotto" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model,name:website_sale_stock_provisioning_date.model_product_product +msgid "Product Variant" +msgstr "Variante prodotto" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model.fields,field_description:website_sale_stock_provisioning_date.field_product_product__show_next_provisioning_date +#: model:ir.model.fields,field_description:website_sale_stock_provisioning_date.field_product_template__show_next_provisioning_date +msgid "Show Next Provisioning Date" +msgstr "Visualizza prossima data fornitura" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model.fields,help:website_sale_stock_provisioning_date.field_product_product__show_next_provisioning_date +#: model:ir.model.fields,help:website_sale_stock_provisioning_date.field_product_template__show_next_provisioning_date +msgid "" +"Shows the next provisioning date in the website shop if the product is out " +"of stock. This option may not make sense if you don't select an " +"'Availability' option that shows the inventory of the product in the website" +" shop." +msgstr "" +"Visualizza la prossima data fornitura nel negosio del sito web se il " +"prodotto è esaurito. Questa opzione può non avere senso se non si seleziona " +"una opzione 'Disponibilità\" che visualizza la giacenza del prodotto nel " +"negozio del sito web." diff --git a/website_sale_stock_provisioning_date/i18n/website_sale_stock_provisioning_date.pot b/website_sale_stock_provisioning_date/i18n/website_sale_stock_provisioning_date.pot new file mode 100644 index 0000000000..25a7ba23c3 --- /dev/null +++ b/website_sale_stock_provisioning_date/i18n/website_sale_stock_provisioning_date.pot @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_sale_stock_provisioning_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.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: website_sale_stock_provisioning_date +#. odoo-javascript +#: code:addons/website_sale_stock_provisioning_date/static/src/xml/website_sale_stock_product_availability.xml:0 +#, python-format +msgid "Next provisioning date:" +msgstr "" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model,name:website_sale_stock_provisioning_date.model_product_template +msgid "Product" +msgstr "" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model,name:website_sale_stock_provisioning_date.model_product_product +msgid "Product Variant" +msgstr "" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model.fields,field_description:website_sale_stock_provisioning_date.field_product_product__show_next_provisioning_date +#: model:ir.model.fields,field_description:website_sale_stock_provisioning_date.field_product_template__show_next_provisioning_date +msgid "Show Next Provisioning Date" +msgstr "" + +#. module: website_sale_stock_provisioning_date +#: model:ir.model.fields,help:website_sale_stock_provisioning_date.field_product_product__show_next_provisioning_date +#: model:ir.model.fields,help:website_sale_stock_provisioning_date.field_product_template__show_next_provisioning_date +msgid "" +"Shows the next provisioning date in the website shop if the product is out " +"of stock. This option may not make sense if you don't select an " +"'Availability' option that shows the inventory of the product in the website" +" shop." +msgstr "" diff --git a/website_sale_stock_provisioning_date/models/__init__.py b/website_sale_stock_provisioning_date/models/__init__.py new file mode 100644 index 0000000000..4218bd2646 --- /dev/null +++ b/website_sale_stock_provisioning_date/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import product_product +from . import product_template diff --git a/website_sale_stock_provisioning_date/models/product_product.py b/website_sale_stock_provisioning_date/models/product_product.py new file mode 100644 index 0000000000..64e0495972 --- /dev/null +++ b/website_sale_stock_provisioning_date/models/product_product.py @@ -0,0 +1,19 @@ +# Copyright 2019 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + def _get_next_provisioning_date(self, company): + domain = [ + ("company_id", "=", company.id), + ("product_id", "in", self.ids), + ("state", "not in", ["draft", "done", "cancel"]), + ("location_id.usage", "=", "supplier"), + ("location_dest_id.usage", "=", "internal"), + ("date", ">=", fields.Datetime.now()), + ] + move = self.env["stock.move"].sudo().search(domain, order="date", limit=1) + return move and move.date.date() or False diff --git a/website_sale_stock_provisioning_date/models/product_template.py b/website_sale_stock_provisioning_date/models/product_template.py new file mode 100644 index 0000000000..cdcb4eb821 --- /dev/null +++ b/website_sale_stock_provisioning_date/models/product_template.py @@ -0,0 +1,85 @@ +# Copyright 2019 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models +from odoo.tools.misc import format_date + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + show_next_provisioning_date = fields.Boolean( + help="Shows the next provisioning date in the website shop " + "if the product is out of stock. This option may not make " + "sense if you don't select an 'Availability' option that " + "shows the inventory of the product in the website shop." + ) + + free_qty = fields.Float( + "Free To Use Quantity ", + compute="_compute_quantities", + search="_search_free_qty", + digits="Product Unit of Measure", + compute_sudo=False, + ) + + def _search_free_qty(self, operator, value): + domain = [("free_qty", operator, value)] + product_variant_query = self.env["product.product"]._search(domain) + return [("product_variant_ids", "in", product_variant_query)] + + def _compute_free_qty_dict(self): + prod_available = {} + variants_available = { + p["id"]: p for p in self.product_variant_ids._origin.read(["free_qty"]) + } + for template in self: + free_qty = 0 + for p in template.product_variant_ids._origin: + free_qty += variants_available[p.id]["free_qty"] + prod_available.setdefault( + template.id, prod_available.get(template.id, {}) + ).update({"free_qty": free_qty}) + return prod_available + + def _compute_quantities(self): + result = super()._compute_quantities() + res = self._compute_free_qty_dict() + for template in self: + template.free_qty = res[template.id]["free_qty"] + return result + + def _get_next_provisioning_date(self, company): + return self.product_variant_ids._get_next_provisioning_date(company) + + def _get_combination_info( + self, + combination=False, + product_id=False, + add_qty=1, + parent_combination=False, + only_template=False, + ): + combination_info = super()._get_combination_info( + combination=combination, + product_id=product_id, + add_qty=add_qty, + parent_combination=parent_combination, + only_template=only_template, + ) + if combination_info["product_id"]: + product = ( + self.env["product.product"] + .sudo() + .browse(combination_info["product_id"]) + ) + else: + product = self.sudo() + website = self.env["website"].get_current_website() + provisioning_date = False + free_qty = website._get_product_available_qty(product) + if product.show_next_provisioning_date and free_qty <= 0: + company = website.company_id + provisioning_date = product._get_next_provisioning_date(company) + provisioning_date = format_date(self.env, provisioning_date) + combination_info.update(provisioning_date=provisioning_date) + return combination_info diff --git a/website_sale_stock_provisioning_date/pyproject.toml b/website_sale_stock_provisioning_date/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/website_sale_stock_provisioning_date/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/website_sale_stock_provisioning_date/readme/CONTRIBUTORS.md b/website_sale_stock_provisioning_date/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..1575929501 --- /dev/null +++ b/website_sale_stock_provisioning_date/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- [Tecnativa](https://www.tecnativa.com): + - Ernesto Tejeda + - Pedro M. Baeza + - Sergio Teruel + - Carlos Roca diff --git a/website_sale_stock_provisioning_date/readme/DESCRIPTION.md b/website_sale_stock_provisioning_date/readme/DESCRIPTION.md new file mode 100644 index 0000000000..d0e80171b0 --- /dev/null +++ b/website_sale_stock_provisioning_date/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module extends the functionality of website to show you the future +provisioning date closest to the current date for a product in the +eCommerce. diff --git a/website_sale_stock_provisioning_date/readme/USAGE.md b/website_sale_stock_provisioning_date/readme/USAGE.md new file mode 100644 index 0000000000..fc3a956138 --- /dev/null +++ b/website_sale_stock_provisioning_date/readme/USAGE.md @@ -0,0 +1,16 @@ +To use this module, you need to: + +1. Go to *Sales \> Products \> Products*, create a new product or edit + an existing one. +2. Check 'Show Next Provisioning Date' field under eCommerce tab. +3. Go to Website Shop. +4. Click on a product that have 'Show Next Provisioning Date' checked. +5. If it is true for that product that 'quantity on hand' - 'outgoing + quantity' \<= 0, then you will see the future provisioning date + closest to the current date for this product under the 'Add to Cart' + button (If there is such a date). + +Note: The closest future provisioning date is the date of the future +stock movement and the closest to the current date. This can be +generated after confirming a purchase order to receive the product on a +date after the current date. diff --git a/website_sale_stock_provisioning_date/static/description/icon.png b/website_sale_stock_provisioning_date/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/website_sale_stock_provisioning_date/static/description/icon.png differ diff --git a/website_sale_stock_provisioning_date/static/description/index.html b/website_sale_stock_provisioning_date/static/description/index.html new file mode 100644 index 0000000000..8857122a76 --- /dev/null +++ b/website_sale_stock_provisioning_date/static/description/index.html @@ -0,0 +1,451 @@ + + + + + +Website Sale Stock Provisioning Date + + + +
+

Website Sale Stock Provisioning Date

+ + +

Production/Stable License: AGPL-3 OCA/e-commerce Translate me on Weblate Try me on Runboat

+

This module extends the functionality of website to show you the future +provisioning date closest to the current date for a product in the +eCommerce.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. Go to Sales > Products > Products, create a new product or edit an +existing one.
  2. +
  3. Check ‘Show Next Provisioning Date’ field under eCommerce tab.
  4. +
  5. Go to Website Shop.
  6. +
  7. Click on a product that have ‘Show Next Provisioning Date’ checked.
  8. +
  9. If it is true for that product that ‘quantity on hand’ - ‘outgoing +quantity’ <= 0, then you will see the future provisioning date +closest to the current date for this product under the ‘Add to Cart’ +button (If there is such a date).
  10. +
+

Note: The closest future provisioning date is the date of the future +stock movement and the closest to the current date. This can be +generated after confirming a purchase order to receive the product on a +date after the current date.

+
+
+

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

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+
    +
  • Tecnativa:
      +
    • Ernesto Tejeda
    • +
    • Pedro M. Baeza
    • +
    • Sergio Teruel
    • +
    • Carlos Roca
    • +
    +
  • +
+
+
+

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/e-commerce project on GitHub.

+

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

+
+
+
+ + diff --git a/website_sale_stock_provisioning_date/static/src/js/website_sale_stock_provisioning_date_tour.esm.js b/website_sale_stock_provisioning_date/static/src/js/website_sale_stock_provisioning_date_tour.esm.js new file mode 100644 index 0000000000..c7da13008e --- /dev/null +++ b/website_sale_stock_provisioning_date/static/src/js/website_sale_stock_provisioning_date_tour.esm.js @@ -0,0 +1,24 @@ +/** @odoo-module **/ +/* Copyright 2020 Tecnativa - Ernesto Tejeda + * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ + +import {registry} from "@web/core/registry"; +import tourUtils from "@website_sale/js/tours/tour_utils"; +import wTourUtils from "@website/js/tours/tour_utils"; + +registry.category("web_tour.tours").add("website_sale_stock_provisioning_date", { + test: true, + url: "/shop", + steps: () => [ + ...tourUtils.searchProduct("provisioning date"), + wTourUtils.clickOnElement( + "click on product test", + '.oe_product_cart a:contains("provisioning date")' + ), + { + trigger: "a#add_to_cart", + extra_trigger: + ".availability_messages:has(span:contains('Next provisioning date:'))", + }, + ], +}); diff --git a/website_sale_stock_provisioning_date/static/src/xml/website_sale_stock_product_availability.xml b/website_sale_stock_provisioning_date/static/src/xml/website_sale_stock_product_availability.xml new file mode 100644 index 0000000000..9388b591c4 --- /dev/null +++ b/website_sale_stock_provisioning_date/static/src/xml/website_sale_stock_product_availability.xml @@ -0,0 +1,17 @@ + + + + + +
+ + Next provisioning date: + +
+
+
+
diff --git a/website_sale_stock_provisioning_date/tests/__init__.py b/website_sale_stock_provisioning_date/tests/__init__.py new file mode 100644 index 0000000000..871b1f4cdc --- /dev/null +++ b/website_sale_stock_provisioning_date/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import test_website_sale_stock_provisioning_date diff --git a/website_sale_stock_provisioning_date/tests/test_website_sale_stock_provisioning_date.py b/website_sale_stock_provisioning_date/tests/test_website_sale_stock_provisioning_date.py new file mode 100644 index 0000000000..144925cc13 --- /dev/null +++ b/website_sale_stock_provisioning_date/tests/test_website_sale_stock_provisioning_date.py @@ -0,0 +1,104 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from datetime import datetime, timedelta + +from odoo.tests.common import Form, HttpCase, tagged + + +@tagged("post_install", "-at_install") +class WebsiteSaleStockProvisioningDate(HttpCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + product = cls.env["product.product"].create( + { + "name": "product test - provisioning date", + "type": "product", + "website_published": True, + "show_next_provisioning_date": True, + } + ) + incoming_picking_type = cls.env["stock.picking.type"].search( + [ + ("code", "=", "incoming"), + "|", + ("warehouse_id.company_id", "=", cls.env.user.company_id.id), + ("warehouse_id", "=", False), + ], + limit=1, + ) + picking_form = Form( + cls.env["stock.picking"].with_context( + default_picking_type_id=incoming_picking_type.id + ), + view="stock.view_picking_form", + ) + with picking_form.move_ids_without_package.new() as move: + move.product_id = product + move.product_uom_qty = 10 + picking = picking_form.save() + picking_form = Form(picking) + picking_form.scheduled_date = datetime.now() + timedelta(days=2) + picking = picking_form.save() + picking.action_confirm() + + cls.warehouse_1 = cls.env["stock.warehouse"].search( + [("company_id", "=", cls.env.company.id)] + ) + # Create two stockable products + cls.product_A = cls.env["product.product"].create( + { + "name": "Product A", + "allow_out_of_stock_order": False, + "type": "product", + "default_code": "E-COM1", + } + ) + cls.partner = cls.env["res.partner"].create( + {"name": "Test Partner", "email": "prueba@pruebae.es"} + ) + # Add 10 Product A in WH1 and 15 Product 1 in WH2 + quants = ( + cls.env["stock.quant"] + .with_context(inventory_mode=True) + .create( + [ + { + "product_id": cls.product_A.id, + "inventory_quantity": 10.0, + "location_id": cls.warehouse_1.lot_stock_id.id, + } + ] + ) + ) + quants.action_apply_inventory() + sale = cls.env["sale.order"].create( + { + "partner_id": cls.partner.id, + "order_line": [ + ( + 0, + 0, + { + "product_id": cls.product_A.id, + "product_uom_qty": 3, + }, + ) + ], + } + ) + sale.action_confirm() + + def test_ui_website(self): + """Test frontend tour.""" + self.start_tour( + "/shop", + "website_sale_stock_provisioning_date", + login="admin", + ) + + def test_search_qty_free(self): + templates = self.env["product.template"].search( + [("free_qty", ">", 0), ("id", "=", self.product_A.product_tmpl_id.id)] + ) + self.assertEqual(templates.free_qty, 7) diff --git a/website_sale_stock_provisioning_date/views/product_template_views.xml b/website_sale_stock_provisioning_date/views/product_template_views.xml new file mode 100644 index 0000000000..ecbd221846 --- /dev/null +++ b/website_sale_stock_provisioning_date/views/product_template_views.xml @@ -0,0 +1,17 @@ + + + + + product.template + + + + + + + +