diff --git a/delivery_postlogistics/README.rst b/delivery_postlogistics/README.rst index e137dcefd5..7265ba1ac2 100644 --- a/delivery_postlogistics/README.rst +++ b/delivery_postlogistics/README.rst @@ -56,14 +56,13 @@ See `Log in `__ To configure: -- Go to Inventory -> Configuration -> Delivery -> Shipping Methods -- Create new shipping methods for PostLogistics and set your login - informations in the "PostLogistics" tab -- Go to Inventory -> Configuration -> Delivery -> Delivery Packages to - create the PostLogistics delivery packaging with the relevant Package - Code (see section 8.10 of - https://developer.post.ch/en/digital-commerce-api for available - codes) +- Go to Inventory -> Configuration -> Delivery -> Shipping Methods +- Create new shipping methods for PostLogistics and set your login + informations in the "PostLogistics" tab +- Go to Inventory -> Configuration -> Delivery -> Delivery Packages to + create the PostLogistics delivery packaging with the relevant Package + Code (see section 8.10 of + https://developer.post.ch/en/digital-commerce-api for available codes) Technical references -------------------- @@ -74,11 +73,11 @@ documentation +- Yannick Vaucher -- Guewen Baconnier +- Guewen Baconnier -- Akim Juillerat +- Akim Juillerat -- Julien Coux +- Julien Coux -- Dung Tran +- Dung Tran -- Phuc Tran +- Phuc Tran -- Jacques-Etienne Baudoux +- Jacques-Etienne Baudoux -- `Trobz `__: +- `Trobz `__: - - Jack Le + - Jack Le Other credits ------------- @@ -125,7 +124,7 @@ Other credits The development of this module in version 14.0 and its migration from 14.0 to 16.0 has been financially supported by: -- Camptocamp +- Camptocamp Maintainers ----------- diff --git a/delivery_postlogistics/static/description/index.html b/delivery_postlogistics/static/description/index.html index ae1e7b2886..fda6d706c2 100644 --- a/delivery_postlogistics/static/description/index.html +++ b/delivery_postlogistics/static/description/index.html @@ -409,8 +409,7 @@

Configuration

  • Go to Inventory -> Configuration -> Delivery -> Delivery Packages to create the PostLogistics delivery packaging with the relevant Package Code (see section 8.10 of -https://developer.post.ch/en/digital-commerce-api for available -codes)
  • +https://developer.post.ch/en/digital-commerce-api for available codes)

    Technical references

    @@ -424,8 +423,8 @@

    Known issues / Roadmap

  • Integration of price webservice : https://www.post.ch/en/customer-center/all-online-services/preise-berechnen/info
  • Not sure if the recursive patch of suds is still needed as there’s no -need to use the integration WS anymore. However we still want to -patch open to get meaningful error messages.
  • +need to use the integration WS anymore. However we still want to patch +open to get meaningful error messages.
    diff --git a/delivery_postlogistics/tests/__init__.py b/delivery_postlogistics/tests/__init__.py index d097ba5c66..95796f92e5 100644 --- a/delivery_postlogistics/tests/__init__.py +++ b/delivery_postlogistics/tests/__init__.py @@ -1,3 +1,5 @@ from . import test_postlogistics from . import test_sanitize_values from . import test_packaging_code +from . import test_stock_picking +from . import test_stock_move diff --git a/delivery_postlogistics/tests/test_packaging_code.py b/delivery_postlogistics/tests/test_packaging_code.py index 60a1754429..c39834e6b3 100644 --- a/delivery_postlogistics/tests/test_packaging_code.py +++ b/delivery_postlogistics/tests/test_packaging_code.py @@ -1,6 +1,7 @@ # Copyright 2022 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +from odoo.exceptions import UserError from odoo.tests import Form, TransactionCase PACKAGE_CODE = "blah-biddy, bloo-blah, blah-blah-biddy, bloo-blah" @@ -42,3 +43,15 @@ def test_shipper_package_code_get_packaging_code(self): package_type.package_carrier_type = self.carrier.delivery_type package_type.shipper_package_code = PACKAGE_CODE self.assertEqual(self.package_type._get_packaging_codes(), EXPECTED_CODES) + + def test_postlogistics_cancel_shipment(self): + self.picking = self.env["stock.picking"].create( + { + "partner_id": self.env.ref("base.partner_demo").id, + "picking_type_id": self.env.ref("stock.picking_type_out").id, + "location_id": self.env.ref("stock.stock_location_stock").id, + "location_dest_id": self.env.ref("stock.stock_location_customers").id, + } + ) + with self.assertRaises(UserError): + self.carrier.postlogistics_cancel_shipment([self.picking]) diff --git a/delivery_postlogistics/tests/test_postlogistics.py b/delivery_postlogistics/tests/test_postlogistics.py index 5756c765de..bed4721436 100644 --- a/delivery_postlogistics/tests/test_postlogistics.py +++ b/delivery_postlogistics/tests/test_postlogistics.py @@ -120,4 +120,4 @@ def test_postlogistics_get_token_error(self): ) with self.assertRaisesRegex(UserError, err_msg): self.service_class._request_access_token(self.carrier) - self.assertEqual(len(cassette.requests), 1) + self.assertEqual(len(cassette.requests), 1) diff --git a/delivery_postlogistics/tests/test_stock_move.py b/delivery_postlogistics/tests/test_stock_move.py new file mode 100644 index 0000000000..758fcfcbc7 --- /dev/null +++ b/delivery_postlogistics/tests/test_stock_move.py @@ -0,0 +1,118 @@ +from odoo import fields + +from .common import TestPostlogisticsCommon + + +class TestStockMove(TestPostlogisticsCommon): + @classmethod + def setUpClass(self): + super().setUpClass() + + res_partner_env = self.env["res.partner"] + product_env = self.env["product.product"] + sale_order_env = self.env["sale.order"] + sale_order_line_env = self.env["sale.order.line"] + stock_picking_env = self.env["stock.picking"] + stock_move_env = self.env["stock.move"] + self.partner = res_partner_env.create( + { + "name": "Test Partner", + "type": "delivery", + "street": "123 Test St.", + "city": "Test City", + "zip": 234567, + "country_id": self.env.ref("base.us").id, + } + ) + + self.product = product_env.create( + { + "name": "Test Product", + "uom_id": self.env.ref("uom.product_uom_unit").id, + } + ) + + self.sale_order = sale_order_env.create( + { + "partner_id": self.partner.id, + "commitment_date": fields.Datetime.now(), + "order_line": [ + ( + 0, + 0, + { + "product_id": self.env.ref("product.product_product_1").id, + "product_uom_qty": 1, + "price_unit": 100, + }, + ) + ], + } + ) + + self.sale_order_line = sale_order_line_env.create( + { + "order_id": self.sale_order.id, + "product_id": self.product.id, + "product_uom_qty": 1, + "price_unit": 100, + } + ) + + self.picking = stock_picking_env.create( + { + "name": "Test Picking", + "sale_id": self.sale_order.id, + "partner_id": self.partner.id, + "picking_type_id": self.env.ref("stock.picking_type_out").id, + "delivery_type": "postlogistics", + } + ) + + self.stock_move = stock_move_env.create( + { + "name": "Test Stock Move", + "product_id": self.product.id, + "product_uom_qty": 1, + "product_uom": self.product.uom_id.id, + "sale_line_id": self.sale_order_line.id, + "picking_id": self.picking.id, + "location_id": self.env.ref("stock.stock_location_stock").id, + "location_dest_id": self.env.ref("stock.stock_location_customers").id, + } + ) + + def test_get_new_picking_values(self): + """Test if 'delivery_fixed_date' is included in the stock move values for a + new picking.""" + stock_move_vals = self.stock_move._get_new_picking_values() + self.assertIn( + "delivery_fixed_date", + stock_move_vals, + "The 'delivery_fixed_date' should be present in the returned values.", + ) + + def test_cod_amount_no_sale_order(self): + """Test COD amount when picking has no linked sale order.""" + picking = self.picking.create( + { + "partner_id": self.env.ref("base.res_partner_1").id, + "location_id": self.env.ref("stock.stock_location_stock").id, + "location_dest_id": self.env.ref("stock.stock_location_customers").id, + "picking_type_id": self.env.ref("stock.picking_type_out").id, + } + ) + self.assertEqual( + picking.postlogistics_cod_amount(), + 0.0, + "COD amount should be 0.0 when no sale order is linked to the picking.", + ) + + def test_cod_amount_single_order_and_picking(self): + """Test COD amount for a single sale order and picking.""" + self.picking.sale_id = self.sale_order + self.assertEqual( + self.picking.postlogistics_cod_amount(), + self.sale_order.amount_total, + "The COD amount should match the total amount of the sale order.", + ) diff --git a/delivery_postlogistics/tests/test_stock_picking.py b/delivery_postlogistics/tests/test_stock_picking.py new file mode 100644 index 0000000000..12c2b300c8 --- /dev/null +++ b/delivery_postlogistics/tests/test_stock_picking.py @@ -0,0 +1,46 @@ +from odoo.exceptions import UserError + +from .common import TestPostlogisticsCommon + + +class TestStockPicking(TestPostlogisticsCommon): + @classmethod + def setUpClass(self): + super().setUpClass() + + res_partner_env = self.env["res.partner"] + stock_picking_env = self.env["stock.picking"] + product_env = self.env["product.product"] + delivery_carrier_env = self.env["delivery.carrier"] + + self.partner = res_partner_env.create( + { + "name": "Test Partner", + "street": "123 Test St.", + "city": "Test City", + "zip": 234567, + "country_id": self.env.ref("base.us").id, + } + ) + self.picking = stock_picking_env.create( + { + "name": "Test Picking", + "delivery_type": "postlogistics", + "picking_type_id": self.env.ref("stock.picking_type_out").id, + "partner_id": self.partner.id, + } + ) + self.product = product_env.create({"name": "Test Product"}) + self.carrier = delivery_carrier_env.create( + { + "name": "PostLogistics", + "delivery_type": "postlogistics", + "product_id": self.product.id, + } + ) + + def test_action_generate_carrier_label_no_carrier(self): + """Test that an error is raised when generating a carrier label without a + carrier.""" + with self.assertRaisesRegex(UserError, "Please, set a carrier."): + self.picking.action_generate_carrier_label()