trytond-purchase_request_pe.../tests/scenario_purchase_request_p...

235 lines
7.3 KiB
ReStructuredText

=========================
Purchase Request Scenario
=========================
Imports::
>>> import datetime
>>> from dateutil.relativedelta import relativedelta
>>> from decimal import Decimal
>>> from proteus import config, Model, Wizard
>>> today = datetime.date.today()
Create database::
>>> config = config.set_trytond()
>>> config.pool.test = True
Install stock Module::
>>> Module = Model.get('ir.module.module')
>>> module, = Module.find([('name', '=', 'purchase_request_pending')])
>>> module.click('install')
>>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
Create company::
>>> Currency = Model.get('currency.currency')
>>> CurrencyRate = Model.get('currency.currency.rate')
>>> 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 = 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
>>> company.currency = currency
>>> company_config.execute('add')
>>> company, = Company.find([])
Reload the context::
>>> User = Model.get('res.user')
>>> Group = Model.get('res.group')
>>> config._context = User.get_preferences(True, config.context)
Create chart of accounts::
>>> AccountTemplate = Model.get('account.account.template')
>>> Account = Model.get('account.account')
>>> Journal = Model.get('account.journal')
>>> account_template, = AccountTemplate.find([('parent', '=', None)])
>>> create_chart = Wizard('account.create_chart')
>>> create_chart.execute('account')
>>> create_chart.form.account_template = account_template
>>> create_chart.form.company = company
>>> create_chart.execute('create_account')
>>> receivable, = Account.find([
... ('kind', '=', 'receivable'),
... ('company', '=', company.id),
... ])
>>> payable, = Account.find([
... ('kind', '=', 'payable'),
... ('company', '=', company.id),
... ])
>>> revenue, = Account.find([
... ('kind', '=', 'revenue'),
... ('company', '=', company.id),
... ])
>>> expense, = Account.find([
... ('kind', '=', 'expense'),
... ('company', '=', company.id),
... ])
>>> create_chart.form.account_receivable = receivable
>>> create_chart.form.account_payable = payable
>>> create_chart.execute('create_properties')
>>> cash, = Account.find([
... ('kind', '=', 'other'),
... ('name', '=', 'Main Cash'),
... ('company', '=', company.id),
... ])
>>> cash_journal, = Journal.find([('type', '=', 'cash')])
>>> cash_journal.credit_account = cash
>>> cash_journal.debit_account = cash
>>> cash_journal.save()
Create parties::
>>> Party = Model.get('party.party')
>>> supplier = Party(name='Supplier')
>>> supplier.save()
>>> 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')])
>>> product = Product()
>>> template = ProductTemplate()
>>> template.name = 'Product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('20')
>>> template.cost_price = Decimal('8')
>>> template.purchasable = True
>>> template.account_expense = expense
>>> template.save()
>>> product.template = template
>>> product.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')])
Create a need for missing product::
>>> ShipmentOut = Model.get('stock.shipment.out')
>>> shipment_out = ShipmentOut()
>>> shipment_out.planned_date = today
>>> shipment_out.effective_date = today
>>> shipment_out.customer = customer
>>> shipment_out.warehouse = warehouse_loc
>>> shipment_out.company = company
>>> move = shipment_out.outgoing_moves.new()
>>> 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 = company.currency
>>> shipment_out.click('wait')
There is no purchase request::
>>> PurchaseRequest = Model.get('purchase.request')
>>> PurchaseRequest.find([])
[]
Create the purchase request::
>>> create_pr = Wizard('purchase.request.create')
>>> create_pr.execute('create_')
There is now a draft purchase request::
>>> pr, = PurchaseRequest.find([])
>>> pr.product == product
True
>>> pr.quantity
1.0
>>> pr.state
'draft'
Set the purchase request to pending state::
>>> pr.click('to_pending')
>>> pr.state
'pending'
Create more needs of the same product::
>>> ShipmentOut = Model.get('stock.shipment.out')
>>> shipment_out = ShipmentOut()
>>> shipment_out.planned_date = today
>>> shipment_out.effective_date = today
>>> shipment_out.customer = customer
>>> shipment_out.warehouse = warehouse_loc
>>> shipment_out.company = company
>>> move = shipment_out.outgoing_moves.new()
>>> move.product = product
>>> move.uom = unit
>>> move.quantity = 2.0
>>> move.from_location = output_loc
>>> move.to_location = customer_loc
>>> move.company = company
>>> move.unit_price = Decimal('1')
>>> move.currency = company.currency
>>> shipment_out.click('wait')
Another purhcase requests is created::
>>> create_pr = Wizard('purchase.request.create')
>>> create_pr.execute('create_')
>>> pending_pr, draft_pr = sorted(PurchaseRequest.find([]),
... key=lambda a: a.quantity)
>>> pending_pr.product == product
True
>>> pending_pr.quantity
1.0
>>> pending_pr.state
'pending'
>>> draft_pr.product == product
True
>>> draft_pr.quantity
2.0
>>> draft_pr.state
'draft'
Set the purchase request back to draft and chech that they are grouped::
>>> pending_pr.click('draft')
>>> pending_pr.state
'draft'
>>> create_pr = Wizard('purchase.request.create')
>>> create_pr.execute('create_')
>>> draft_pr, = PurchaseRequest.find([])
>>> draft_pr.product == product
True
>>> draft_pr.quantity
3.0
>>> draft_pr.state
'draft'