399 lines
11 KiB
ReStructuredText
399 lines
11 KiB
ReStructuredText
================
|
|
Carrier load UL
|
|
================
|
|
|
|
Imports::
|
|
|
|
>>> import datetime
|
|
>>> from trytond.tests.tools import activate_modules
|
|
>>> from dateutil.relativedelta import relativedelta
|
|
>>> from decimal import Decimal
|
|
>>> from trytond.modules.company.tests.tools import create_company, \
|
|
... get_company
|
|
>>> from trytond.modules.carrier_vehicle.tests.tools import create_carrier
|
|
>>> from trytond.modules.account.tests.tools import create_fiscalyear, \
|
|
... create_chart, get_accounts, create_tax
|
|
>>> from.trytond.modules.account_invoice.tests.tools import \
|
|
... set_fiscalyear_invoice_sequences, create_payment_term
|
|
>>> from trytond.modules.stock_unit_load.tests.tools import create_unit_load
|
|
>>> from proteus import Model, Wizard
|
|
>>> today = datetime.date.today()
|
|
|
|
Install agro Module::
|
|
|
|
>>> config = activate_modules('carrier_load_done2running')
|
|
|
|
Create company::
|
|
|
|
>>> _ = create_company()
|
|
>>> company = get_company()
|
|
|
|
Reload the context::
|
|
|
|
>>> User = Model.get('res.user')
|
|
>>> Group = Model.get('res.group')
|
|
>>> config._context = User.get_preferences(True, config.context)
|
|
|
|
Create sale user::
|
|
|
|
>>> sale_user = User()
|
|
>>> sale_user.name = 'Sale'
|
|
>>> sale_user.login = 'sale'
|
|
>>> sale_user.main_company = company
|
|
>>> sale_group, = Group.find([('name', '=', 'Sales')])
|
|
>>> sale_user.groups.append(sale_group)
|
|
>>> sale_user.save()
|
|
|
|
Create stock user::
|
|
|
|
>>> stock_user = User()
|
|
>>> stock_user.name = 'Stock'
|
|
>>> stock_user.login = 'stock'
|
|
>>> stock_user.main_company = company
|
|
>>> stock_group, = Group.find([('name', '=', 'Stock')])
|
|
>>> stock_user.groups.append(stock_group)
|
|
>>> stock_user.save()
|
|
|
|
Create account user::
|
|
|
|
>>> account_user = User()
|
|
>>> account_user.name = 'Account'
|
|
>>> account_user.login = 'account'
|
|
>>> account_user.main_company = company
|
|
>>> account_group, = Group.find([('name', '=', 'Account')])
|
|
>>> account_user.groups.append(account_group)
|
|
>>> account_user.save()
|
|
|
|
Create fiscal year::
|
|
|
|
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
|
... create_fiscalyear(company))
|
|
>>> fiscalyear.click('create_period')
|
|
|
|
Create chart of accounts::
|
|
|
|
>>> _ = create_chart(company)
|
|
>>> accounts = get_accounts(company)
|
|
>>> revenue = accounts['revenue']
|
|
>>> expense = accounts['expense']
|
|
>>> cash = accounts['cash']
|
|
|
|
>>> Journal = Model.get('account.journal')
|
|
>>> cash_journal, = Journal.find([('type', '=', 'cash')])
|
|
>>> cash_journal.credit_account = cash
|
|
>>> cash_journal.debit_account = cash
|
|
>>> cash_journal.save()
|
|
|
|
Create tax::
|
|
|
|
>>> tax = create_tax(Decimal('.10'))
|
|
>>> tax.save()
|
|
|
|
Create parties::
|
|
|
|
>>> Party = Model.get('party.party')
|
|
>>> customer = Party(name='Customer')
|
|
>>> customer.save()
|
|
|
|
Create payment term::
|
|
|
|
>>> payment_term = create_payment_term()
|
|
>>> payment_term.save()
|
|
|
|
Create carrier::
|
|
|
|
>>> carrier = create_carrier(config)
|
|
>>> carrier_product = carrier.carrier_product.template
|
|
>>> carrier_product.purchasable = True
|
|
>>> carrier_product.purchase_uom = carrier_product.default_uom
|
|
>>> carrier_product.account_expense = expense
|
|
>>> carrier_product.save()
|
|
|
|
Get warehouse and dock::
|
|
|
|
>>> Location = Model.get('stock.location')
|
|
>>> wh, = Location.find([('type', '=', 'warehouse')])
|
|
>>> dock = wh.docks.new()
|
|
>>> dock.name = 'Dock 1'
|
|
>>> dock.code = 'D1'
|
|
>>> wh.save()
|
|
|
|
Create carrier load::
|
|
|
|
>>> Load = Model.get('carrier.load')
|
|
>>> load = Load()
|
|
>>> load.company != None
|
|
True
|
|
>>> load.state
|
|
'draft'
|
|
>>> load.date == today
|
|
True
|
|
>>> load.warehouse != None
|
|
True
|
|
>>> load.warehouse_output == load.warehouse.output_location
|
|
True
|
|
>>> load.dock != None
|
|
True
|
|
>>> load.carrier = carrier
|
|
>>> load.vehicle != None
|
|
True
|
|
>>> load.save()
|
|
>>> load.code != None
|
|
True
|
|
|
|
Create load order::
|
|
|
|
>>> Order = Model.get('carrier.load.order')
|
|
>>> order = Order(load=load)
|
|
>>> order.start_date = datetime.datetime.now() - relativedelta(minutes=20)
|
|
>>> order.state
|
|
'draft'
|
|
>>> order.ul_origin_restrict
|
|
True
|
|
>>> order.party = customer
|
|
>>> line = order.lines.new()
|
|
>>> line.ul_quantity = Decimal(1)
|
|
>>> order.save()
|
|
>>> order.code != None
|
|
True
|
|
>>> order.date == load.date
|
|
True
|
|
>>> order.click('wait')
|
|
>>> order.state
|
|
u'waiting'
|
|
|
|
Create unit load::
|
|
|
|
>>> Unitload = Model.get('stock.unit_load')
|
|
>>> ul = create_unit_load(config=config, do_state=False,
|
|
... default_values={'start_date': datetime.datetime.now() + relativedelta(days=-1)})
|
|
>>> template = ul.product.template
|
|
>>> template.salable = True
|
|
>>> template.account_expense = expense
|
|
>>> template.account_revenue = revenue
|
|
>>> template.save()
|
|
>>> main_product = ul.product
|
|
|
|
Add other products to unit load::
|
|
|
|
>>> ProductUom = Model.get('product.uom')
|
|
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
|
>>> ProductTemplate = Model.get('product.template')
|
|
>>> Product = Model.get('product.product')
|
|
>>> ProductCategory = Model.get('product.category')
|
|
>>> category = ProductCategory(name='Category')
|
|
>>> category.save()
|
|
>>> product = Product()
|
|
>>> template = ProductTemplate()
|
|
>>> template.name = 'Plastic Case 30x30'
|
|
>>> template.categories.append(category)
|
|
>>> template.default_uom = unit
|
|
>>> template.type = 'goods'
|
|
>>> template.salable = True
|
|
>>> template.list_price = Decimal('10')
|
|
>>> template.cost_price = Decimal('5')
|
|
>>> template.account_expense = expense
|
|
>>> template.account_revenue = revenue
|
|
>>> template.customer_taxes.append(tax)
|
|
>>> template.save()
|
|
>>> product.template = template
|
|
>>> product.save()
|
|
>>> move = ul.moves.new()
|
|
>>> move.planned_date = today
|
|
>>> move.product = product
|
|
>>> move.quantity = Decimal(2)
|
|
>>> move.from_location = ul.moves[0].from_location
|
|
>>> move.to_location = ul.moves[0].to_location
|
|
>>> move.currency = move.company.currency
|
|
>>> ul.save()
|
|
|
|
Starting load wizard::
|
|
|
|
>>> start_load = Wizard('carrier.load_uls', [])
|
|
>>> start_load.form.load_order = order
|
|
>>> start_load.execute('data')
|
|
>>> start_load.form.load_order == order
|
|
True
|
|
>>> len(start_load.form.uls_loaded)
|
|
0
|
|
>>> start_load.form.loaded_uls
|
|
0
|
|
>>> start_load.form.ul_code = 'X'
|
|
>>> start_load.execute('load_') # doctest:
|
|
Traceback (most recent call last):
|
|
...
|
|
UserError: ('UserError', ('Cannot find Unit load "X".', ''))
|
|
|
|
Check UL loading restrictions::
|
|
|
|
>>> start_load.form.ul_code = ul.code
|
|
>>> start_load.execute('load_') # doctest:
|
|
Traceback (most recent call last):
|
|
...
|
|
UserError: ('UserError', (u'UL "1" must be in Done state.', ''))
|
|
>>> ul.click('assign')
|
|
>>> ul.click('do')
|
|
>>> start_load.execute('load_')
|
|
>>> start_load.form.loaded_uls
|
|
1
|
|
>>> order.reload()
|
|
>>> order.state
|
|
u'running'
|
|
>>> order.start_date != None
|
|
True
|
|
>>> len(order.unit_loads)
|
|
1
|
|
>>> start_load.form.ul_code = ul.code
|
|
>>> start_load.execute('load_') # doctest:
|
|
Traceback (most recent call last):
|
|
...
|
|
UserError: ('UserError', (u'UL "1" is already loaded.', ''))
|
|
|
|
|
|
Add an invalid UL::
|
|
|
|
>>> Location = Model.get('stock.location')
|
|
>>> lost_found, = Location.find([('type', '=', 'lost_found')], limit=1)
|
|
>>> ul2 = create_unit_load(do_state=False,
|
|
... default_values={'start_date': datetime.datetime.now() + relativedelta(days=-1)})
|
|
>>> ul2.save()
|
|
>>> ul2.click('do')
|
|
>>> move_ul = Wizard('stock.unit_load.do_move', [ul2])
|
|
>>> move_ul.form.location = lost_found
|
|
>>> move_ul.form.date = ul2.end_date + relativedelta(minutes=30)
|
|
>>> move_ul.execute('move_')
|
|
>>> ul2.click('do')
|
|
>>> start_load.form.ul_code = ul2.code
|
|
>>> start_load.execute('load_') # doctest:
|
|
Traceback (most recent call last):
|
|
...
|
|
UserError: ('UserError', (u'UL "2" must be in a storage location.', ''))
|
|
>>> move_ul = Wizard('stock.unit_load.do_move', [ul2])
|
|
>>> move_ul.form.location = ul.location
|
|
>>> move_ul.form.date = ul2.end_date + relativedelta(minutes=45)
|
|
>>> move_ul.execute('move_')
|
|
>>> ul2.reload()
|
|
>>> ul2.click('do')
|
|
>>> Model.get('res.user.warning')(user=config.user,
|
|
... name='loading_ul_origin_2', always=True).save()
|
|
>>> start_load.execute('load_') # doctest:
|
|
Traceback (most recent call last):
|
|
...
|
|
UserError: ('UserError', (u'All valid lines of load order "1" are complete. Cannot load more ULs.', ''))
|
|
|
|
Unload UL::
|
|
|
|
>>> order.lines[0].ul_quantity += 1
|
|
>>> order.save()
|
|
>>> start_load.execute('load_')
|
|
>>> start_load.form.loaded_uls
|
|
2
|
|
>>> start_load.form.uls_loaded.append(ul2)
|
|
>>> start_load.execute('unload_')
|
|
>>> start_load.form.loaded_uls
|
|
1
|
|
>>> ul2.load_line == None
|
|
True
|
|
>>> start_load.execute('end')
|
|
>>> order.reload()
|
|
>>> len(order.unit_loads)
|
|
1
|
|
>>> start_load = Wizard('carrier.load_uls', [order])
|
|
>>> start_load.form.ul_code = ul2.code
|
|
>>> start_load.execute('load_')
|
|
>>> start_load.execute('end')
|
|
>>> order.reload()
|
|
>>> len(order.unit_loads)
|
|
2
|
|
>>> ul2.click('unload')
|
|
>>> order.reload()
|
|
>>> len(order.unit_loads)
|
|
1
|
|
|
|
Finish loading::
|
|
|
|
>>> start_load = Wizard('carrier.load_uls', [order])
|
|
>>> start_load.execute('do_') # doctest:
|
|
Traceback (most recent call last):
|
|
...
|
|
UserWarning: ('UserWarning', ('pending_uls_1', 'You have loaded less ULs (1) than expected (2).', ''))
|
|
>>> Model.get('res.user.warning')(user=config.user,
|
|
... name='pending_uls_1', always=True).save()
|
|
>>> start_load.execute('do_')
|
|
>>> order.reload()
|
|
>>> len(order.unit_loads)
|
|
1
|
|
>>> order.state
|
|
u'done'
|
|
|
|
Check sale::
|
|
|
|
>>> order.sale != None
|
|
True
|
|
>>> order.sale.state
|
|
u'quotation'
|
|
>>> order.sale.number != None
|
|
True
|
|
>>> len(order.sale.lines)
|
|
1
|
|
>>> order.sale.lines[0].product.id == ul.product.id
|
|
True
|
|
>>> len(order.sale.shipments)
|
|
1
|
|
>>> shipment, = order.sale.shipments
|
|
>>> shipment.start_date == order.start_date
|
|
True
|
|
>>> shipment.end_date == order.end_date
|
|
True
|
|
>>> len(shipment.outgoing_moves)
|
|
1
|
|
>>> shipment.outgoing_moves[0].unit_load.id == ul.id
|
|
True
|
|
>>> len(shipment.inventory_moves)
|
|
1
|
|
>>> shipment.inventory_moves[0].unit_load.id == ul.id
|
|
True
|
|
>>> len(order.inventory_moves)
|
|
1
|
|
>>> order.inventory_moves[0].product.rec_name
|
|
u'Plastic Case 30x30'
|
|
>>> order.inventory_moves[0].quantity
|
|
2.0
|
|
>>> order.inventory_moves[0].start_date == order.start_date
|
|
True
|
|
>>> order.inventory_moves[0].end_date == order.end_date
|
|
True
|
|
>>> len(order.outgoing_moves)
|
|
1
|
|
>>> order.outgoing_moves[0].product.rec_name
|
|
u'Plastic Case 30x30'
|
|
>>> order.outgoing_moves[0].quantity
|
|
2.0
|
|
|
|
Undo Sale and Shipment::
|
|
|
|
>>> Sale = Model.get('sale.sale')
|
|
>>> Shipment = Model.get('stock.shipment.out')
|
|
>>> sale_id = order.sale.id
|
|
>>> shipment_id = order.shipment.id
|
|
>>> order.click('run')
|
|
>>> order.reload()
|
|
>>> not order.sale
|
|
True
|
|
>>> not order.shipment
|
|
True
|
|
>>> not order.inventory_moves
|
|
True
|
|
>>> not order.outgoing_moves
|
|
True
|
|
>>> order.state
|
|
u'running'
|
|
>>> sales = Sale.find([('id', '=', sale_id)])
|
|
>>> not sales
|
|
True
|
|
>>> shipments = Shipment.find([('id', '=', shipment_id)])
|
|
>>> not shipments
|
|
True
|
|
>>> not order.shipment
|
|
True
|