diff --git a/delivery_carrier_manual_price/README.rst b/delivery_carrier_manual_price/README.rst new file mode 100644 index 0000000000..209f7e7783 --- /dev/null +++ b/delivery_carrier_manual_price/README.rst @@ -0,0 +1,84 @@ +============================= +Delivery Carrier Manual Price +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:608ecbf041689e42589bbb1b2ef567ad875bce40970e796ba23594c9169ae942 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.0/delivery_carrier_manual_price + :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-16-0/delivery-carrier-16-0-delivery_carrier_manual_price + :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=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module adds a flag in Shipping Methods to allow to set their cost manually +in each Sales Order. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +When adding the shipping method in a sales order, the cost will be editable for +methods marked with the flag 'Manual Price'. + +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 +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Jordi Masvidal +* Marina Alapont + +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/delivery_carrier_manual_price/__init__.py b/delivery_carrier_manual_price/__init__.py new file mode 100644 index 0000000000..e56f916687 --- /dev/null +++ b/delivery_carrier_manual_price/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import models +from . import wizard diff --git a/delivery_carrier_manual_price/__manifest__.py b/delivery_carrier_manual_price/__manifest__.py new file mode 100644 index 0000000000..170ff36fc7 --- /dev/null +++ b/delivery_carrier_manual_price/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +{ + "name": "Delivery Carrier Manual Price", + "summary": "Allow setting manual shipping cost in sale order.", + "version": "16.0.1.0.0", + "category": "Delivery", + "website": "https://github.com/OCA/delivery-carrier", + "author": "ForgeFlow,Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": [ + "delivery", + ], + "data": ["wizard/choose_delivery_carrier_views.xml", "views/delivery_view.xml"], + "application": False, + "installable": True, +} diff --git a/delivery_carrier_manual_price/models/__init__.py b/delivery_carrier_manual_price/models/__init__.py new file mode 100644 index 0000000000..205cd401eb --- /dev/null +++ b/delivery_carrier_manual_price/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import delivery_carrier +from . import sale_order diff --git a/delivery_carrier_manual_price/models/delivery_carrier.py b/delivery_carrier_manual_price/models/delivery_carrier.py new file mode 100644 index 0000000000..062715c0ef --- /dev/null +++ b/delivery_carrier_manual_price/models/delivery_carrier.py @@ -0,0 +1,10 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class DeliveryCarrier(models.Model): + _inherit = "delivery.carrier" + + is_manual_price = fields.Boolean(string="Manual Price") diff --git a/delivery_carrier_manual_price/models/sale_order.py b/delivery_carrier_manual_price/models/sale_order.py new file mode 100644 index 0000000000..979da79459 --- /dev/null +++ b/delivery_carrier_manual_price/models/sale_order.py @@ -0,0 +1,15 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + @api.onchange("order_line", "partner_id", "partner_shipping_id") + def onchange_order_line(self): + res = super().onchange_order_line() + if self.carrier_id and self.carrier_id.is_manual_price: + self.recompute_delivery_price = False + return res diff --git a/delivery_carrier_manual_price/readme/CONTRIBUTORS.rst b/delivery_carrier_manual_price/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..d712c6d272 --- /dev/null +++ b/delivery_carrier_manual_price/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Jordi Masvidal +* Marina Alapont diff --git a/delivery_carrier_manual_price/readme/DESCRIPTION.rst b/delivery_carrier_manual_price/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..8753c9dec8 --- /dev/null +++ b/delivery_carrier_manual_price/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module adds a flag in Shipping Methods to allow to set their cost manually +in each Sales Order. diff --git a/delivery_carrier_manual_price/readme/USAGE.rst b/delivery_carrier_manual_price/readme/USAGE.rst new file mode 100644 index 0000000000..b4d7bd450c --- /dev/null +++ b/delivery_carrier_manual_price/readme/USAGE.rst @@ -0,0 +1,2 @@ +When adding the shipping method in a sales order, the cost will be editable for +methods marked with the flag 'Manual Price'. diff --git a/delivery_carrier_manual_price/static/description/icon.png b/delivery_carrier_manual_price/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/delivery_carrier_manual_price/static/description/icon.png differ diff --git a/delivery_carrier_manual_price/static/description/index.html b/delivery_carrier_manual_price/static/description/index.html new file mode 100644 index 0000000000..a1aee7ce84 --- /dev/null +++ b/delivery_carrier_manual_price/static/description/index.html @@ -0,0 +1,428 @@ + + + + + +Delivery Carrier Manual Price + + + +
+

Delivery Carrier Manual Price

+ + +

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

+

This module adds a flag in Shipping Methods to allow to set their cost manually +in each Sales Order.

+

Table of contents

+ +
+

Usage

+

When adding the shipping method in a sales order, the cost will be editable for +methods marked with the flag ‘Manual Price’.

+
+
+

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

+
    +
  • ForgeFlow
  • +
