diff --git a/sale_pricelist_from_commitment_date/README.rst b/sale_pricelist_from_commitment_date/README.rst new file mode 100644 index 00000000..834e0097 --- /dev/null +++ b/sale_pricelist_from_commitment_date/README.rst @@ -0,0 +1,105 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=================================== +Sale Pricelist From Commitment Date +=================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f7cb9a3371d9e916481865df469b90de09062e21e5d03d9af3d450927153ab7c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Fsale--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/sale-workflow/tree/18.0/sale_pricelist_from_commitment_date + :alt: OCA/sale-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-0-sale_pricelist_from_commitment_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/sale-workflow&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +When the sale order commitment date is set, this date is used by +pricelist to compute price unit instead of using order date. + +This module also provides configuration options to enhance the Delivery +Date field visibility and requirement. The Delivery Date field can be +displayed in header (after the Quotation/Order Date field) for better +visibility, and can optionally be made mandatory on sales orders. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Go to Sales → Configuration → Settings to configure the following +options: + +**Show Delivery Date in Header** + +- Display the Delivery Date field in header (after the Quotation/Order + Date field) on the sales order form for better visibility. + +**Require Delivery Date** + +- Make the Delivery Date field mandatory on sales orders. + +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 +------- + +* Camptocamp + +Contributors +------------ + +- Julien Coux +- Quartile + + - Yoshi Tashiro + - Aung Ko Ko Lin + +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/sale-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_pricelist_from_commitment_date/__init__.py b/sale_pricelist_from_commitment_date/__init__.py new file mode 100644 index 00000000..31660d6a --- /dev/null +++ b/sale_pricelist_from_commitment_date/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/sale_pricelist_from_commitment_date/__manifest__.py b/sale_pricelist_from_commitment_date/__manifest__.py new file mode 100644 index 00000000..50c6a954 --- /dev/null +++ b/sale_pricelist_from_commitment_date/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2021 Camptocamp +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Sale Pricelist From Commitment Date", + "summary": "Use sale order commitment date to compute line price from pricelist", + "version": "18.0.1.0.0", + "category": "Sale", + "website": "https://github.com/OCA/sale-workflow", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": ["sale"], + "data": [ + "views/res_config_settings_views.xml", + "views/sale_order_views.xml", + ], + "installable": True, +} diff --git a/sale_pricelist_from_commitment_date/i18n/es.po b/sale_pricelist_from_commitment_date/i18n/es.po new file mode 100644 index 00000000..919878da --- /dev/null +++ b/sale_pricelist_from_commitment_date/i18n/es.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_pricelist_from_commitment_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-18 20:10+0000\n" +"Last-Translator: Ivorra78 \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.17\n" + +#. module: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_product_pricelist +msgid "Pricelist" +msgstr "Lista de Precios" + +#. module: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_product_pricelist_item +msgid "Pricelist Rule" +msgstr "Regla de la lista de Precios" + +#. module: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_sale_order_line +msgid "Sales Order Line" +msgstr "Línea de Orden de Venta" diff --git a/sale_pricelist_from_commitment_date/i18n/fr.po b/sale_pricelist_from_commitment_date/i18n/fr.po new file mode 100644 index 00000000..3065a3c7 --- /dev/null +++ b/sale_pricelist_from_commitment_date/i18n/fr.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_pricelist_from_commitment_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-12-31 15:06+0000\n" +"Last-Translator: samibc2c \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 5.6.2\n" + +#. module: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_product_pricelist +msgid "Pricelist" +msgstr "Liste de prix" + +#. module: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_product_pricelist_item +msgid "Pricelist Rule" +msgstr "Règle de liste de prix" + +#. module: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_sale_order_line +msgid "Sales Order Line" +msgstr "Ligne de bon de commande" diff --git a/sale_pricelist_from_commitment_date/i18n/it.po b/sale_pricelist_from_commitment_date/i18n/it.po new file mode 100644 index 00000000..f4fb1ae3 --- /dev/null +++ b/sale_pricelist_from_commitment_date/i18n/it.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_pricelist_from_commitment_date +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-12-07 18:33+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: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_product_pricelist +msgid "Pricelist" +msgstr "Listino prezzi" + +#. module: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_product_pricelist_item +msgid "Pricelist Rule" +msgstr "Regola listino prezzi" + +#. module: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_sale_order_line +msgid "Sales Order Line" +msgstr "Riga ordine di vendita" diff --git a/sale_pricelist_from_commitment_date/i18n/sale_pricelist_from_commitment_date.pot b/sale_pricelist_from_commitment_date/i18n/sale_pricelist_from_commitment_date.pot new file mode 100644 index 00000000..b76293f6 --- /dev/null +++ b/sale_pricelist_from_commitment_date/i18n/sale_pricelist_from_commitment_date.pot @@ -0,0 +1,29 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_pricelist_from_commitment_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: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_product_pricelist +msgid "Pricelist" +msgstr "" + +#. module: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_product_pricelist_item +msgid "Pricelist Rule" +msgstr "" + +#. module: sale_pricelist_from_commitment_date +#: model:ir.model,name:sale_pricelist_from_commitment_date.model_sale_order_line +msgid "Sales Order Line" +msgstr "" diff --git a/sale_pricelist_from_commitment_date/models/__init__.py b/sale_pricelist_from_commitment_date/models/__init__.py new file mode 100644 index 00000000..9d9d3b91 --- /dev/null +++ b/sale_pricelist_from_commitment_date/models/__init__.py @@ -0,0 +1,6 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import sale_order_line +from . import sale_order +from . import res_company +from . import res_config_settings diff --git a/sale_pricelist_from_commitment_date/models/res_company.py b/sale_pricelist_from_commitment_date/models/res_company.py new file mode 100644 index 00000000..3f00354e --- /dev/null +++ b/sale_pricelist_from_commitment_date/models/res_company.py @@ -0,0 +1,11 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + sale_require_commitment_date = fields.Boolean() + sale_commitment_date_in_header = fields.Boolean() diff --git a/sale_pricelist_from_commitment_date/models/res_config_settings.py b/sale_pricelist_from_commitment_date/models/res_config_settings.py new file mode 100644 index 00000000..f8f649a0 --- /dev/null +++ b/sale_pricelist_from_commitment_date/models/res_config_settings.py @@ -0,0 +1,17 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + sale_require_commitment_date = fields.Boolean( + related="company_id.sale_require_commitment_date", + readonly=False, + ) + sale_commitment_date_in_header = fields.Boolean( + related="company_id.sale_commitment_date_in_header", + readonly=False, + ) diff --git a/sale_pricelist_from_commitment_date/models/sale_order.py b/sale_pricelist_from_commitment_date/models/sale_order.py new file mode 100644 index 00000000..84937a0e --- /dev/null +++ b/sale_pricelist_from_commitment_date/models/sale_order.py @@ -0,0 +1,34 @@ +# Copyright 2026 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, fields, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + sale_require_commitment_date = fields.Boolean( + compute="_compute_sale_require_commitment_date" + ) + sale_commitment_date_in_header = fields.Boolean( + related="company_id.sale_commitment_date_in_header" + ) + + @api.depends( + "company_id.sale_require_commitment_date", + "locked", + "order_line.qty_delivered", + "order_line.product_uom_qty", + ) + def _compute_sale_require_commitment_date(self): + for order in self: + if not order.company_id.sale_require_commitment_date: + order.sale_require_commitment_date = False + elif order.locked: + order.sale_require_commitment_date = False + elif order.order_line and all( + line.qty_delivered >= line.product_uom_qty for line in order.order_line + ): + order.sale_require_commitment_date = False + else: + order.sale_require_commitment_date = True diff --git a/sale_pricelist_from_commitment_date/models/sale_order_line.py b/sale_pricelist_from_commitment_date/models/sale_order_line.py new file mode 100644 index 00000000..b3f014f4 --- /dev/null +++ b/sale_pricelist_from_commitment_date/models/sale_order_line.py @@ -0,0 +1,31 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + @api.depends( + "product_id", + "product_uom", + "product_uom_qty", + "order_id.commitment_date", + ) + def _compute_price_unit(self): + return super()._compute_price_unit() + + @api.depends( + "product_id", + "product_uom", + "product_uom_qty", + "order_id.commitment_date", + ) + def _compute_pricelist_item_id(self): + return super()._compute_pricelist_item_id() + + def _get_order_date(self): + if self.order_id.commitment_date: + return self.order_id.commitment_date + return super()._get_order_date() diff --git a/sale_pricelist_from_commitment_date/pyproject.toml b/sale_pricelist_from_commitment_date/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/sale_pricelist_from_commitment_date/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_pricelist_from_commitment_date/readme/CONFIGURE.md b/sale_pricelist_from_commitment_date/readme/CONFIGURE.md new file mode 100644 index 00000000..e350583f --- /dev/null +++ b/sale_pricelist_from_commitment_date/readme/CONFIGURE.md @@ -0,0 +1,8 @@ +Go to Sales → Configuration → Settings to configure the following options: + +**Show Delivery Date in Header** +- Display the Delivery Date field in header (after the Quotation/Order Date + field) on the sales order form for better visibility. + +**Require Delivery Date** +- Make the Delivery Date field mandatory on sales orders. diff --git a/sale_pricelist_from_commitment_date/readme/CONTRIBUTORS.md b/sale_pricelist_from_commitment_date/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..0b1efdad --- /dev/null +++ b/sale_pricelist_from_commitment_date/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +- Julien Coux \<\> +- Quartile \<\> + - Yoshi Tashiro + - Aung Ko Ko Lin diff --git a/sale_pricelist_from_commitment_date/readme/DESCRIPTION.md b/sale_pricelist_from_commitment_date/readme/DESCRIPTION.md new file mode 100644 index 00000000..920a05b6 --- /dev/null +++ b/sale_pricelist_from_commitment_date/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +When the sale order commitment date is set, this date is used by +pricelist to compute price unit instead of using order date. + +This module also provides configuration options to enhance the Delivery Date +field visibility and requirement. The Delivery Date field can be displayed +in header (after the Quotation/Order Date field) for better visibility, and +can optionally be made mandatory on sales orders. diff --git a/sale_pricelist_from_commitment_date/static/description/icon.png b/sale_pricelist_from_commitment_date/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/sale_pricelist_from_commitment_date/static/description/icon.png differ diff --git a/sale_pricelist_from_commitment_date/static/description/index.html b/sale_pricelist_from_commitment_date/static/description/index.html new file mode 100644 index 00000000..3f6fa4b7 --- /dev/null +++ b/sale_pricelist_from_commitment_date/static/description/index.html @@ -0,0 +1,454 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Sale Pricelist From Commitment Date

