From 0fe78c01d9b7685528dfeea4fb54f5389f377df8 Mon Sep 17 00:00:00 2001 From: Walid Date: Wed, 12 Jul 2023 10:36:06 +0000 Subject: [PATCH] [FIX] website_sale_delivery: correct adress states Steps to reproduce: - set shipping methods country to mexico (empty states) - fill an order on website on check out select seprate shipping/billing - on billing set country as US - on shipping the only country avialable is mexico - avialable states are the ones from the US not mexico Bug: the states are set from the country of the customer even though it isn't an option on any carrier. bug was introduced by this commit[1] Fix: revert the mentioned commit(1) since a new commit[2] was introduced that correctly handles that use case too [1]:https://github.com/odoo/odoo/commit/d59fe9c58c2dcc2bf6613adb7ac3662597b50496 [2]:https://github.com/odoo/odoo/commit/297641da69982d6c76bd591296636b479cabf657 opw-3230361 closes odoo/odoo#128349 X-original-commit: c59bc765f186858bffb642987cd88fcb80fe262a Signed-off-by: Walid Hanniche (waha) Signed-off-by: William Henrotin (whe) --- addons/website_sale/models/res_country.py | 2 -- .../tests/test_delivery_controller.py | 22 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/addons/website_sale/models/res_country.py b/addons/website_sale/models/res_country.py index 06b0f8285e7..aab125e7823 100644 --- a/addons/website_sale/models/res_country.py +++ b/addons/website_sale/models/res_country.py @@ -34,7 +34,5 @@ class ResCountry(models.Model): states = res break states |= carrier.state_ids - if not states: - states = states.search([('country_id', '=', self.id)]) res = res & states return res diff --git a/addons/website_sale/tests/test_delivery_controller.py b/addons/website_sale/tests/test_delivery_controller.py index a346647af11..90f6484d61e 100644 --- a/addons/website_sale/tests/test_delivery_controller.py +++ b/addons/website_sale/tests/test_delivery_controller.py @@ -34,3 +34,25 @@ class TestWebsiteSaleDeliveryController(PaymentCommon): order = self.website.sale_get_order(force_create=True) order.transaction_ids = self._create_transaction(flow='redirect', state='draft') self.Controller.update_eshop_carrier(carrier_id=1) + + def test_address_states(self): + US = self.env.ref('base.us') + MX = self.env.ref('base.mx') + + # Set all carriers to mexico + self.env['delivery.carrier'].sudo().search([('website_published', '=', True)]).country_ids = [(6, 0, [MX.id])] + + # Create a new carrier to only one state in mexico + self.env['delivery.carrier'].create({ + 'name': "One_state", + 'product_id': self.env['product.product'].create({'name': "delivery product"}).id, + 'website_published': True, + 'country_ids': [(6, 0, [MX.id])], + 'state_ids': [(6, 0, [MX.state_ids.ids[0]])] + }) + + country_info = self.Controller.country_infos(country=MX, mode="shipping") + self.assertEqual(len(country_info['states']), len(MX.state_ids)) + + country_info = self.Controller.country_infos(country=US, mode="shipping") + self.assertEqual(len(country_info['states']), 0)