+
+
+

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/delivery_carrier_manual_price/tests/__init__.py b/delivery_carrier_manual_price/tests/__init__.py new file mode 100644 index 0000000000..c08fa17a38 --- /dev/null +++ b/delivery_carrier_manual_price/tests/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from . import test_delivery_carrier_manual_price diff --git a/delivery_carrier_manual_price/tests/test_delivery_carrier_manual_price.py b/delivery_carrier_manual_price/tests/test_delivery_carrier_manual_price.py new file mode 100644 index 0000000000..14d1e0c423 --- /dev/null +++ b/delivery_carrier_manual_price/tests/test_delivery_carrier_manual_price.py @@ -0,0 +1,72 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo.tests import Form +from odoo.tests.common import TransactionCase + + +class TestDeliveryCarrierManualPrice(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + product_shipping_cost = cls.env["product.product"].create( + { + "type": "service", + "name": "Shipping costs", + "standard_price": 10, + "list_price": 100, + } + ) + cls.carrier = cls.env["delivery.carrier"].create( + { + "name": "Test carrier", + "delivery_type": "fixed", + "product_id": product_shipping_cost.id, + "fixed_price": 50, + "is_manual_price": True, + } + ) + cls.product = cls.env["product.product"].create( + {"name": "Test product", "type": "product"} + ) + cls.partner = cls.env["res.partner"].create({"name": "Test Partner"}) + cls.sale = cls.env["sale.order"].create( + { + "partner_id": cls.partner.id, + "order_line": [ + ( + 0, + 0, + { + "product_id": cls.product.id, + "product_uom_qty": 1, + "price_unit": 10, + }, + ) + ], + } + ) + + def test_delivery_carrier_manual_price(self): + delivery_wizard = Form( + self.env["choose.delivery.carrier"].with_context( + **{"default_order_id": self.sale.id, "default_carrier_id": self.carrier} + ) + ) + choose_delivery_carrier = delivery_wizard.save() + self.assertEqual(choose_delivery_carrier.delivery_price, 50) + with Form( + choose_delivery_carrier, + view="delivery_carrier_manual_price.choose_delivery_carrier_view_form", + ) as form: + form.delivery_price = 70 + choose_delivery_carrier.button_confirm() + delivery_lines = self.sale.order_line.filtered(lambda line: line.is_delivery) + delivery_price = sum(delivery_lines.mapped("price_unit")) + self.assertEqual(delivery_price, 70) + self.assertEqual(len(delivery_lines), 1) + # Modify sale line and check recompute_delivery_price + line = self.sale.order_line.filtered( + lambda line: line.product_id == self.product + ) + line.price_unit = 20 + self.assertFalse(self.sale.recompute_delivery_price) diff --git a/delivery_carrier_manual_price/views/delivery_view.xml b/delivery_carrier_manual_price/views/delivery_view.xml new file mode 100644 index 0000000000..4a8189b0f6 --- /dev/null +++ b/delivery_carrier_manual_price/views/delivery_view.xml @@ -0,0 +1,32 @@ + + + + delivery.carrier.form - delivery_carrier_manual_price + delivery.carrier + + + + + + + + + sale.order.form - delivery_carrier_manual_price + sale.order + + + + 1 + + + 1 + + + + diff --git a/delivery_carrier_manual_price/wizard/__init__.py b/delivery_carrier_manual_price/wizard/__init__.py new file mode 100644 index 0000000000..19469a826b --- /dev/null +++ b/delivery_carrier_manual_price/wizard/__init__.py @@ -0,0 +1,3 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import choose_delivery_carrier diff --git a/delivery_carrier_manual_price/wizard/choose_delivery_carrier.py b/delivery_carrier_manual_price/wizard/choose_delivery_carrier.py new file mode 100644 index 0000000000..83a05ec563 --- /dev/null +++ b/delivery_carrier_manual_price/wizard/choose_delivery_carrier.py @@ -0,0 +1,10 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ChooseDeliveryCarrier(models.TransientModel): + _inherit = "choose.delivery.carrier" + + is_manual_price = fields.Boolean(related="carrier_id.is_manual_price") diff --git a/delivery_carrier_manual_price/wizard/choose_delivery_carrier_views.xml b/delivery_carrier_manual_price/wizard/choose_delivery_carrier_views.xml new file mode 100644 index 0000000000..431b615e94 --- /dev/null +++ b/delivery_carrier_manual_price/wizard/choose_delivery_carrier_views.xml @@ -0,0 +1,31 @@ + + + + choose.delivery.carrier.form - delivery_carrier_manual_price + choose.delivery.carrier + + + + + + + 0 + {'invisible': [('is_manual_price','=', False)]} + monetary + {'currency_field': 'currency_id'} + + + {'invisible': ['|', ('carrier_id','=', False), ('is_manual_price','=', True)]} + + + + + + + diff --git a/setup/delivery_carrier_manual_price/odoo/addons/delivery_carrier_manual_price b/setup/delivery_carrier_manual_price/odoo/addons/delivery_carrier_manual_price new file mode 120000 index 0000000000..407aad8e7a --- /dev/null +++ b/setup/delivery_carrier_manual_price/odoo/addons/delivery_carrier_manual_price @@ -0,0 +1 @@ +../../../../delivery_carrier_manual_price \ No newline at end of file diff --git a/setup/delivery_carrier_manual_price/setup.py b/setup/delivery_carrier_manual_price/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/delivery_carrier_manual_price/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)