trytond-stock_lot_fifo/tests/scenario_stock_lot_fifo.rst
2017-01-27 16:48:31 +01:00

176 lines
No EOL
5.5 KiB
ReStructuredText

===========================
Stock Lot Fifo Scenario
===========================
=============
General Setup
=============
Imports::
>>> import datetime
>>> from dateutil.relativedelta import relativedelta
>>> from decimal import Decimal
>>> from proteus import config, Model, Wizard
>>> today = datetime.date.today()
>>> yesterday = today - relativedelta(days=1)
Create database::
>>> config = config.set_trytond()
>>> config.pool.test = True
Install stock Module::
>>> Module = Model.get('ir.module.module')
>>> modules = Module.find([('name', '=', 'stock_lot_fifo')])
>>> Module.install([x.id for x in modules], config.context)
>>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
Create company::
>>> Currency = Model.get('currency.currency')
>>> CurrencyRate = Model.get('currency.currency.rate')
>>> Company = Model.get('company.company')
>>> Party = Model.get('party.party')
>>> company_config = Wizard('company.company.config')
>>> company_config.execute('company')
>>> company = company_config.form
>>> party = Party(name='Dunder Mifflin')
>>> party.save()
>>> company.party = party
>>> currencies = Currency.find([('code', '=', 'USD')])
>>> if not currencies:
... currency = Currency(name='U.S. Dollar', symbol='$', code='USD',
... rounding=Decimal('0.01'), mon_grouping='[3, 3, 0]',
... mon_decimal_point='.', mon_thousands_sep=',')
... currency.save()
... CurrencyRate(date=today + relativedelta(month=1, day=1),
... rate=Decimal('1.0'), currency=currency).save()
... else:
... currency, = currencies
>>> company.currency = currency
>>> company_config.execute('add')
>>> company, = Company.find()
Reload the context::
>>> User = Model.get('res.user')
>>> config._context = User.get_preferences(True, config.context)
Create customer::
>>> Party = Model.get('party.party')
>>> customer = Party(name='Customer')
>>> customer.save()
Create category::
>>> ProductCategory = Model.get('product.category')
>>> category = ProductCategory(name='Category')
>>> category.save()
Get stock locations::
>>> Location = Model.get('stock.location')
>>> warehouse_loc, = Location.find([('code', '=', 'WH')])
>>> supplier_loc, = Location.find([('code', '=', 'SUP')])
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
>>> output_loc, = Location.find([('code', '=', 'OUT')])
>>> storage_loc, = Location.find([('code', '=', 'STO')])
>>> lost_found, = Location.find([('type', '=', 'lost_found')])
Create product::
>>> ProductUom = Model.get('product.uom')
>>> ProductTemplate = Model.get('product.template')
>>> Product = Model.get('product.product')
>>> StockLotType = Model.get('stock.lot.type')
>>> lot_types, = StockLotType.find([('code', '=', 'storage')])
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> product = Product()
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.category = category
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('20')
>>> template.cost_price = Decimal('8')
>>> template.lot_required.append(lot_types)
>>> template.save()
>>> product.template = template
>>> product.save()
Create Lots::
>>> Lot = Model.get('stock.lot')
>>> lot = Lot(number="Lot Test 1", product=product.id)
>>> lot.save()
>>> lot2 = Lot(number="Lot Test 2", product=product.id)
>>> lot2.save()
Create Shipment Out::
>>> ShipmentOut = Model.get('stock.shipment.out')
>>> shipment_out = ShipmentOut()
>>> shipment_out.planned_date = today
>>> shipment_out.customer = customer
>>> shipment_out.warehouse = warehouse_loc
>>> shipment_out.company = company
Add two shipment lines of same product::
>>> StockMove = Model.get('stock.move')
>>> shipment_out.outgoing_moves.extend([StockMove(), StockMove()])
>>> for move in shipment_out.outgoing_moves:
... move.product = product
... move.uom =unit
... move.quantity = 1
... move.from_location = output_loc
... move.to_location = customer_loc
... move.company = company
... move.unit_price = Decimal('1')
... move.currency = currency
>>> shipment_out.save()
Set the shipment state to waiting::
>>> ShipmentOut.wait([shipment_out.id], config.context)
>>> shipment_out.reload()
>>> len(shipment_out.outgoing_moves)
2
>>> len(shipment_out.inventory_moves)
2
Make 2 unit of the product available::
>>> incoming_move = StockMove()
>>> incoming_move.product = product
>>> incoming_move.uom = unit
>>> incoming_move.quantity = 2
>>> incoming_move.lot = lot
>>> incoming_move.from_location = supplier_loc
>>> incoming_move.to_location = storage_loc
>>> incoming_move.planned_date = today
>>> incoming_move.effective_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('1')
>>> incoming_move.currency = currency
>>> incoming_move.save()
>>> StockMove.do([incoming_move.id], config.context)
Assign the shipoment::
>>> ShipmentOut.assign_try([shipment_out.id], config.context)
True
Test::
>>> moves = ShipmentOut(shipment_out.id).inventory_moves
>>> move1, move2 = moves
>>> move1.lot.number == lot.number
True
>>> move1.quantity == 1
True
>>> move2.lot.number
u'Lot Test 1'
>>> move2.quantity == 1
True