diff --git a/sale_order_warehouse_from_delivery_carrier/README.rst b/sale_order_warehouse_from_delivery_carrier/README.rst new file mode 100644 index 0000000000..3c68e5c8c0 --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/README.rst @@ -0,0 +1,102 @@ +========================================== +Sale Order Warehouse from Delivery Carrier +========================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:31d3be7a7aeddf2a3958be40ec29b0f17389652da8bcf1460e6e3369346624a7 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fdelivery--carrier-lightgray.png?logo=github + :target: https://github.com/OCA/delivery-carrier/tree/17.0/sale_order_warehouse_from_delivery_carrier + :alt: OCA/delivery-carrier +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/delivery-carrier-17-0/delivery-carrier-17-0-sale_order_warehouse_from_delivery_carrier + :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/delivery-carrier&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to set warehouse in Sales Order based on selected +shipping method. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Go to Sales -> Settings -> Shipping methods and select a shipping method + +Set warehouse in the "Sales Order Warehouse" field. + +Usage +===== + +Create a new quotation and select a shipping method. + +If selected shipping method has a sales order warehouse defined this +warehouse will be automatically set in the quotation. + +**Note**: The warehouse will NOT be updated if the sales order is +already confirmed. + +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 +------- + +* Cetmix + +Contributors +------------ + +- Cetmix + + - Ivan Sokolov + - Maksim Shurupov + +- Codeforward (https://www.codeforward.nl): + + - Sander Lienaerts sander.lienaerts@codeforward.nl + +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/delivery-carrier `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sale_order_warehouse_from_delivery_carrier/__init__.py b/sale_order_warehouse_from_delivery_carrier/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_order_warehouse_from_delivery_carrier/__manifest__.py b/sale_order_warehouse_from_delivery_carrier/__manifest__.py new file mode 100644 index 0000000000..411eabcf41 --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/__manifest__.py @@ -0,0 +1,14 @@ +{ + "name": "Sale Order Warehouse from Delivery Carrier", + "version": "17.0.1.0.0", + "category": "Delivery", + "summary": "Sale Order WH from Delivery Carrier", + "depends": ["sale_stock", "delivery"], + "website": "https://github.com/OCA/delivery-carrier", + "author": "Cetmix, Odoo Community Association (OCA)", + "data": [ + "views/delivery_carrier_views.xml", + ], + "installable": True, + "license": "AGPL-3", +} diff --git a/sale_order_warehouse_from_delivery_carrier/i18n/it.po b/sale_order_warehouse_from_delivery_carrier/i18n/it.po new file mode 100644 index 0000000000..e2949d1165 --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/i18n/it.po @@ -0,0 +1,38 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_warehouse_from_delivery_carrier +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-07-30 16:58+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 5.6.2\n" + +#. module: sale_order_warehouse_from_delivery_carrier +#: model:ir.model.fields,help:sale_order_warehouse_from_delivery_carrier.field_delivery_carrier__so_warehouse_id +msgid "Default warehouse for the sales order that uses this delivery carrier" +msgstr "" +"Il magazzino predefinito per gli ordini di vendita che usano questo corriere" + +#. module: sale_order_warehouse_from_delivery_carrier +#: model:ir.model,name:sale_order_warehouse_from_delivery_carrier.model_sale_order +msgid "Sales Order" +msgstr "Ordine di vendita" + +#. module: sale_order_warehouse_from_delivery_carrier +#: model:ir.model.fields,field_description:sale_order_warehouse_from_delivery_carrier.field_delivery_carrier__so_warehouse_id +msgid "Sales Order Warehouse" +msgstr "Magazzino ordine di vendita" + +#. module: sale_order_warehouse_from_delivery_carrier +#: model:ir.model,name:sale_order_warehouse_from_delivery_carrier.model_delivery_carrier +msgid "Shipping Methods" +msgstr "Metodi di spedizione" diff --git a/sale_order_warehouse_from_delivery_carrier/i18n/nl.po b/sale_order_warehouse_from_delivery_carrier/i18n/nl.po new file mode 100644 index 0000000000..f31bd19563 --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/i18n/nl.po @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_warehouse_from_delivery_carrier +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-08-06 07:52+0000\n" +"PO-Revision-Date: 2024-08-06 07:52+0000\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_order_warehouse_from_delivery_carrier +#: model:ir.model.fields,help:sale_order_warehouse_from_delivery_carrier.field_delivery_carrier__so_warehouse_id +msgid "Default warehouse for the sales order that uses this delivery carrier" +msgstr "Standaard magazijn voor de verkooporder die deze verzendwijze gebruikt" + +#. module: sale_order_warehouse_from_delivery_carrier +#: model:ir.model,name:sale_order_warehouse_from_delivery_carrier.model_sale_order +msgid "Sales Order" +msgstr "Verkooporder" + +#. module: sale_order_warehouse_from_delivery_carrier +#: model:ir.model.fields,field_description:sale_order_warehouse_from_delivery_carrier.field_delivery_carrier__so_warehouse_id +msgid "Sales Order Warehouse" +msgstr "Verkooporder magazijn" + +#. module: sale_order_warehouse_from_delivery_carrier +#: model:ir.model,name:sale_order_warehouse_from_delivery_carrier.model_delivery_carrier +msgid "Shipping Methods" +msgstr "Verzendwijzes" diff --git a/sale_order_warehouse_from_delivery_carrier/i18n/sale_order_warehouse_from_delivery_carrier.pot b/sale_order_warehouse_from_delivery_carrier/i18n/sale_order_warehouse_from_delivery_carrier.pot new file mode 100644 index 0000000000..dc337d1ff1 --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/i18n/sale_order_warehouse_from_delivery_carrier.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sale_order_warehouse_from_delivery_carrier +# +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_order_warehouse_from_delivery_carrier +#: model:ir.model.fields,help:sale_order_warehouse_from_delivery_carrier.field_delivery_carrier__so_warehouse_id +msgid "Default warehouse for the sales order that uses this delivery carrier" +msgstr "" + +#. module: sale_order_warehouse_from_delivery_carrier +#: model:ir.model,name:sale_order_warehouse_from_delivery_carrier.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: sale_order_warehouse_from_delivery_carrier +#: model:ir.model.fields,field_description:sale_order_warehouse_from_delivery_carrier.field_delivery_carrier__so_warehouse_id +msgid "Sales Order Warehouse" +msgstr "" + +#. module: sale_order_warehouse_from_delivery_carrier +#: model:ir.model,name:sale_order_warehouse_from_delivery_carrier.model_delivery_carrier +msgid "Shipping Methods" +msgstr "" diff --git a/sale_order_warehouse_from_delivery_carrier/models/__init__.py b/sale_order_warehouse_from_delivery_carrier/models/__init__.py new file mode 100644 index 0000000000..e5fe558510 --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/models/__init__.py @@ -0,0 +1,2 @@ +from . import delivery_carrier +from . import sale_order diff --git a/sale_order_warehouse_from_delivery_carrier/models/delivery_carrier.py b/sale_order_warehouse_from_delivery_carrier/models/delivery_carrier.py new file mode 100644 index 0000000000..9e7021bcfa --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/models/delivery_carrier.py @@ -0,0 +1,11 @@ +from odoo import fields, models + + +class DeliveryCarrier(models.Model): + _inherit = "delivery.carrier" + + so_warehouse_id = fields.Many2one( + comodel_name="stock.warehouse", + string="Sales Order Warehouse", + help="Default warehouse for the sales order that uses this delivery carrier", + ) diff --git a/sale_order_warehouse_from_delivery_carrier/models/sale_order.py b/sale_order_warehouse_from_delivery_carrier/models/sale_order.py new file mode 100644 index 0000000000..a65193a49d --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/models/sale_order.py @@ -0,0 +1,19 @@ +from odoo import api, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + @api.depends("user_id", "company_id", "carrier_id") + def _compute_warehouse_id(self): + # Set warehouse by shipping method + so_with_shipping = self.browse() + for order in self: + if ( + order.state == "draft" + and order.carrier_id + and order.carrier_id.so_warehouse_id + ): + order.warehouse_id = order.carrier_id.so_warehouse_id + so_with_shipping |= order + return super(SaleOrder, self - so_with_shipping)._compute_warehouse_id() diff --git a/sale_order_warehouse_from_delivery_carrier/pyproject.toml b/sale_order_warehouse_from_delivery_carrier/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sale_order_warehouse_from_delivery_carrier/readme/CONFIGURE.md b/sale_order_warehouse_from_delivery_carrier/readme/CONFIGURE.md new file mode 100644 index 0000000000..a97cf8cfda --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/readme/CONFIGURE.md @@ -0,0 +1,4 @@ +Go to Sales -\> Settings -\> Shipping methods and select a shipping +method + +Set warehouse in the "Sales Order Warehouse" field. diff --git a/sale_order_warehouse_from_delivery_carrier/readme/CONTRIBUTORS.md b/sale_order_warehouse_from_delivery_carrier/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..2cbc3bc87a --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- Cetmix \ + - Ivan Sokolov + - Maksim Shurupov +- Codeforward (https://www.codeforward.nl): + - Sander Lienaerts diff --git a/sale_order_warehouse_from_delivery_carrier/readme/DESCRIPTION.md b/sale_order_warehouse_from_delivery_carrier/readme/DESCRIPTION.md new file mode 100644 index 0000000000..e8ae1dc6d7 --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module allows to set warehouse in Sales Order based on selected +shipping method. diff --git a/sale_order_warehouse_from_delivery_carrier/readme/USAGE.md b/sale_order_warehouse_from_delivery_carrier/readme/USAGE.md new file mode 100644 index 0000000000..a8e782346c --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/readme/USAGE.md @@ -0,0 +1,7 @@ +Create a new quotation and select a shipping method. + +If selected shipping method has a sales order warehouse defined this +warehouse will be automatically set in the quotation. + +**Note**: The warehouse will NOT be updated if the sales order is +already confirmed. diff --git a/sale_order_warehouse_from_delivery_carrier/static/description/icon.png b/sale_order_warehouse_from_delivery_carrier/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/sale_order_warehouse_from_delivery_carrier/static/description/icon.png differ diff --git a/sale_order_warehouse_from_delivery_carrier/static/description/index.html b/sale_order_warehouse_from_delivery_carrier/static/description/index.html new file mode 100644 index 0000000000..25e602cdba --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/static/description/index.html @@ -0,0 +1,444 @@ + + + + + +Sale Order Warehouse from Delivery Carrier + + + +
+

