first commit
This commit is contained in:
2
modules/stock_split/tests/__init__.py
Normal file
2
modules/stock_split/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
BIN
modules/stock_split/tests/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
modules/stock_split/tests/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
93
modules/stock_split/tests/scenario_stock_split_shipment.rst
Normal file
93
modules/stock_split/tests/scenario_stock_split_shipment.rst
Normal file
@@ -0,0 +1,93 @@
|
||||
====================
|
||||
Stock Split Shipment
|
||||
====================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.modules.currency.tests.tools import get_currency
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('stock_split', create_company)
|
||||
|
||||
Get currency::
|
||||
|
||||
>>> currency = get_currency()
|
||||
|
||||
Create customer::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> customer = Party(name="Customer")
|
||||
>>> customer.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> unit, = ProductUom.find([('name', '=', "Unit")])
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Product"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.list_price = Decimal('20')
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Get stock locations::
|
||||
|
||||
>>> Location = Model.get('stock.location')
|
||||
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
|
||||
>>> output_loc, = Location.find([('code', '=', 'OUT')])
|
||||
>>> storage_loc, = Location.find([('code', '=', 'STO')])
|
||||
|
||||
Create shipment with 2 lines::
|
||||
|
||||
>>> Shipment = Model.get('stock.shipment.out')
|
||||
>>> Move = Model.get('stock.move')
|
||||
|
||||
>>> shipment1 = Shipment()
|
||||
>>> shipment1.customer = customer
|
||||
|
||||
>>> for i in range(1, 3):
|
||||
... move = shipment1.outgoing_moves.new()
|
||||
... move.product = product
|
||||
... move.unit = unit
|
||||
... move.quantity = i
|
||||
... move.from_location = output_loc
|
||||
... move.to_location = customer_loc
|
||||
... move.unit_price = Decimal(1)
|
||||
... move.currency = currency
|
||||
|
||||
>>> shipment1.save()
|
||||
>>> move1, move2 = shipment1.outgoing_moves
|
||||
|
||||
Set to waiting and go back to draft to get inventory moves::
|
||||
|
||||
>>> shipment1.click('wait')
|
||||
>>> len(shipment1.inventory_moves)
|
||||
2
|
||||
>>> shipment1.click('draft')
|
||||
|
||||
Split shipment::
|
||||
|
||||
>>> split_shipment = shipment1.click('split_wizard')
|
||||
>>> len(split_shipment.form.domain_moves)
|
||||
2
|
||||
>>> split_shipment.form.moves.append(Move(move2.id))
|
||||
>>> split_shipment.execute('split')
|
||||
|
||||
>>> shipment2, = Shipment.find([('id', '!=', shipment1.id)])
|
||||
|
||||
>>> move, = shipment1.outgoing_moves
|
||||
>>> assertEqual(move, move1)
|
||||
>>> len(shipment1.inventory_moves)
|
||||
0
|
||||
|
||||
>>> move, = shipment2.outgoing_moves
|
||||
>>> assertEqual(move, move2)
|
||||
178
modules/stock_split/tests/test_module.py
Normal file
178
modules/stock_split/tests/test_module.py
Normal file
@@ -0,0 +1,178 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.modules.company.tests import (
|
||||
CompanyTestMixin, create_company, set_company)
|
||||
from trytond.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
|
||||
|
||||
class StockSplitTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Stock Lot module'
|
||||
module = 'stock_split'
|
||||
|
||||
@with_transaction()
|
||||
def test_split(self):
|
||||
'Test split'
|
||||
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')
|
||||
|
||||
unit, = Uom.search([('name', '=', 'Unit')])
|
||||
template, = Template.create([{
|
||||
'name': 'Test Split',
|
||||
'type': 'goods',
|
||||
'default_uom': unit.id,
|
||||
}])
|
||||
product, = Product.create([{
|
||||
'template': template.id,
|
||||
}])
|
||||
input_, = Location.search([('code', '=', 'IN')])
|
||||
storage, = Location.search([('code', '=', 'STO')])
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
|
||||
def create_move(quantity):
|
||||
move, = Move.create([{
|
||||
'product': product.id,
|
||||
'unit': unit.id,
|
||||
'quantity': quantity,
|
||||
'from_location': input_.id,
|
||||
'to_location': storage.id,
|
||||
'company': company.id,
|
||||
}])
|
||||
return move
|
||||
|
||||
move = create_move(10)
|
||||
moves = move.split(5, unit)
|
||||
self.assertEqual(len(moves), 2)
|
||||
self.assertEqual([m.quantity for m in moves], [5, 5])
|
||||
|
||||
move = create_move(13)
|
||||
moves = move.split(5, unit)
|
||||
self.assertEqual(len(moves), 3)
|
||||
self.assertEqual([m.quantity for m in moves], [5, 5, 3])
|
||||
|
||||
move = create_move(7)
|
||||
moves = move.split(8, unit)
|
||||
self.assertEqual(moves, [move])
|
||||
self.assertEqual(move.quantity, 7)
|
||||
|
||||
move = create_move(20)
|
||||
moves = move.split(5, unit, count=2)
|
||||
self.assertEqual(len(moves), 3)
|
||||
self.assertEqual([m.quantity for m in moves], [5, 5, 10])
|
||||
|
||||
move = create_move(20)
|
||||
moves = move.split(5, unit, count=4)
|
||||
self.assertEqual(len(moves), 4)
|
||||
self.assertEqual([m.quantity for m in moves], [5, 5, 5, 5])
|
||||
|
||||
move = create_move(10)
|
||||
moves = move.split(5, unit, count=3)
|
||||
self.assertEqual(len(moves), 2)
|
||||
self.assertEqual([m.quantity for m in moves], [5, 5])
|
||||
|
||||
move = create_move(10)
|
||||
Move.write([move], {
|
||||
'state': 'assigned',
|
||||
})
|
||||
moves = move.split(5, unit)
|
||||
self.assertEqual(len(moves), 2)
|
||||
self.assertEqual([m.quantity for m in moves], [5, 5])
|
||||
self.assertEqual([m.state for m in moves],
|
||||
['assigned', 'assigned'])
|
||||
|
||||
@with_transaction()
|
||||
def test_unsplit(self):
|
||||
"Test unsplit"
|
||||
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')
|
||||
|
||||
meter, = Uom.search([('name', '=', "Meter")])
|
||||
cm, = Uom.search([('name', '=', "Centimeter")])
|
||||
template, = Template.create([{
|
||||
'name': 'Test Split',
|
||||
'type': 'goods',
|
||||
'default_uom': meter.id,
|
||||
}])
|
||||
product, = Product.create([{
|
||||
'template': template.id,
|
||||
}])
|
||||
input_, = Location.search([('code', '=', 'IN')])
|
||||
storage, = Location.search([('code', '=', 'STO')])
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
moves = Move.create([{
|
||||
'product': product,
|
||||
'unit': meter,
|
||||
'quantity': 2,
|
||||
'from_location': input_.id,
|
||||
'to_location': storage.id,
|
||||
'company': company.id,
|
||||
}, {
|
||||
'product': product,
|
||||
'unit': cm,
|
||||
'quantity': 25,
|
||||
'from_location': input_.id,
|
||||
'to_location': storage.id,
|
||||
'company': company.id,
|
||||
}])
|
||||
Move.unsplit(moves)
|
||||
|
||||
self.assertEqual(moves[0].quantity, 225)
|
||||
self.assertEqual(moves[0].unit, cm)
|
||||
self.assertEqual(moves[1].quantity, 0)
|
||||
|
||||
@with_transaction()
|
||||
def test_unsplit_different(self):
|
||||
"Test unsplit different"
|
||||
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')
|
||||
|
||||
unit, = Uom.search([('name', '=', "Unit")])
|
||||
template, = Template.create([{
|
||||
'name': 'Test Split',
|
||||
'type': 'goods',
|
||||
'default_uom': unit.id,
|
||||
}])
|
||||
product, = Product.create([{
|
||||
'template': template.id,
|
||||
}])
|
||||
input_, = Location.search([('code', '=', 'IN')])
|
||||
storage, = Location.search([('code', '=', 'STO')])
|
||||
company = create_company()
|
||||
with set_company(company):
|
||||
moves = Move.create([{
|
||||
'product': product,
|
||||
'unit': unit,
|
||||
'quantity': 2,
|
||||
'from_location': input_.id,
|
||||
'to_location': storage.id,
|
||||
'company': company.id,
|
||||
}, {
|
||||
'product': product,
|
||||
'unit': unit,
|
||||
'quantity': 2,
|
||||
'from_location': storage.id,
|
||||
'to_location': input_.id,
|
||||
'company': company.id,
|
||||
}])
|
||||
Move.unsplit(moves)
|
||||
|
||||
self.assertEqual(moves[0].quantity, 2)
|
||||
self.assertEqual(moves[1].quantity, 2)
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/stock_split/tests/test_scenario.py
Normal file
8
modules/stock_split/tests/test_scenario.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import load_doc_tests
|
||||
|
||||
|
||||
def load_tests(*args, **kwargs):
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
Reference in New Issue
Block a user