Skip to content

Commit

Permalink
[WIP]delivery_postlogistics:Migrated to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
KAG authored and RUS committed Feb 5, 2025
1 parent f9389fe commit d6702a9
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 28 deletions.
45 changes: 22 additions & 23 deletions delivery_postlogistics/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ See `Log in <https://account.post.ch/selfadmin/?login&lang=en>`__

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
--------------------
Expand All @@ -74,11 +73,11 @@ documentation <https://www.post.ch/en/business/a-z-of-subjects/dropping-off-mail
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.
- 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.

Bug Tracker
===========
Expand All @@ -101,31 +100,31 @@ Authors
Contributors
------------

- Yannick Vaucher <[email protected]>
- Yannick Vaucher <[email protected]>

- Guewen Baconnier <[email protected]>
- Guewen Baconnier <[email protected]>

- Akim Juillerat <[email protected]>
- Akim Juillerat <[email protected]>

- Julien Coux <[email protected]>
- Julien Coux <[email protected]>

- Dung Tran <[email protected]>
- Dung Tran <[email protected]>

- Phuc Tran <[email protected]>
- Phuc Tran <[email protected]>

- Jacques-Etienne Baudoux <[email protected]>
- Jacques-Etienne Baudoux <[email protected]>

- `Trobz <https://trobz.com>`__:
- `Trobz <https://trobz.com>`__:

- Jack Le <[email protected]>
- Jack Le <[email protected]>

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
-----------
Expand Down
7 changes: 3 additions & 4 deletions delivery_postlogistics/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<li>Go to Inventory -&gt; Configuration -&gt; Delivery -&gt; Delivery Packages to
create the PostLogistics delivery packaging with the relevant Package
Code (see section 8.10 of
<a class="reference external" href="https://developer.post.ch/en/digital-commerce-api">https://developer.post.ch/en/digital-commerce-api</a> for available
codes)</li>
<a class="reference external" href="https://developer.post.ch/en/digital-commerce-api">https://developer.post.ch/en/digital-commerce-api</a> for available codes)</li>
</ul>
<div class="section" id="technical-references">
<h2><a class="toc-backref" href="#toc-entry-2">Technical references</a></h2>
Expand All @@ -424,8 +423,8 @@ <h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
<li>Integration of price webservice :
<a class="reference external" href="https://www.post.ch/en/customer-center/all-online-services/preise-berechnen/info">https://www.post.ch/en/customer-center/all-online-services/preise-berechnen/info</a></li>
<li>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.</li>
need to use the integration WS anymore. However we still want to patch
open to get meaningful error messages.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
Expand Down
2 changes: 2 additions & 0 deletions delivery_postlogistics/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions delivery_postlogistics/tests/test_packaging_code.py
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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])
2 changes: 1 addition & 1 deletion delivery_postlogistics/tests/test_postlogistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
118 changes: 118 additions & 0 deletions delivery_postlogistics/tests/test_stock_move.py
Original file line number Diff line number Diff line change
@@ -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.",
)
46 changes: 46 additions & 0 deletions delivery_postlogistics/tests/test_stock_picking.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit d6702a9

Please sign in to comment.