Sale Order Warehouse from Delivery Carrier

+ + +

Beta License: AGPL-3 OCA/delivery-carrier Translate me on Weblate Try me on Runboat

+

This module allows to set warehouse in Sales Order based on selected +shipping method.

+

Table of contents

+ +
+

Configuration

+

Go to Sales -> Settings -> Shipping methods and select a shipping method

+

Set warehouse in the “Sales Order Warehouse” field.

+
+
+

Usage

+

Create a new quotation and select a shipping method.

+

If selected shipping method has a sales order warehouse defined this +warehouse will be automatically set in the quotation.

+

Note: The warehouse will NOT be updated if the sales order is +already confirmed.

+
+
+

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

+
    +
  • Cetmix
  • +
+
+
+

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/delivery-carrier project on GitHub.

+

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

+
+
+
+ + diff --git a/sale_order_warehouse_from_delivery_carrier/tests/__init__.py b/sale_order_warehouse_from_delivery_carrier/tests/__init__.py new file mode 100644 index 0000000000..9f0ab2bf10 --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/tests/__init__.py @@ -0,0 +1 @@ +from . import test_module_flow diff --git a/sale_order_warehouse_from_delivery_carrier/tests/test_module_flow.py b/sale_order_warehouse_from_delivery_carrier/tests/test_module_flow.py new file mode 100644 index 0000000000..014d8240b7 --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/tests/test_module_flow.py @@ -0,0 +1,88 @@ +from odoo.tests import Form, TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestModuleFlow(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.local_delivery = cls.env.ref( + "delivery.delivery_local_delivery", raise_if_not_found=False + ) + cls.poste_delivery = cls.env.ref( + "delivery.delivery_carrier", raise_if_not_found=False + ) + cls.warehouse0 = cls.env["stock.warehouse"].create( + { + "name": "Test Warehouse #1", + "code": "TWH-1", + } + ) + cls.warehouse1 = cls.env["stock.warehouse"].create( + { + "name": "Test Warehouse #2", + "code": "TWH-2", + } + ) + cls.local_delivery.write({"so_warehouse_id": cls.warehouse0.id}) + cls.poste_delivery.write({"so_warehouse_id": cls.warehouse1.id}) + cls.saleperson_warehouse = cls.env.user._get_default_warehouse_id() + + form = Form( + cls.env["sale.order"], + ) + form.partner_id = cls.env.ref("base.res_partner_2", raise_if_not_found=False) + with form.order_line.new() as line: + line.product_id = cls.env.ref( + "product.product_product_25", raise_if_not_found=False + ) + cls.sale_order = form.save() + + def _set_shipping_method(self, delivery_method): + form = Form( + self.env["choose.delivery.carrier"].with_context( + default_order_id=self.sale_order.id, + ), + view="delivery.choose_delivery_carrier_view_form", + ) + form.carrier_id = delivery_method + shipping = form.save() + shipping.button_confirm() + + def test_sale_order_warehouse_default(self): + """Test flow when set order warehouse by default""" + self.assertEqual( + self.saleperson_warehouse, + self.sale_order.warehouse_id, + msg="Order Warehouse must be equal to saleperson default warehouse", + ) + + def test_sale_order_warehouse_custom(self): + """Test flow when set order warehouse by 'Shipping Method' record""" + self._set_shipping_method(self.local_delivery) + self.assertEqual( + self.warehouse0, + self.sale_order.warehouse_id, + msg="Order Warehouse must be equal to 'Test Warehouse #1'", + ) + + def test_sale_order_carrier_id_confirmation(self): + """Test flow when change 'Shipping Method' after confirmation""" + self._set_shipping_method(self.local_delivery) + self.assertEqual( + self.sale_order.warehouse_id.id, + self.warehouse0.id, + msg="Order Warehouse must be equal to 'Test Warehouse #1'", + ) + self.sale_order.action_confirm() + self._set_shipping_method(self.poste_delivery) + self.assertNotEqual( + self.sale_order.warehouse_id.id, + self.warehouse1.id, + msg="Order Warehouse must not be equal to 'Test Warehouse #2'", + ) + self.assertEqual( + self.sale_order.warehouse_id.id, + self.warehouse0.id, + msg="Order Warehouse must be equal to 'Test Warehouse #1'", + ) diff --git a/sale_order_warehouse_from_delivery_carrier/views/delivery_carrier_views.xml b/sale_order_warehouse_from_delivery_carrier/views/delivery_carrier_views.xml new file mode 100644 index 0000000000..b85645bf6c --- /dev/null +++ b/sale_order_warehouse_from_delivery_carrier/views/delivery_carrier_views.xml @@ -0,0 +1,15 @@ + + + + + delivery.carrier.so.warehouse.form + delivery.carrier + + + + + + + + +