Debian Codegraph @

addons/delivery_stock_picking_batch/tests/test_delivery_picking_batch.py

raw
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo import Command
4 from odoo.tests import common, tagged
5
6
7 @tagged('-at_install', 'post_install')
8 class TestDeliveryPickingBatch(common.TransactionCase):
9
10 @classmethod
11 def setUpClass(cls):
12 super().setUpClass()
13 cls.picking_type_out = cls.env.ref('stock.picking_type_out')
14 cls.local_delivery_carrier = cls.env['delivery.carrier'].create({
15 'name': 'Local Delivery - Testing',
16 'fixed_price': 5.0,
17 'free_over': True,
18 'amount': 50,
19 'sequence': 4,
20 'delivery_type': 'fixed',
21 'product_id': cls.env['product.product'].create({
22 'name': 'Local Delivery - Testing',
23 'default_code': 'Delivery_Testing',
24 'type': 'service',
25 'categ_id': cls.env.ref('delivery.product_category_deliveries').id,
26 'sale_ok': False,
27 'purchase_ok': False,
28 'list_price': 10.0,
29 'invoice_policy': 'order'
30 }).id
31 })
32 cls.stock_location = cls.env.ref('stock.stock_location_stock')
33 cls.customer_location = cls.env.ref('stock.stock_location_customers')
34
35 cls.package_type = cls.env['stock.package.type'].create({
36 'name': 'normal package',
37 'base_weight': 1.0,
38 })
39
40 cls.product_a = cls.env['product.product'].create({
41 'name': 'product_a',
42 'is_storable': True,
43 'weight': 1.0,
44 })
45
46 def test_batch_picking_pack_shipping_weight_compute(self):
47 """ Having a batch transfer with 2+ of the same product across multiple pickings and adding
48 the products to the same pack should result in an accurate computed shipping weight.gau
49 """
50 picking_create_vals = {
51 'picking_type_id': self.picking_type_out.id,
52 'location_id': self.stock_location.id,
53 'location_dest_id': self.customer_location.id,
54 'carrier_id': self.local_delivery_carrier.id,
55 }
56
57 batch = self.env['stock.picking.batch'].create({
58 'picking_ids': [Command.create(picking_create_vals) for _ in range(2)],
59 })
60
61 for picking in batch.picking_ids:
62 picking.move_ids = self.env['stock.move'].create({
63 'product_id': self.product_a.id,
64 'product_uom_qty': 1.0,
65 'location_id': self.stock_location.id,
66 'location_dest_id': self.customer_location.id,
67 })
68 picking.move_ids[0].quantity = 1.0
69
70 pack_wizard_vals = batch.action_put_in_pack()
71 pack_wizard = self.env[(pack_wizard_vals.get('res_model'))].with_context(pack_wizard_vals.get('context')).create({})
72 pack_wizard.package_type_id = self.package_type.id
73 self.assertEqual(pack_wizard.shipping_weight, 3.0)
74 package = pack_wizard.action_put_in_pack()
75 batch.action_done()
76 self.assertEqual(package.weight, 3.0)