+ +

Beta License: AGPL-3 OCA/sale-workflow Translate me on Weblate Try me on Runboat

+

When the sale order commitment date is set, this date is used by +pricelist to compute price unit instead of using order date.

+

This module also provides configuration options to enhance the Delivery +Date field visibility and requirement. The Delivery Date field can be +displayed in header (after the Quotation/Order Date field) for better +visibility, and can optionally be made mandatory on sales orders.

+

Table of contents

+ +
+

Configuration

+

Go to Sales → Configuration → Settings to configure the following +options:

+

Show Delivery Date in Header

+
    +
  • Display the Delivery Date field in header (after the Quotation/Order +Date field) on the sales order form for better visibility.
  • +
+

Require Delivery Date

+
    +
  • Make the Delivery Date field mandatory on sales orders.
  • +
+
+
+

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

+
    +
  • Camptocamp
  • +
+
+
+

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.

+

This module is part of the OCA/sale-workflow project on GitHub.

+

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

+
+
+
+
+ + diff --git a/sale_pricelist_from_commitment_date/tests/__init__.py b/sale_pricelist_from_commitment_date/tests/__init__.py new file mode 100644 index 00000000..9060048d --- /dev/null +++ b/sale_pricelist_from_commitment_date/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_pricelist_from_commitment_date diff --git a/sale_pricelist_from_commitment_date/tests/test_pricelist_from_commitment_date.py b/sale_pricelist_from_commitment_date/tests/test_pricelist_from_commitment_date.py new file mode 100644 index 00000000..5f2b87a9 --- /dev/null +++ b/sale_pricelist_from_commitment_date/tests/test_pricelist_from_commitment_date.py @@ -0,0 +1,188 @@ +# Copyright 2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import Command +from odoo.tests import TransactionCase + + +class PricelistFromCommitmentDate(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + + # Pricelists. + cls.pricelist_parent = cls._create_price_list("Parent Pricelist") + cls.pricelist = cls._create_price_list("Simple Pricelist") + cls.env["product.pricelist.item"].create( + { + "pricelist_id": cls.pricelist.id, + "applied_on": "3_global", + "compute_price": "formula", + "base": "pricelist", + "base_pricelist_id": cls.pricelist_parent.id, + } + ) + # Test in the past to avoid to have date order in the interval + cls._create_price_list_item(cls.pricelist, 10, "2020-03-05", "2020-03-09") + cls._create_price_list_item(cls.pricelist, 20, "2020-03-10", "2020-03-14") + # Parent item + cls._create_price_list_item( + cls.pricelist_parent, 30, "2020-03-15", "2020-03-20" + ) + + # Create the SO with 1 order line + cls.sale = cls.env.ref("sale.sale_order_1") + + @classmethod + def _create_price_list(cls, name): + return cls.env["product.pricelist"].create( + { + "name": name, + "active": True, + "currency_id": cls.env.ref("base.USD").id, + "company_id": cls.env.user.company_id.id, + } + ) + + @classmethod + def _create_price_list_item(cls, pricelist, price, date_start=None, date_end=None): + values = { + "pricelist_id": pricelist.id, + "applied_on": "3_global", + "base": "list_price", + "compute_price": "fixed", + "fixed_price": price, + } + if date_start: + values["date_start"] = date_start + if date_end: + values["date_end"] = date_end + return cls.env["product.pricelist.item"].create(values) + + def _import_file_and_check_price_unit(self, file_vals): + file = "{}\r\n{}".format( + ",".join(file_vals.keys()), ",".join(file_vals.values()) + ) + # Create the importer and run it + import_wizard = self.env["base_import.import"].create( + { + "res_model": "sale.order", + "file": file.encode("utf-8"), + "file_type": "text/csv", + "file_name": "data.csv", + } + ) + res = import_wizard.execute_import( + list(file_vals.keys()), + list(file_vals.keys()), + { + "quoting": '"', + "separator": ",", + "has_headers": True, + "datetime_format": "%Y-%m-%d %H:%M:%S", + }, + True, + ) + # Check if the order line's price unit is the expected one + order = self.env["sale.order"].browse(res["ids"]) + real_pu = order.order_line[-1].price_unit + expected_pu = float(file_vals["order_line/price_unit"]) + self.assertEqual(real_pu, expected_pu) + + def test_00_pricelist(self): + sale = self.sale + order_line = sale.order_line[0] + product = order_line.product_id + self.assertEqual(order_line.price_unit, product.list_price) + # Change pricelist have no effect as no item match + sale.pricelist_id = self.pricelist + self.assertEqual(order_line.price_unit, product.list_price) + # Test with commitment date + sale.commitment_date = "2020-03-08" + self.assertEqual(order_line.price_unit, 10) + sale.commitment_date = "2020-03-12" + self.assertEqual(order_line.price_unit, 20) + # Parent price list must match + sale.commitment_date = "2020-03-17" + self.assertEqual(order_line.price_unit, 30) + sale.date_order = "2020-03-08" + # No change with changing order date + self.assertEqual(order_line.price_unit, 30) + # Remove commitment date, will match on date_order + sale.commitment_date = False + self.assertEqual(order_line.price_unit, 10) + # Remove the order date, will match on default price + sale.date_order = False + + def test_01_import_create(self): + """Tests whether prices are correctly set when creating a new SO""" + # These are the values we'll use to create the file to import + partner = self.env.ref("base.res_partner_2") + product = self.env.ref("product.product_product_8") + user = self.env.ref("base.user_demo") + self._import_file_and_check_price_unit( + { + "id": "__import__.sale_order_test_pricelist_from_commitment_date", + "name": "Test Pricelist From Commitment Date", + "partner_id": partner.name, + "user_id": user.name, + "order_line/product_id": product.name, + "order_line/product_uom_qty": "1", + "order_line/price_unit": "300.00", + "commitment_date": "2021-10-22 6:30:00", + } + ) + + def test_02_import_write(self): + """Tests whether prices are correctly set when updating a SO""" + # These are the values we'll use to create the file to import + product = self.env.ref("product.product_product_8") + self._import_file_and_check_price_unit( + { + "id": self.sale.get_external_id()[self.sale.id], + "order_line/product_id": product.name, + "order_line/product_uom_qty": "1", + "order_line/price_unit": "300.00", + } + ) + + def test_03_sale_require_commitment_date(self): + """Test sale_require_commitment_date computed field""" + company = self.env.company + partner = self.env["res.partner"].create({"name": "Test Partner"}) + product = self.env["product.product"].create({"name": "Test Product 1"}) + product2 = self.env["product.product"].create({"name": "Test Product 2"}) + company.sale_require_commitment_date = False + order = self.env["sale.order"].create( + { + "partner_id": partner.id, + "order_line": [ + Command.create({"product_id": product.id, "product_uom_qty": 10}) + ], + } + ) + self.assertFalse(order.sale_require_commitment_date) + company.sale_require_commitment_date = True + self.assertTrue(order.sale_require_commitment_date) + order.locked = True + self.assertFalse(order.sale_require_commitment_date) + order.locked = False + order.order_line[0].qty_delivered = 5 + self.assertTrue(order.sale_require_commitment_date) + order.order_line[0].qty_delivered = 10 + self.assertFalse(order.sale_require_commitment_date) + order.order_line[0].qty_delivered = 15 + self.assertFalse(order.sale_require_commitment_date) + order.write( + { + "order_line": [ + Command.create({"product_id": product2.id, "product_uom_qty": 5}) + ] + } + ) + order.order_line[0].qty_delivered = 10 + order.order_line[1].qty_delivered = 2 + self.assertTrue(order.sale_require_commitment_date) + order.order_line[1].qty_delivered = 5 + self.assertFalse(order.sale_require_commitment_date) diff --git a/sale_pricelist_from_commitment_date/views/res_config_settings_views.xml b/sale_pricelist_from_commitment_date/views/res_config_settings_views.xml new file mode 100644 index 00000000..17457a12 --- /dev/null +++ b/sale_pricelist_from_commitment_date/views/res_config_settings_views.xml @@ -0,0 +1,26 @@ + + + + res.config.settings.view.form.inherit + res.config.settings + + + + + + + + + + + + + diff --git a/sale_pricelist_from_commitment_date/views/sale_order_views.xml b/sale_pricelist_from_commitment_date/views/sale_order_views.xml new file mode 100644 index 00000000..1cf0555e --- /dev/null +++ b/sale_pricelist_from_commitment_date/views/sale_order_views.xml @@ -0,0 +1,18 @@ + + + sale.order.form.inherit.show.commitment_date + sale.order + + + + + + + + + +