/usr/lib/python2.7/dist-packages/trytond/modules/account/tests/scenario_move_template.rst is in tryton-modules-account 4.2.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | ======================
Move Template Scenario
======================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model, Wizard
>>> from trytond.tests.tools import activate_modules
>>> from trytond.modules.company.tests.tools import create_company, \
... get_company
>>> from trytond.modules.account.tests.tools import create_fiscalyear, \
... create_chart, get_accounts, create_tax, set_tax_code
Install account::
>>> config = activate_modules('account')
Create company::
>>> _ = create_company()
>>> company = get_company()
Create fiscal year::
>>> fiscalyear = create_fiscalyear(company)
>>> fiscalyear.click('create_period')
>>> period = fiscalyear.periods[0]
Create chart of accounts::
>>> _ = create_chart(company)
>>> accounts = get_accounts(company)
>>> payable = accounts['payable']
>>> expense = accounts['expense']
>>> tax = accounts['tax']
Create tax with code::
>>> tax = set_tax_code(create_tax(Decimal('0.1')))
>>> tax.save()
Create parties::
>>> Party = Model.get('party.party')
>>> supplier = Party(name='Supplier')
>>> supplier.save()
Create Template::
>>> MoveTemplate = Model.get('account.move.template')
>>> Journal = Model.get('account.journal')
>>> template = MoveTemplate()
>>> template.name = 'Test'
>>> template.journal, = Journal.find([
... ('code', '=', 'CASH'),
... ])
>>> _ = template.keywords.new(name='party', string='Party',
... type_='party')
>>> _ = template.keywords.new(name='description', string='Description',
... type_='char')
>>> _ = template.keywords.new(name='amount', string='Amount',
... type_='numeric', digits=2)
>>> template.description = '{party} - {description}'
>>> line = template.lines.new()
>>> line.operation = 'credit'
>>> line.account = payable
>>> line.party = 'party'
>>> line.amount = 'amount'
>>> line = template.lines.new()
>>> line.operation = 'debit'
>>> line.account = expense
>>> line.amount = 'amount / 1.1'
>>> ttax = line.taxes.new()
>>> ttax.amount = line.amount
>>> ttax.code = tax.invoice_base_code
>>> ttax.tax = tax
>>> line = template.lines.new()
>>> line.operation = 'debit'
>>> line.account = tax.invoice_account
>>> line.amount = 'amount * (1 - 1/1.1)'
>>> ttax = line.taxes.new()
>>> ttax.amount = line.amount
>>> ttax.code = tax.invoice_tax_code
>>> ttax.tax = tax
>>> template.save()
Create Move::
>>> create_move = Wizard('account.move.template.create')
>>> create_move.form.template = template
>>> create_move.execute('keywords')
>>> data = {}
>>> keywords = data['keywords'] = {}
>>> keywords['party'] = supplier.id
>>> keywords['description'] = 'Test'
>>> keywords['amount'] = Decimal('12.24')
>>> context = create_move._context.copy()
>>> context.update(create_move._config.context)
>>> _ = create_move._proxy.execute(create_move.session_id, data, 'create_',
... context)
.. note:: using custom call because proteus doesn't support fake model
Check the Move::
>>> Move = Model.get('account.move')
>>> move, = Move.find([])
>>> len(move.lines)
3
>>> sorted((l.debit, l.credit) for l in move.lines)
[(Decimal('0'), Decimal('12.24')), (Decimal('1.11'), Decimal('0')), (Decimal('11.13'), Decimal('0'))]
>>> move.description
u'Supplier - Test'
>>> tax.invoice_base_code.sum
Decimal('11.13')
>>> tax.invoice_tax_code.sum
Decimal('1.11')
|