Advertisement
Guest User

scenario_account_invoice_history.rst

a guest
Mar 24th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.27 KB | None | 0 0
  1. ================
  2. Invoice Scenario
  3. ================
  4.  
  5. Imports::
  6.     >>> import datetime
  7.     >>> from dateutil.relativedelta import relativedelta
  8.     >>> from decimal import Decimal
  9.     >>> from operator import attrgetter
  10.     >>> from proteus import config, Model, Wizard
  11.     >>> today = datetime.date.today()
  12.  
  13. Create database::
  14.  
  15.     >>> config = config.set_trytond()
  16.     >>> config.pool.test = True
  17.  
  18. Install account_invoice_history::
  19.  
  20.     >>> Module = Model.get('ir.module.module')
  21.     >>> account_invoice_module, = Module.find(
  22.     ...     [('name', '=', 'account_invoice_history')])
  23.     >>> Module.install([account_invoice_module.id], config.context)
  24.     >>> Wizard('ir.module.module.install_upgrade').execute('upgrade')
  25.  
  26. Create company::
  27.  
  28.     >>> Currency = Model.get('currency.currency')
  29.     >>> CurrencyRate = Model.get('currency.currency.rate')
  30.     >>> currencies = Currency.find([('code', '=', 'USD')])
  31.     >>> if not currencies:
  32.     ...     currency = Currency(name='US Dollar', symbol=u'$', code='USD',
  33.     ...         rounding=Decimal('0.01'), mon_grouping='[]',
  34.     ...         mon_decimal_point='.')
  35.     ...     currency.save()
  36.     ...     CurrencyRate(date=today + relativedelta(month=1, day=1),
  37.     ...         rate=Decimal('1.0'), currency=currency).save()
  38.     ... else:
  39.     ...     currency, = currencies
  40.     >>> Company = Model.get('company.company')
  41.     >>> Party = Model.get('party.party')
  42.     >>> company_config = Wizard('company.company.config')
  43.     >>> company_config.execute('company')
  44.     >>> company = company_config.form
  45.     >>> party = Party(name='Dunder Mifflin')
  46.     >>> party.save()
  47.     >>> company.party = party
  48.     >>> company.currency = currency
  49.     >>> company_config.execute('add')
  50.     >>> company, = Company.find([])
  51.  
  52. Reload the context::
  53.  
  54.     >>> User = Model.get('res.user')
  55.     >>> config._context = User.get_preferences(True, config.context)
  56.  
  57. Create fiscal year::
  58.  
  59.     >>> FiscalYear = Model.get('account.fiscalyear')
  60.     >>> Sequence = Model.get('ir.sequence')
  61.     >>> SequenceStrict = Model.get('ir.sequence.strict')
  62.     >>> fiscalyear = FiscalYear(name=str(today.year))
  63.     >>> fiscalyear.start_date = today + relativedelta(month=1, day=1)
  64.     >>> fiscalyear.end_date = today + relativedelta(month=12, day=31)
  65.     >>> fiscalyear.company = company
  66.     >>> post_move_seq = Sequence(name=str(today.year), code='account.move',
  67.     ...     company=company)
  68.     >>> post_move_seq.save()
  69.     >>> fiscalyear.post_move_sequence = post_move_seq
  70.     >>> invoice_seq = SequenceStrict(name=str(today.year),
  71.     ...     code='account.invoice', company=company)
  72.     >>> invoice_seq.save()
  73.     >>> fiscalyear.out_invoice_sequence = invoice_seq
  74.     >>> fiscalyear.in_invoice_sequence = invoice_seq
  75.     >>> fiscalyear.out_credit_note_sequence = invoice_seq
  76.     >>> fiscalyear.in_credit_note_sequence = invoice_seq
  77.     >>> fiscalyear.save()
  78.     >>> FiscalYear.create_period([fiscalyear.id], config.context)
  79.  
  80. Create chart of accounts::
  81.  
  82.     >>> AccountTemplate = Model.get('account.account.template')
  83.     >>> Account = Model.get('account.account')
  84.     >>> account_template, = AccountTemplate.find([('parent', '=', None)])
  85.     >>> create_chart = Wizard('account.create_chart')
  86.     >>> create_chart.execute('account')
  87.     >>> create_chart.form.account_template = account_template
  88.     >>> create_chart.form.company = company
  89.     >>> create_chart.execute('create_account')
  90.     >>> receivable, = Account.find([
  91.     ...         ('kind', '=', 'receivable'),
  92.     ...         ('company', '=', company.id),
  93.     ...         ])
  94.     >>> payable, = Account.find([
  95.     ...         ('kind', '=', 'payable'),
  96.     ...         ('company', '=', company.id),
  97.     ...         ])
  98.     >>> create_chart.form.account_receivable = receivable
  99.     >>> create_chart.form.account_payable = payable
  100.     >>> create_chart.execute('create_properties')
  101.  
  102. Create party::
  103.  
  104.     >>> Party = Model.get('party.party')
  105.     >>> party = Party(name='Party')
  106.     >>> party.addresses[0].street = 'Street'
  107.     >>> party.addresses[0].invoice = True
  108.     >>> party.save()
  109.  
  110. Create product::
  111.  
  112.     >>> ProductUom = Model.get('product.uom')
  113.     >>> unit, = ProductUom.find([('name', '=', 'Unit')])
  114.     >>> ProductTemplate = Model.get('product.template')
  115.     >>> Product = Model.get('product.product')
  116.     >>> product = Product()
  117.     >>> template = ProductTemplate()
  118.     >>> template.name = 'product'
  119.     >>> template.default_uom = unit
  120.     >>> template.type = 'service'
  121.     >>> template.list_price = Decimal('40')
  122.     >>> template.cost_price = Decimal('25')
  123.     >>> template.save()
  124.     >>> product.template = template
  125.     >>> product.save()
  126.  
  127. Create payment term::
  128.  
  129.     >>> PaymentTerm = Model.get('account.invoice.payment_term')
  130.     >>> PaymentTermLine = Model.get('account.invoice.payment_term.line')
  131.     >>> payment_term = PaymentTerm(name='Term')
  132.     >>> payment_term_line = PaymentTermLine(type='percent', days=20,
  133.     ...     percentage=Decimal(50))
  134.     >>> payment_term.lines.append(payment_term_line)
  135.     >>> payment_term_line = PaymentTermLine(type='remainder', days=40)
  136.     >>> payment_term.lines.append(payment_term_line)
  137.     >>> payment_term.save()
  138.  
  139. Create invoice::
  140.  
  141.     >>> Invoice = Model.get('account.invoice')
  142.     >>> invoice = Invoice()
  143.     >>> invoice.party = party
  144.     >>> invoice.payment_term = payment_term
  145.     >>> import interlude; interlude.interact(locals())
  146.     >>> invoice.save()
  147.     >>> Invoice.post([invoice.id], config.context)
  148.     >>> invoice.reload()
  149.     >>> invoice.state
  150.     u'paid'
  151.  
  152. Check invoice party and address::
  153.  
  154.     >>> invoice.party == party
  155.     True
  156.     >>> invoice.party.name
  157.     u'Party'
  158.     >>> invoice.invoice_address == party.addresses[0]
  159.     True
  160.     >>> invoice.invoice_address.street
  161.     u'Street'
  162.  
  163. Change party and address::
  164.  
  165.     >>> party = Party(party.id)
  166.     >>> party.name = 'Party changed'
  167.     >>> party.addresses[0].street = 'Street changed'
  168.     >>> party.addresses[0].save()
  169.     >>> party.save()
  170.  
  171. Check new values::
  172.  
  173.     >>> party = Party(party.id)
  174.     >>> party.name
  175.     u'Party changed'
  176.     >>> party.addresses[0].street
  177.     u'Street changed'
  178.  
  179. Check historized party and address on invoice::
  180.  
  181.     >>> invoice = Invoice(invoice.id)
  182.     >>> invoice.party.name          
  183.     u'Party changed' # WRONG! should be u'Party'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement