This file is indexed.

/usr/lib/python3/dist-packages/trytond/modules/stock_shipment_measurements/tests/test_stock_shipment_measurements.py is in tryton-modules-stock-shipment-measurements 4.6.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# This file is part of Tryton.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

import unittest
from decimal import Decimal

from trytond.pool import Pool
from trytond.tests.test_tryton import (ModuleTestCase, activate_module,
    with_transaction)
from trytond.tests.test_tryton import suite as test_suite

from trytond.modules.company.tests import create_company, set_company


class StockShipmentMeasurementsTestCase(ModuleTestCase):
    'Test Stock Shipment Measurements module'
    module = 'stock_shipment_measurements'
    longMessage = True

    @classmethod
    def setUpClass(cls):
        super(StockShipmentMeasurementsTestCase, cls).setUpClass()
        activate_module('stock_package')

    @with_transaction()
    def test_move_internal_measurements(self):
        "Test move internal measurements"
        pool = Pool()
        Uom = pool.get('product.uom')
        Template = pool.get('product.template')
        Product = pool.get('product.product')
        Location = pool.get('stock.location')
        Move = pool.get('stock.move')

        kg, = Uom.search([('name', '=', 'Kilogram')])
        g, = Uom.search([('name', '=', 'Gram')])
        liter, = Uom.search([('name', '=', 'Liter')])
        supplier, = Location.search([('code', '=', 'SUP')])
        storage, = Location.search([('code', '=', 'STO')])
        company = create_company()
        currency = company.currency

        template, = Template.create([{
                    'name': "Test internal measurements",
                    'type': 'goods',
                    'list_price': Decimal(1),
                    'default_uom': kg,
                    }])
        product, = Product.create([{
                    'template': template.id,
                    }])

        # without any measurements
        with set_company(company):
            move, = Move.create([{
                        'product': product,
                        'uom': g,
                        'quantity': 200,
                        'from_location': supplier,
                        'to_location': storage,
                        'company': company,
                        'unit_price': Decimal(1),
                        'currency': currency,
                        }])
            self.assertEqual(move.internal_weight, 0.2)
            self.assertEqual(move.internal_volume, None)

            Move.write([move], {'quantity': 100})
            self.assertEqual(move.internal_weight, 0.1)
            self.assertEqual(move.internal_volume, None)

        template.weight = 1.1
        template.weight_uom = kg
        template.save()

        # with weight measurements
        with set_company(company):
            move, = Move.create([{
                        'product': product,
                        'uom': g,
                        'quantity': 300,
                        'from_location': supplier,
                        'to_location': storage,
                        'company': company,
                        'unit_price': Decimal(1),
                        'currency': currency,
                        }])
            self.assertEqual(move.internal_weight, 0.33)
            self.assertEqual(move.internal_volume, None)

            Move.write([move], {'quantity': 500})
            self.assertEqual(move.internal_weight, 0.55)
            self.assertEqual(move.internal_volume, None)

        template.volume = 2
        template.volume_uom = liter
        template.save()

        # with weight and volume measurements
        with set_company(company):
            move, = Move.create([{
                        'product': product,
                        'uom': g,
                        'quantity': 500,
                        'from_location': supplier,
                        'to_location': storage,
                        'company': company,
                        'unit_price': Decimal(1),
                        'currency': currency,
                        }])
            self.assertEqual(move.internal_weight, 0.55)
            self.assertEqual(move.internal_volume, 1)

            Move.write([move], {'quantity': 600})
            self.assertEqual(move.internal_weight, 0.66)
            self.assertEqual(move.internal_volume, 1.2)

    @with_transaction()
    def test_shipment_out_measurements(self):
        "Test shipment out measurements"
        pool = Pool()
        Uom = pool.get('product.uom')
        Template = pool.get('product.template')
        Product = pool.get('product.product')
        Location = pool.get('stock.location')
        Move = pool.get('stock.move')
        Shipment = pool.get('stock.shipment.out')
        Package = pool.get('stock.package')
        PackageType = pool.get('stock.package.type')
        Party = pool.get('party.party')

        kg, = Uom.search([('name', '=', 'Kilogram')])
        liter, = Uom.search([('name', '=', 'Liter')])
        customer, = Location.search([('code', '=', 'CUS')])
        storage, = Location.search([('code', '=', 'STO')])
        party = Party(name='Customer')
        party.addresses = [{}]
        party.save()
        company = create_company()
        currency = company.currency
        package_type = PackageType(name="Type")
        package_type.save()

        template, = Template.create([{
                    'name': "Test measurements",
                    'type': 'goods',
                    'list_price': Decimal(1),
                    'default_uom': kg,
                    'volume': 0.2,
                    'volume_uom': liter,
                    }])
        product, = Product.create([{
                    'template': template.id,
                    }])

        with set_company(company):
            shipment = Shipment()
            shipment.customer = party
            shipment.delivery_address, = party.addresses
            shipment.save()

            # without moves
            self.assertEqual(shipment.weight, None)
            self.assertEqual(shipment.volume, None)

            shipment.moves = [Move(
                    product=product,
                    uom=kg,
                    quantity=10,
                    from_location=storage,
                    to_location=customer,
                    company=company,
                    unit_price=Decimal(1),
                    currency=currency,
                    )]
            shipment.save()

            # without inventory moves
            self.assertEqual(shipment.weight, 10)
            self.assertEqual(shipment.volume, 2)

            Shipment.wait([shipment])

            # with inventory moves
            self.assertEqual(shipment.weight, 10)
            self.assertEqual(shipment.volume, 2)

            for clause, result in [
                    ([('weight', '=', 10)], [shipment]),
                    ([('weight', '=', 5)], []),
                    ([('volume', '=', 2)], [shipment]),
                    ([('volume', '=', 3)], []),
                    ]:
                msg = 'clause: %s' % clause
                self.assertEqual(Shipment.search(clause), result, msg=msg)

            # Add packages
            package_root = Package()
            package_root.type = package_type
            package_root.shipment = shipment
            package_root.additional_weight = 1
            package_root.save()

            package = Package()
            package.type = package_type
            package.shipment = shipment
            package.moves = shipment.moves
            package.parent = package_root
            package.save()

            self.assertEqual(package_root.weight, None)
            self.assertEqual(package_root.volume, None)

            self.assertEqual(package.weight, 10)
            self.assertEqual(package.volume, 2)

            self.assertEqual(package_root.total_weight, 11)
            self.assertEqual(package_root.total_volume, 2)


def suite():
    suite = test_suite()
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
            StockShipmentMeasurementsTestCase))
    return suite