summaryrefslogtreecommitdiff
path: root/addons/delivery/tests
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/delivery/tests
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/delivery/tests')
-rw-r--r--addons/delivery/tests/__init__.py5
-rw-r--r--addons/delivery/tests/test_delivery_cost.py157
-rw-r--r--addons/delivery/tests/test_delivery_stock_move.py100
-rw-r--r--addons/delivery/tests/test_packing_delivery.py78
4 files changed, 340 insertions, 0 deletions
diff --git a/addons/delivery/tests/__init__.py b/addons/delivery/tests/__init__.py
new file mode 100644
index 00000000..6a8fb1be
--- /dev/null
+++ b/addons/delivery/tests/__init__.py
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing detailsself.
+
+from . import test_delivery_cost, test_delivery_stock_move
+from . import test_packing_delivery
diff --git a/addons/delivery/tests/test_delivery_cost.py b/addons/delivery/tests/test_delivery_cost.py
new file mode 100644
index 00000000..8353abbd
--- /dev/null
+++ b/addons/delivery/tests/test_delivery_cost.py
@@ -0,0 +1,157 @@
+# -*- coding: utf-8 -*-
+
+from odoo.tests import common, Form
+from odoo.tools import float_compare
+
+
+@common.tagged('post_install', '-at_install')
+class TestDeliveryCost(common.TransactionCase):
+
+ def setUp(self):
+ super(TestDeliveryCost, self).setUp()
+ self.SaleOrder = self.env['sale.order']
+ self.SaleOrderLine = self.env['sale.order.line']
+ self.AccountAccount = self.env['account.account']
+ self.SaleConfigSetting = self.env['res.config.settings']
+ self.Product = self.env['product.product']
+
+ self.partner_18 = self.env['res.partner'].create({'name': 'My Test Customer'})
+ self.pricelist = self.env.ref('product.list0')
+ self.product_4 = self.env['product.product'].create({'name': 'A product to deliver'})
+ self.product_uom_unit = self.env.ref('uom.product_uom_unit')
+ self.product_delivery_normal = self.env['product.product'].create({
+ 'name': 'Normal Delivery Charges',
+ 'type': 'service',
+ 'list_price': 10.0,
+ 'categ_id': self.env.ref('delivery.product_category_deliveries').id,
+ })
+ self.normal_delivery = self.env['delivery.carrier'].create({
+ 'name': 'Normal Delivery Charges',
+ 'fixed_price': 10,
+ 'delivery_type': 'fixed',
+ 'product_id': self.product_delivery_normal.id,
+ })
+ self.partner_4 = self.env['res.partner'].create({'name': 'Another Customer'})
+ self.partner_address_13 = self.env['res.partner'].create({
+ 'name': "Another Customer's Address",
+ 'parent_id': self.partner_4.id,
+ })
+ self.product_uom_hour = self.env.ref('uom.product_uom_hour')
+ self.account_data = self.env.ref('account.data_account_type_revenue')
+ self.account_tag_operating = self.env.ref('account.account_tag_operating')
+ self.product_2 = self.env['product.product'].create({'name': 'Zizizaproduct'})
+ self.product_category = self.env.ref('product.product_category_all')
+ self.free_delivery = self.env.ref('delivery.free_delivery_carrier')
+ # as the tests hereunder assume all the prices in USD, we must ensure
+ # that the company actually uses USD
+ # We do an invalidate_cache so the cache is aware of it too.
+ self.env.cr.execute(
+ "UPDATE res_company SET currency_id = %s WHERE id = %s",
+ [self.env.ref('base.USD').id, self.env.company.id])
+ self.env.company.invalidate_cache()
+ self.pricelist.currency_id = self.env.ref('base.USD').id
+
+ def test_00_delivery_cost(self):
+ # In order to test Carrier Cost
+ # Create sales order with Normal Delivery Charges
+
+ self.sale_normal_delivery_charges = self.SaleOrder.create({
+ 'partner_id': self.partner_18.id,
+ 'partner_invoice_id': self.partner_18.id,
+ 'partner_shipping_id': self.partner_18.id,
+ 'pricelist_id': self.pricelist.id,
+ 'order_line': [(0, 0, {
+ 'name': 'PC Assamble + 2GB RAM',
+ 'product_id': self.product_4.id,
+ 'product_uom_qty': 1,
+ 'product_uom': self.product_uom_unit.id,
+ 'price_unit': 750.00,
+ })],
+ })
+ # I add delivery cost in Sales order
+
+ self.a_sale = self.AccountAccount.create({
+ 'code': 'X2020',
+ 'name': 'Product Sales - (test)',
+ 'user_type_id': self.account_data.id,
+ 'tag_ids': [(6, 0, {
+ self.account_tag_operating.id
+ })]
+ })
+
+ self.product_consultant = self.Product.create({
+ 'sale_ok': True,
+ 'list_price': 75.0,
+ 'standard_price': 30.0,
+ 'uom_id': self.product_uom_hour.id,
+ 'uom_po_id': self.product_uom_hour.id,
+ 'name': 'Service',
+ 'categ_id': self.product_category.id,
+ 'type': 'service'
+ })
+
+ # I add delivery cost in Sales order
+ delivery_wizard = Form(self.env['choose.delivery.carrier'].with_context({
+ 'default_order_id': self.sale_normal_delivery_charges.id,
+ 'default_carrier_id': self.normal_delivery.id
+ }))
+ choose_delivery_carrier = delivery_wizard.save()
+ choose_delivery_carrier.button_confirm()
+
+ # I check sales order after added delivery cost
+
+ line = self.SaleOrderLine.search([('order_id', '=', self.sale_normal_delivery_charges.id),
+ ('product_id', '=', self.normal_delivery.product_id.id)])
+ self.assertEqual(len(line), 1, "Delivery cost is not Added")
+
+ zin = str(delivery_wizard.display_price) + " " + str(delivery_wizard.delivery_price) + ' ' + line.company_id.country_id.code + line.company_id.name
+ self.assertEqual(float_compare(line.price_subtotal, 10.0, precision_digits=2), 0,
+ "Delivery cost does not correspond to 10.0. %s %s" % (line.price_subtotal, zin))
+
+ # I confirm the sales order
+
+ self.sale_normal_delivery_charges.action_confirm()
+
+ # Create one more sales order with Free Delivery Charges
+
+ self.delivery_sale_order_cost = self.SaleOrder.create({
+ 'partner_id': self.partner_4.id,
+ 'partner_invoice_id': self.partner_address_13.id,
+ 'partner_shipping_id': self.partner_address_13.id,
+ 'pricelist_id': self.pricelist.id,
+ 'order_line': [(0, 0, {
+ 'name': 'Service on demand',
+ 'product_id': self.product_consultant.id,
+ 'product_uom_qty': 24,
+ 'product_uom': self.product_uom_hour.id,
+ 'price_unit': 75.00,
+ }), (0, 0, {
+ 'name': 'On Site Assistance',
+ 'product_id': self.product_2.id,
+ 'product_uom_qty': 30,
+ 'product_uom': self.product_uom_hour.id,
+ 'price_unit': 38.25,
+ })],
+ })
+
+ # I add free delivery cost in Sales order
+ delivery_wizard = Form(self.env['choose.delivery.carrier'].with_context({
+ 'default_order_id': self.delivery_sale_order_cost.id,
+ 'default_carrier_id': self.free_delivery.id
+ }))
+ choose_delivery_carrier = delivery_wizard.save()
+ choose_delivery_carrier.button_confirm()
+
+ # I check sales order after adding delivery cost
+ line = self.SaleOrderLine.search([('order_id', '=', self.delivery_sale_order_cost.id),
+ ('product_id', '=', self.free_delivery.product_id.id)])
+
+ self.assertEqual(len(line), 1, "Delivery cost is not Added")
+ self.assertEqual(float_compare(line.price_subtotal, 0, precision_digits=2), 0,
+ "Delivery cost is not correspond.")
+
+ # I set default delivery policy
+
+ self.default_delivery_policy = self.SaleConfigSetting.create({})
+
+ self.default_delivery_policy.execute()
diff --git a/addons/delivery/tests/test_delivery_stock_move.py b/addons/delivery/tests/test_delivery_stock_move.py
new file mode 100644
index 00000000..a9d5b7d5
--- /dev/null
+++ b/addons/delivery/tests/test_delivery_stock_move.py
@@ -0,0 +1,100 @@
+# -*- coding: utf-8 -*-
+
+from odoo.addons.account.tests.common import AccountTestInvoicingCommon
+from odoo.tests import tagged, Form
+
+
+@tagged('post_install', '-at_install')
+class StockMoveInvoice(AccountTestInvoicingCommon):
+
+ @classmethod
+ def setUpClass(cls, chart_template_ref=None):
+ super().setUpClass(chart_template_ref=chart_template_ref)
+
+ cls.ProductProduct = cls.env['product.product']
+ cls.SaleOrder = cls.env['sale.order']
+ cls.AccountJournal = cls.env['account.journal']
+
+ cls.partner_18 = cls.env['res.partner'].create({'name': 'My Test Customer'})
+ cls.pricelist_id = cls.env.ref('product.list0')
+ cls.product_11 = cls.env['product.product'].create({'name': 'A product to deliver'})
+ cls.product_cable_management_box = cls.env['product.product'].create({
+ 'name': 'Another product to deliver',
+ 'weight': 1.0,
+ 'invoice_policy': 'order',
+ })
+ cls.product_uom_unit = cls.env.ref('uom.product_uom_unit')
+ cls.product_delivery_normal = cls.env['product.product'].create({
+ 'name': 'Normal Delivery Charges',
+ 'invoice_policy': 'order',
+ 'type': 'service',
+ 'list_price': 10.0,
+ 'categ_id': cls.env.ref('delivery.product_category_deliveries').id,
+ })
+ cls.normal_delivery = cls.env['delivery.carrier'].create({
+ 'name': 'Normal Delivery Charges',
+ 'fixed_price': 10,
+ 'delivery_type': 'fixed',
+ 'product_id': cls.product_delivery_normal.id,
+ })
+
+ def test_01_delivery_stock_move(self):
+ # Test if the stored fields of stock moves are computed with invoice before delivery flow
+ self.product_11.write({
+ 'weight': 0.25,
+ })
+
+ self.sale_prepaid = self.SaleOrder.create({
+ 'partner_id': self.partner_18.id,
+ 'partner_invoice_id': self.partner_18.id,
+ 'partner_shipping_id': self.partner_18.id,
+ 'pricelist_id': self.pricelist_id.id,
+ 'order_line': [(0, 0, {
+ 'name': 'Cable Management Box',
+ 'product_id': self.product_cable_management_box.id,
+ 'product_uom_qty': 2,
+ 'product_uom': self.product_uom_unit.id,
+ 'price_unit': 750.00,
+ })],
+ })
+
+ # I add delivery cost in Sales order
+ delivery_wizard = Form(self.env['choose.delivery.carrier'].with_context({
+ 'default_order_id': self.sale_prepaid.id,
+ 'default_carrier_id': self.normal_delivery.id,
+ }))
+ choose_delivery_carrier = delivery_wizard.save()
+ choose_delivery_carrier.button_confirm()
+
+ # I confirm the SO.
+ self.sale_prepaid.action_confirm()
+ self.sale_prepaid._create_invoices()
+
+ # I check that the invoice was created
+ self.assertEqual(len(self.sale_prepaid.invoice_ids), 1, "Invoice not created.")
+
+ # I confirm the invoice
+
+ self.invoice = self.sale_prepaid.invoice_ids
+ self.invoice.action_post()
+
+ # I pay the invoice.
+ self.journal = self.AccountJournal.search([('type', '=', 'cash'), ('company_id', '=', self.sale_prepaid.company_id.id)], limit=1)
+
+ register_payments = self.env['account.payment.register'].with_context(active_model='account.move', active_ids=self.invoice.ids).create({
+ 'journal_id': self.journal.id,
+ })
+ register_payments._create_payments()
+
+ # Check the SO after paying the invoice
+ self.assertNotEqual(self.sale_prepaid.invoice_count, 0, 'order not invoiced')
+ self.assertTrue(self.sale_prepaid.invoice_status == 'invoiced', 'order is not invoiced')
+ self.assertEqual(len(self.sale_prepaid.picking_ids), 1, 'pickings not generated')
+
+ # Check the stock moves
+ moves = self.sale_prepaid.picking_ids.move_lines
+ self.assertEqual(moves[0].product_qty, 2, 'wrong product_qty')
+ self.assertEqual(moves[0].weight, 2.0, 'wrong move weight')
+
+ # Ship
+ self.picking = self.sale_prepaid.picking_ids._action_done()
diff --git a/addons/delivery/tests/test_packing_delivery.py b/addons/delivery/tests/test_packing_delivery.py
new file mode 100644
index 00000000..e4710c70
--- /dev/null
+++ b/addons/delivery/tests/test_packing_delivery.py
@@ -0,0 +1,78 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.addons.stock.tests.test_packing import TestPackingCommon
+
+
+class TestPacking(TestPackingCommon):
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestPacking, cls).setUpClass()
+ cls.uom_kg = cls.env.ref('uom.product_uom_kgm')
+ cls.product_aw = cls.env['product.product'].create({
+ 'name': 'Product AW',
+ 'type': 'product',
+ 'weight': 2.4,
+ 'uom_id': cls.uom_kg.id,
+ 'uom_po_id': cls.uom_kg.id
+ })
+ cls.product_bw = cls.env['product.product'].create({
+ 'name': 'Product BW',
+ 'type': 'product',
+ 'weight': 0.3,
+ 'uom_id': cls.uom_kg.id,
+ 'uom_po_id': cls.uom_kg.id
+ })
+ test_carrier_product = cls.env['product.product'].create({
+ 'name': 'Test carrier product',
+ 'type': 'service',
+ })
+ cls.test_carrier = cls.env['delivery.carrier'].create({
+ 'name': 'Test carrier',
+ 'delivery_type': 'fixed',
+ 'product_id': test_carrier_product.id,
+ })
+
+ def test_put_in_pack_weight_wizard(self):
+ """ Check that de default weight is correctly set by default when using the 'choose.delivery.package' wizard.
+ This purpose of this wizard is
+ """
+ self.env['stock.quant']._update_available_quantity(self.product_aw, self.stock_location, 20.0)
+ self.env['stock.quant']._update_available_quantity(self.product_bw, self.stock_location, 20.0)
+
+ picking_ship = self.env['stock.picking'].create({
+ 'partner_id': self.env['res.partner'].create({'name': 'A partner'}).id,
+ 'picking_type_id': self.warehouse.out_type_id.id,
+ 'location_id': self.stock_location.id,
+ 'location_dest_id': self.customer_location.id,
+ 'carrier_id': self.test_carrier.id
+ })
+ move_line_paw = self.env['stock.move.line'].create({
+ 'product_id': self.product_aw.id,
+ 'product_uom_id': self.uom_kg.id,
+ 'picking_id': picking_ship.id,
+ 'qty_done': 5,
+ 'location_id': self.stock_location.id,
+ 'location_dest_id': self.customer_location.id
+ })
+ move_line_pbw = self.env['stock.move.line'].create({
+ 'product_id': self.product_bw.id,
+ 'product_uom_id': self.uom_kg.id,
+ 'picking_id': picking_ship.id,
+ 'qty_done': 5,
+ 'location_id': self.stock_location.id,
+ 'location_dest_id': self.customer_location.id
+ })
+ picking_ship.action_confirm()
+ pack_action = picking_ship.action_put_in_pack()
+ pack_action_ctx = pack_action['context']
+ pack_action_model = pack_action['res_model']
+
+ # We make sure the correct action was returned
+ self.assertEqual(pack_action_model, 'choose.delivery.package')
+
+ # We instanciate the wizard with the context of the action and check that the
+ # default weight was set.
+ pack_wiz = self.env['choose.delivery.package'].with_context(pack_action_ctx).create({})
+ self.assertEqual(pack_wiz.shipping_weight, 13.5)