Add some test tools to ease scenario writing

review11331002
This commit is contained in:
Cédric Krier
2014-10-24 10:44:48 +02:00
parent 4fe2341b9d
commit 07fb7e396e
+15 -41
View File
@@ -2,16 +2,14 @@
Stock FIFO Cost Price
=====================
=============
General Setup
=============
Imports::
>>> import datetime
>>> from dateutil.relativedelta import relativedelta
>>> from decimal import Decimal
>>> from proteus import config, Model, Wizard
>>> from trytond.modules.company.tests.tools import create_company, \
... get_company
>>> today = datetime.date.today()
Create database::
@@ -22,35 +20,14 @@ Create database::
Install stock Module::
>>> Module = Model.get('ir.module.module')
>>> modules = Module.find([('name', '=', 'product_cost_fifo')])
>>> Module.install([x.id for x in modules], config.context)
>>> module, = Module.find([('name', '=', 'product_cost_fifo')])
>>> module.click('install')
>>> 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='US Dollar', symbol='$', code='USD',
... rounding=Decimal('0.01'), mon_grouping='[3, 3, 0]',
... mon_decimal_point='.')
... 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()
>>> _ = create_company()
>>> company = get_company()
Reload the context::
@@ -94,9 +71,8 @@ Make 4 units of the product available @ 10 ::
>>> incoming_move.planned_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('10')
>>> incoming_move.currency = currency
>>> incoming_move.save()
>>> StockMove.do([incoming_move.id], config.context)
>>> incoming_move.currency = company.currency
>>> incoming_move.click('do')
Check Cost Price is 10::
@@ -115,9 +91,8 @@ Add 2 more units @ 25::
>>> incoming_move.planned_date = today
>>> incoming_move.company = company
>>> incoming_move.unit_price = Decimal('25')
>>> incoming_move.currency = currency
>>> incoming_move.save()
>>> StockMove.do([incoming_move.id], config.context)
>>> incoming_move.currency = company.currency
>>> incoming_move.click('do')
Check Cost Price FIFO is 15::
@@ -136,9 +111,8 @@ Sell 3 units @ 50::
>>> outgoing_move.planned_date = today
>>> outgoing_move.company = company
>>> outgoing_move.unit_price = Decimal('50')
>>> outgoing_move.currency = currency
>>> outgoing_move.save()
>>> StockMove.do([outgoing_move.id], config.context)
>>> outgoing_move.currency = company.currency
>>> outgoing_move.click('do')
Check Cost Price FIFO is 20::
@@ -158,7 +132,7 @@ Sell twice 1 more units @ 50::
>>> outgoing_move.planned_date = today
>>> outgoing_move.company = company
>>> outgoing_move.unit_price = Decimal('50')
>>> outgoing_move.currency = currency
>>> outgoing_move.currency = company.currency
>>> outgoing_move.save()
>>> outgoing_moves.append(outgoing_move)
@@ -171,11 +145,11 @@ Sell twice 1 more units @ 50::
>>> outgoing_move.planned_date = today
>>> outgoing_move.company = company
>>> outgoing_move.unit_price = Decimal('50')
>>> outgoing_move.currency = currency
>>> outgoing_move.currency = company.currency
>>> outgoing_move.save()
>>> outgoing_moves.append(outgoing_move)
>>> StockMove.do([m.id for m in outgoing_moves], config.context)
>>> StockMove.click(outgoing_moves, 'do')
Check Cost Price FIFO is 25::