Skip to content

Commit

Permalink
Updated test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteMeAsap committed Sep 20, 2024
1 parent bd845df commit 907db62
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions delivery_sendcloud_oca/tests/test_delivery_sendcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from odoo import fields
from odoo.exceptions import UserError, ValidationError
from odoo.tests import Form, TransactionCase,tagged
from odoo.tests import Form, TransactionCase
from odoo.tools import mute_logger

_super_send = requests.Session.send
Expand All @@ -26,7 +26,7 @@
decode_compressed_response=True,
)

@tagged("post_install", "-at_install")

class TestDeliverySendCloud(TransactionCase):
@classmethod
def _request_handler(cls, s, r, /, **kw):
Expand Down Expand Up @@ -181,8 +181,15 @@ def rollback():
force_sendcloud_shipment_code="c9b2058d-2621-4ce5-afb0-f14e8e5565b6"
).action_confirm()
# Set HS code and confirm order
sale_order.mapped("order_line").mapped("product_id").mapped("product_tmpl_id").write({"hs_code": "123"})
_logger.info(("Hs codes %s",sale_order.mapped("order_line").mapped("product_id").mapped("product_tmpl_id").mapped("hs_code")))
is_product_harmonized_system_installed = self.env["ir.module.module"].search(
[("name", "=", "product_harmonized_system"), ("state", "=", "installed")],
limit=1,
)
if is_product_harmonized_system_installed:
sale_order.mapped("order_line.product_id").write(
{"hs_code_id": self.env.ref("product_harmonized_system.84715000").id})
else:
sale_order.mapped("order_line.product_id").write({"hs_code": "123"})
with rollback():
# Origin Country consistency
with self.assertRaisesRegex(
Expand All @@ -194,9 +201,11 @@ def rollback():
force_sendcloud_shipment_code="c9b2058d-2621-4ce5-afb0-f14e8e5565b6"
).action_confirm()
# Set country_of_origin and confirm order
sale_order.mapped("order_line").mapped("product_id").write(
{"country_of_origin": sale_order.warehouse_id.partner_id.country_id}
)
if is_product_harmonized_system_installed:
sale_order.mapped("order_line.product_id").write(
{"origin_country_id": sale_order.warehouse_id.partner_id.country_id})
else:
sale_order.mapped("order_line.product_id").write({"country_of_origin": sale_order.warehouse_id.partner_id.country_id})
with recorder.use_cassette("shipping_02"):
sale_order.with_context(
force_sendcloud_shipment_code="c9b2058d-2621-4ce5-afb0-f14e8e5565b6"
Expand Down Expand Up @@ -394,12 +403,17 @@ def test_10_auto_create_invoice(self):
# Sale order to outside EU
sale_order = self.env.ref("sale.sale_order_1").copy()
self.assertEqual(sale_order.partner_id.country_id.code, "US")
sale_order.mapped("order_line").mapped("product_id").mapped("product_tmpl_id").write(
{
"hs_code": "123",
"country_of_origin": sale_order.warehouse_id.partner_id.country_id,
}
is_product_harmonized_system_installed = self.env["ir.module.module"].search(
[("name", "=", "product_harmonized_system"), ("state", "=", "installed")],
limit=1,
)
if is_product_harmonized_system_installed:
sale_order.mapped("order_line.product_id").write(
{"hs_code_id": self.env.ref("product_harmonized_system.84715000").id,
"origin_country_id": sale_order.warehouse_id.partner_id.country_id,})
else:
sale_order.mapped("order_line.product_id").write({"hs_code": "123",
"country_of_origin": sale_order.warehouse_id.partner_id.country_id,})

# Enable "Auto create invoice"
sale_order.company_id.sendcloud_auto_create_invoice = True
Expand Down

0 comments on commit 907db62

Please sign in to comment.