diff --git a/rma_delivery/README.rst b/rma_delivery/README.rst new file mode 100644 index 00000000..10ad0aff --- /dev/null +++ b/rma_delivery/README.rst @@ -0,0 +1,109 @@ +================================================================== +Return Merchandise Authorization Management - Link with deliveries +================================================================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Frma-lightgray.png?logo=github + :target: https://github.com/OCA/rma/tree/13.0/rma_delivery + :alt: OCA/rma +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/rma-13-0/rma-13-0-rma_delivery + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/145/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of the RMA module to allow to choose a default +behavior for the shipping method used on the RMA returns to the customer. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To configure RMAs shipping strategy for your company: + +#. Go to *Inventory > Configuration > Settings* +#. Choose an *RMA delivery method strategy*. +#. There are 3 possibilities: + + - Fixed method: the method will always be the same. Select it on the field *Default RMA delivery method* + (or leave it empty for no delivery method at all). + - Customer method: the method will be the one configured on the partner. + - Mixed method: the method will be the one configured on the partner, otherwise + the fixed one will be chosen. + +Usage +===== + +To use this module, you need to: + +#. Go to a RMA which has received quantities. +#. Return it to the customer. +#. Depending on your company configuration, the return picking will get one or another + carrier. + +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 `_: + + * David Vidal + +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. + +.. |maintainer-chienandalu| image:: https://github.com/chienandalu.png?size=40px + :target: https://github.com/chienandalu + :alt: chienandalu + +Current `maintainer `__: + +|maintainer-chienandalu| + +This module is part of the `OCA/rma `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/rma_delivery/__init__.py b/rma_delivery/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/rma_delivery/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/rma_delivery/__manifest__.py b/rma_delivery/__manifest__.py new file mode 100644 index 00000000..29327487 --- /dev/null +++ b/rma_delivery/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2022 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Return Merchandise Authorization Management - Link with deliveries", + "summary": "Allow to choose a default delivery carrier for returns", + "version": "13.0.1.0.0", + "development_status": "Beta", + "category": "RMA", + "website": "https://github.com/OCA/rma", + "author": "Tecnativa, Odoo Community Association (OCA)", + "maintainers": ["chienandalu"], + "license": "AGPL-3", + "depends": ["rma", "delivery"], + "data": ["views/res_config_settings_views.xml"], +} diff --git a/rma_delivery/models/__init__.py b/rma_delivery/models/__init__.py new file mode 100644 index 00000000..45a22220 --- /dev/null +++ b/rma_delivery/models/__init__.py @@ -0,0 +1,3 @@ +from . import res_company +from . import res_config_settings +from . import rma diff --git a/rma_delivery/models/res_company.py b/rma_delivery/models/res_company.py new file mode 100644 index 00000000..35da2ad9 --- /dev/null +++ b/rma_delivery/models/res_company.py @@ -0,0 +1,21 @@ +# Copyright 2022 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class Company(models.Model): + _inherit = "res.company" + + rma_delivery_strategy = fields.Selection( + selection=[ + ("fixed_method", "Fixed method"), + ("customer_method", "Customer method"), + ("mixed_method", "Customer method (fallback to fixed)"), + ], + string="RMA delivery method strategy", + default="mixed_method", + ) + rma_fixed_delivery_method = fields.Many2one( + comodel_name="delivery.carrier", string="Default RMA delivery method", + ) diff --git a/rma_delivery/models/res_config_settings.py b/rma_delivery/models/res_config_settings.py new file mode 100644 index 00000000..5ce7c490 --- /dev/null +++ b/rma_delivery/models/res_config_settings.py @@ -0,0 +1,14 @@ +# Copyright 2022 Tecnativa - David Vidal +# 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" + + rma_delivery_strategy = fields.Selection( + related="company_id.rma_delivery_strategy", readonly=False, + ) + rma_fixed_delivery_method = fields.Many2one( + related="company_id.rma_fixed_delivery_method", readonly=False, + ) diff --git a/rma_delivery/models/rma.py b/rma_delivery/models/rma.py new file mode 100644 index 00000000..c7008741 --- /dev/null +++ b/rma_delivery/models/rma.py @@ -0,0 +1,41 @@ +# Copyright 2022 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import models + + +class Rma(models.Model): + _inherit = "rma" + + def _get_default_carrier_id(self, company, partner): + """Gather the company option for default carrier on RMA returns. We could + either: + - Get a fixed method + - Get the partner's defined method (or his commercial entity one) + - Get the partner's and fallback to a fixed one if defined + """ + strategy = company.rma_delivery_strategy + delivery_method = company.rma_fixed_delivery_method + partner_method = ( + partner.property_delivery_carrier_id + or partner.commercial_partner_id.property_delivery_carrier_id + ) + if strategy == "customer_method" or ( + strategy == "mixed_method" and partner_method + ): + delivery_method = partner_method + return delivery_method + + def _prepare_returning_picking(self, picking_form, origin=None): + super()._prepare_returning_picking(picking_form, origin) + picking_form.carrier_id = self._get_default_carrier_id( + picking_form.company_id, picking_form.partner_id + ) + + def create_replace(self, scheduled_date, warehouse, product, qty, uom): + existing_pickings = self.delivery_move_ids.mapped("picking_id") + super().create_replace(scheduled_date, warehouse, product, qty, uom) + new_pickings = self.delivery_move_ids.mapped("picking_id") - existing_pickings + for picking in new_pickings: + picking.carrier_id = self._get_default_carrier_id( + picking.company_id, picking.partner_id + ) diff --git a/rma_delivery/readme/CONFIGURE.rst b/rma_delivery/readme/CONFIGURE.rst new file mode 100644 index 00000000..6e22c8a4 --- /dev/null +++ b/rma_delivery/readme/CONFIGURE.rst @@ -0,0 +1,11 @@ +To configure RMAs shipping strategy for your company: + +#. Go to *Inventory > Configuration > Settings* +#. Choose an *RMA delivery method strategy*. +#. There are 3 possibilities: + + - Fixed method: the method will always be the same. Select it on the field *Default RMA delivery method* + (or leave it empty for no delivery method at all). + - Customer method: the method will be the one configured on the partner. + - Mixed method: the method will be the one configured on the partner, otherwise + the fixed one will be chosen. diff --git a/rma_delivery/readme/CONTRIBUTORS.rst b/rma_delivery/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..94b6ba95 --- /dev/null +++ b/rma_delivery/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Tecnativa `_: + + * David Vidal diff --git a/rma_delivery/readme/DESCRIPTION.rst b/rma_delivery/readme/DESCRIPTION.rst new file mode 100644 index 00000000..035dc0cd --- /dev/null +++ b/rma_delivery/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module extends the functionality of the RMA module to allow to choose a default +behavior for the shipping method used on the RMA returns to the customer. diff --git a/rma_delivery/readme/USAGE.rst b/rma_delivery/readme/USAGE.rst new file mode 100644 index 00000000..c6feea28 --- /dev/null +++ b/rma_delivery/readme/USAGE.rst @@ -0,0 +1,6 @@ +To use this module, you need to: + +#. Go to a RMA which has received quantities. +#. Return it to the customer. +#. Depending on your company configuration, the return picking will get one or another + carrier. diff --git a/rma_delivery/static/description/index.html b/rma_delivery/static/description/index.html new file mode 100644 index 00000000..2c7d4e5a --- /dev/null +++ b/rma_delivery/static/description/index.html @@ -0,0 +1,453 @@ + + + + + + +Return Merchandise Authorization Management - Link with deliveries + + + + + + diff --git a/rma_delivery/tests/__init__.py b/rma_delivery/tests/__init__.py new file mode 100644 index 00000000..d85e9676 --- /dev/null +++ b/rma_delivery/tests/__init__.py @@ -0,0 +1 @@ +from . import test_rma_delivery diff --git a/rma_delivery/tests/test_rma_delivery.py b/rma_delivery/tests/test_rma_delivery.py new file mode 100644 index 00000000..cd0efef2 --- /dev/null +++ b/rma_delivery/tests/test_rma_delivery.py @@ -0,0 +1,142 @@ +# Copyright 2022 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.tests import Form + +from odoo.addons.rma.tests.test_rma import TestRma + + +class TestRmaDelivery(TestRma): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.carrier_product = cls.product_product.create( + {"name": "Delivery product test 1", "type": "service"} + ) + cls.replace_product = cls.product_product.create( + {"name": "Replace product test 1", "type": "product"} + ) + cls.carrier = cls.env["delivery.carrier"].create( + { + "name": "Test Fixed delivery method", + "product_id": cls.carrier_product.id, + } + ) + cls.carrier_customer = cls.env["delivery.carrier"].create( + { + "name": "Test Customer delivery method", + "product_id": cls.carrier_product.id, + } + ) + cls.partner.property_delivery_carrier_id = cls.carrier_customer + cls.partner_shipping.property_delivery_carrier_id = False + cls.company.rma_fixed_delivery_method = cls.carrier + + def _return_to_customer(self, rma, delivery_type="return"): + """Helper to return the rma""" + delivery_form = Form( + self.env["rma.delivery.wizard"].with_context( + active_ids=rma.ids, rma_delivery_type=delivery_type, + ) + ) + if delivery_type == "replace": + delivery_form.product_id = self.replace_product + delivery_form.product_uom_qty = 1 + delivery_wizard = delivery_form.save() + delivery_wizard.action_deliver() + return rma.delivery_move_ids.picking_id + + def test_01_fixed_method(self): + """Fixed method. RMA gets the company default carrier""" + # Return picking + rma = self._create_confirm_receive( + self.partner_shipping, self.product, 1, self.rma_loc + ) + self.company.rma_delivery_strategy = "fixed_method" + picking = self._return_to_customer(rma) + self.assertEqual( + picking.carrier_id, + self.carrier, + "The carrier isn't the one set in the company as default", + ) + # Replace picking + rma = self._create_confirm_receive( + self.partner_shipping, self.product, 1, self.rma_loc + ) + picking = self._return_to_customer(rma, "replace") + self.assertEqual( + picking.carrier_id, + self.carrier, + "The carrier isn't the one set in the company as default", + ) + + def test_02_customer_method(self): + """Customer method. RMA gets the carrier from the contact""" + # Return picking + rma = self._create_confirm_receive( + self.partner_shipping, self.product, 1, self.rma_loc + ) + self.company.rma_delivery_strategy = "customer_method" + picking = self._return_to_customer(rma) + self.assertEqual( + picking.carrier_id, + self.carrier_customer, + "The carrier isn't the same one as in the commercial partner", + ) + carrier_2 = self.env["delivery.carrier"].create( + {"name": "Test delivery method", "product_id": self.carrier_product.id} + ) + self.partner_shipping.property_delivery_carrier_id = carrier_2 + rma = self._create_confirm_receive( + self.partner_shipping, self.product, 1, self.rma_loc + ) + picking = self._return_to_customer(rma) + self.assertEqual( + picking.carrier_id, + carrier_2, + "The carrier isn't the same one as in the picking partner", + ) + # Replace picking + rma = self._create_confirm_receive( + self.partner_shipping, self.product, 1, self.rma_loc + ) + picking = self._return_to_customer(rma, "replace") + self.assertEqual( + picking.carrier_id, + carrier_2, + "The carrier isn't the same one as in the picking partner", + ) + + def test_03_mixed_method(self): + """Mixed method. RMA gets the carrier from the contact otherwise the company + default one""" + # Return picking + rma = self._create_confirm_receive( + self.partner_shipping, self.product, 1, self.rma_loc + ) + self.company.rma_delivery_strategy = "mixed_method" + picking = self._return_to_customer(rma) + self.assertEqual( + picking.carrier_id, + self.carrier_customer, + "The carrier isn't the same one as in the commercial partner", + ) + self.partner.property_delivery_carrier_id = False + rma = self._create_confirm_receive( + self.partner_shipping, self.product, 1, self.rma_loc + ) + picking = self._return_to_customer(rma) + self.assertEqual( + picking.carrier_id, + self.carrier, + "The carrier isn't the one set in the company as default", + ) + # Replace picking + rma = self._create_confirm_receive( + self.partner_shipping, self.product, 1, self.rma_loc + ) + picking = self._return_to_customer(rma, "replace") + self.assertEqual( + picking.carrier_id, + self.carrier, + "The carrier isn't the one set in the company as default", + ) diff --git a/rma_delivery/views/res_config_settings_views.xml b/rma_delivery/views/res_config_settings_views.xml new file mode 100644 index 00000000..8de930ad --- /dev/null +++ b/rma_delivery/views/res_config_settings_views.xml @@ -0,0 +1,44 @@ + + + + res.config.settings + + + +
+
+
+
+ +
+
+
+