diff --git a/tests/scenario_account_stock_anglo_saxon.rst b/tests/scenario_account_stock_anglo_saxon.rst index 885c98455a..1a938d499a 100644 --- a/tests/scenario_account_stock_anglo_saxon.rst +++ b/tests/scenario_account_stock_anglo_saxon.rst @@ -2,16 +2,22 @@ Account Stock Anglo-Saxon Scenario ================================== -============= -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 + >>> from trytond.modules.account.tests.tools import create_fiscalyear, \ + ... create_chart, get_accounts + >>> from.trytond.modules.account_invoice.tests.tools import \ + ... set_fiscalyear_invoice_sequences, create_payment_term + >>> from trytond.modules.account_stock_continental.tests.tools import \ + ... add_stock_accounts + >>> from trytond.modules.account_stock_anglo_saxon.tests.tools import \ + ... add_cogs_accounts >>> today = datetime.date.today() Create database:: @@ -26,40 +32,19 @@ Install account_stock_continental, sale and purchase:: ... ('name', 'in', ('account_stock_anglo_saxon', ... 'sale', 'purchase')), ... ]) - >>> Module.install([x.id for x in modules], config.context) + >>> for module in modules: + ... 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='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.currency = currency - >>> company_config.execute('add') - >>> company, = Company.find() + >>> _ = create_company() + >>> company = get_company() Reload the context:: >>> User = Model.get('res.user') - >>> config._context = User.get_preferences(True, - ... config.context) + >>> config._context = User.get_preferences(True, config.context) Create an accountant user:: @@ -74,71 +59,28 @@ Create an accountant user:: Create fiscal year:: - >>> FiscalYear = Model.get('account.fiscalyear') - >>> Sequence = Model.get('ir.sequence') - >>> SequenceStrict = Model.get('ir.sequence.strict') - >>> fiscalyear = FiscalYear(name='%s' % today.year) - >>> fiscalyear.start_date = today + relativedelta(month=1, day=1) - >>> fiscalyear.end_date = today + relativedelta(month=12, day=31) - >>> fiscalyear.company = company + >>> fiscalyear = set_fiscalyear_invoice_sequences( + ... create_fiscalyear(company)) >>> fiscalyear.account_stock_method = 'anglo_saxon' - >>> post_move_sequence = Sequence(name='%s' % today.year, - ... code='account.move', - ... company=company) - >>> post_move_sequence.save() - >>> fiscalyear.post_move_sequence = post_move_sequence - >>> invoice_sequence = SequenceStrict(name='%s' % today.year, - ... code='account.invoice', - ... company=company) - >>> invoice_sequence.save() - >>> fiscalyear.out_invoice_sequence = invoice_sequence - >>> fiscalyear.in_invoice_sequence = invoice_sequence - >>> fiscalyear.out_credit_note_sequence = invoice_sequence - >>> fiscalyear.in_credit_note_sequence = invoice_sequence - >>> fiscalyear.save() - >>> FiscalYear.create_period([fiscalyear.id], config.context) + >>> fiscalyear.click('create_period') Create chart of accounts:: - >>> AccountTemplate = Model.get('account.account.template') - >>> Account = Model.get('account.account') + >>> _ = create_chart(company) + >>> accounts = add_cogs_accounts(add_stock_accounts( + ... get_accounts(company), company), company) + >>> receivable = accounts['receivable'] + >>> payable = accounts['payable'] + >>> revenue = accounts['revenue'] + >>> expense = accounts['expense'] + >>> stock = accounts['stock'] + >>> stock_customer = accounts['stock_customer'] + >>> stock_lost_found = accounts['stock_lost_found'] + >>> stock_production = accounts['stock_production'] + >>> stock_supplier = accounts['stock_supplier'] + >>> cogs = accounts['cogs'] + >>> AccountJournal = 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), - ... ]) - >>> (stock, stock_customer, stock_lost_found, stock_production, - ... stock_supplier) = Account.find([ - ... ('kind', '=', 'stock'), - ... ('company', '=', company.id), - ... ('name', 'like', 'Stock%'), - ... ], order=[('name', 'ASC')]) - >>> cogs, = Account.find([ - ... ('kind', '=', 'other'), - ... ('company', '=', company.id), - ... ('name', '=', 'COGS'), - ... ]) - >>> create_chart.form.account_receivable = receivable - >>> create_chart.form.account_payable = payable - >>> create_chart.execute('create_properties') >>> stock_journal, = AccountJournal.find([('code', '=', 'STO')]) Create parties:: @@ -187,38 +129,30 @@ Create product:: >>> template.save() >>> product.template = template >>> product.save() - >>> template_average = ProductTemplate(ProductTemplate.copy([template.id], - ... config.context)[0]) + >>> template_average, = ProductTemplate.duplicate([template]) >>> template_average.cost_price_method = 'average' >>> template_average.save() - >>> product_average = Product(Product.copy([product.id], { + >>> product_average, = Product.duplicate([product], { ... 'template': template_average.id, - ... }, config.context)[0]) + ... }) Create payment term:: - >>> PaymentTerm = Model.get('account.invoice.payment_term') - >>> PaymentTermLine = Model.get('account.invoice.payment_term.line') - >>> payment_term = PaymentTerm(name='Direct') - >>> payment_term_line = PaymentTermLine(type='remainder', days=0) - >>> payment_term.lines.append(payment_term_line) + >>> payment_term = create_payment_term() >>> payment_term.save() Purchase 12 products:: >>> Purchase = Model.get('purchase.purchase') - >>> PurchaseLine = Model.get('purchase.line') >>> purchase = Purchase() >>> purchase.party = supplier >>> purchase.payment_term = payment_term >>> purchase.invoice_method = 'shipment' - >>> purchase_line = PurchaseLine() - >>> purchase.lines.append(purchase_line) + >>> purchase_line = purchase.lines.new() >>> purchase_line.product = product >>> purchase_line.quantity = 5.0 >>> purchase_line.unit_price = Decimal(4) - >>> purchase_line = PurchaseLine() - >>> purchase.lines.append(purchase_line) + >>> purchase_line = purchase.lines.new() >>> purchase_line.product = product_average >>> purchase_line.quantity = 7.0 >>> purchase_line.unit_price = Decimal(6) @@ -239,9 +173,8 @@ Receive 9 products:: >>> move = Move(purchase.moves[1].id) >>> shipment.incoming_moves.append(move) >>> move.quantity = 5.0 - >>> shipment.save() - >>> ShipmentIn.receive([shipment.id], config.context) - >>> ShipmentIn.done([shipment.id], config.context) + >>> shipment.click('receive') + >>> shipment.click('done') >>> shipment.state u'done' >>> stock_supplier.reload() @@ -271,8 +204,7 @@ Open supplier invoice:: >>> invoice_line = invoice.lines[1] >>> invoice_line.unit_price = Decimal('4') >>> invoice.invoice_date = today - >>> invoice.save() - >>> Invoice.post([invoice.id], config.context) + >>> invoice.click('post') >>> invoice.state u'posted' >>> payable.reload() @@ -294,23 +226,19 @@ Open supplier invoice:: Sale 5 products:: >>> Sale = Model.get('sale.sale') - >>> SaleLine = Model.get('sale.line') >>> sale = Sale() >>> sale.party = customer >>> sale.payment_term = payment_term >>> sale.invoice_method = 'shipment' - >>> sale_line = SaleLine() - >>> sale.lines.append(sale_line) + >>> sale_line = sale.lines.new() >>> sale_line.product = product >>> sale_line.quantity = 2.0 - >>> sale_line = SaleLine() - >>> sale.lines.append(sale_line) + >>> sale_line = sale.lines.new() >>> sale_line.product = product_average >>> sale_line.quantity = 3.0 - >>> sale.save() - >>> Sale.quote([sale.id], config.context) - >>> Sale.confirm([sale.id], config.context) - >>> Sale.process([sale.id], config.context) + >>> sale.click('quote') + >>> sale.click('confirm') + >>> sale.click('process') >>> sale.state u'processing' @@ -318,16 +246,14 @@ Send 5 products:: >>> ShipmentOut = Model.get('stock.shipment.out') >>> shipment, = sale.shipments - >>> ShipmentOut.assign_try([shipment.id], config.context) + >>> shipment.click('assign_try') True >>> shipment.state u'assigned' - >>> shipment.reload() - >>> ShipmentOut.pack([shipment.id], config.context) + >>> shipment.click('pack') >>> shipment.state u'packed' - >>> shipment.reload() - >>> ShipmentOut.done([shipment.id], config.context) + >>> shipment.click('done') >>> shipment.state u'done' >>> stock_customer.reload() @@ -345,7 +271,7 @@ Open customer invoice:: >>> sale.reload() >>> invoice, = sale.invoices - >>> Invoice.post([invoice.id], config.context) + >>> invoice.click('post') >>> invoice.state u'posted' >>> receivable.reload() @@ -375,8 +301,7 @@ Now create a supplier invoice with an accountant:: >>> purchase.party = supplier >>> purchase.payment_term = payment_term >>> purchase.invoice_method = 'order' - >>> purchase_line = PurchaseLine() - >>> purchase.lines.append(purchase_line) + >>> purchase_line = purchase.lines.new() >>> purchase_line.product = product >>> purchase_line.quantity = 5.0 >>> purchase_line.unit_price = Decimal(4) @@ -386,12 +311,11 @@ Now create a supplier invoice with an accountant:: >>> purchase.state u'processing' - >>> invoice_ids = [i.id for i in purchase.invoices] >>> config.user = accountant.id - >>> Invoice.write(invoice_ids, { - ... 'invoice_date': today, - ... }, config.context) - >>> Invoice.validate_invoice([i.id for i in purchase.invoices], config.context) + >>> for invoice in purchase.invoices: + ... invoice.invoice_date = today + >>> Invoice.save(purchase.invoices) + >>> Invoice.click(purchase.invoices, 'validate_invoice') Create customer invoice with negative quantity:: @@ -401,8 +325,7 @@ Create customer invoice with negative quantity:: >>> invoice_line = invoice.lines.new() >>> invoice_line.product = product >>> invoice_line.quantity = -1 - >>> invoice.save() - >>> Invoice.post([invoice.id], config.context) + >>> invoice.click('post') >>> invoice.state u'posted' >>> move = invoice.move diff --git a/tests/scenario_account_stock_anglo_saxon_with_drop_shipment.rst b/tests/scenario_account_stock_anglo_saxon_with_drop_shipment.rst index 88f2f51b59..ddc05745dd 100644 --- a/tests/scenario_account_stock_anglo_saxon_with_drop_shipment.rst +++ b/tests/scenario_account_stock_anglo_saxon_with_drop_shipment.rst @@ -2,16 +2,22 @@ Account Stock Anglo-Saxon with Drop Shipment Scenario ===================================================== -============= -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 + >>> from trytond.modules.account.tests.tools import create_fiscalyear, \ + ... create_chart, get_accounts + >>> from.trytond.modules.account_invoice.tests.tools import \ + ... set_fiscalyear_invoice_sequences, create_payment_term + >>> from trytond.modules.account_stock_continental.tests.tools import \ + ... add_stock_accounts + >>> from trytond.modules.account_stock_anglo_saxon.tests.tools import \ + ... add_cogs_accounts >>> today = datetime.date.today() Create database:: @@ -26,34 +32,14 @@ Install sale_supply, sale, purchase:: ... ('name', 'in', ('account_stock_anglo_saxon', ... 'sale_supply_drop_shipment', 'sale', 'purchase')), ... ]) - >>> Module.install([x.id for x in modules], config.context) + >>> for module in modules: + ... 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='Euro', symbol=u'$', 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:: @@ -106,71 +92,28 @@ Create account user:: Create fiscal year:: - >>> FiscalYear = Model.get('account.fiscalyear') - >>> Sequence = Model.get('ir.sequence') - >>> SequenceStrict = Model.get('ir.sequence.strict') - >>> fiscalyear = FiscalYear(name='%s' % today.year) - >>> fiscalyear.start_date = today + relativedelta(month=1, day=1) - >>> fiscalyear.end_date = today + relativedelta(month=12, day=31) - >>> fiscalyear.company = company + >>> fiscalyear = set_fiscalyear_invoice_sequences( + ... create_fiscalyear(company)) >>> fiscalyear.account_stock_method = 'anglo_saxon' - >>> post_move_sequence = Sequence(name='%s' % today.year, - ... code='account.move', - ... company=company) - >>> post_move_sequence.save() - >>> fiscalyear.post_move_sequence = post_move_sequence - >>> invoice_sequence = SequenceStrict(name='%s' % today.year, - ... code='account.invoice', - ... company=company) - >>> invoice_sequence.save() - >>> fiscalyear.out_invoice_sequence = invoice_sequence - >>> fiscalyear.in_invoice_sequence = invoice_sequence - >>> fiscalyear.out_credit_note_sequence = invoice_sequence - >>> fiscalyear.in_credit_note_sequence = invoice_sequence - >>> fiscalyear.save() - >>> FiscalYear.create_period([fiscalyear.id], config.context) + >>> fiscalyear.click('create_period') Create chart of accounts:: - >>> AccountTemplate = Model.get('account.account.template') - >>> Account = Model.get('account.account') + >>> _ = create_chart(company) + >>> accounts = add_cogs_accounts(add_stock_accounts( + ... get_accounts(company), company), company) + >>> receivable = accounts['receivable'] + >>> payable = accounts['payable'] + >>> revenue = accounts['revenue'] + >>> expense = accounts['expense'] + >>> stock = accounts['stock'] + >>> stock_customer = accounts['stock_customer'] + >>> stock_lost_found = accounts['stock_lost_found'] + >>> stock_production = accounts['stock_production'] + >>> stock_supplier = accounts['stock_supplier'] + >>> cogs = accounts['cogs'] + >>> AccountJournal = 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), - ... ]) - >>> (stock, stock_customer, stock_lost_found, stock_production, - ... stock_supplier) = Account.find([ - ... ('kind', '=', 'stock'), - ... ('company', '=', company.id), - ... ('name', 'like', 'Stock%'), - ... ], order=[('name', 'ASC')]) - >>> cogs, = Account.find([ - ... ('kind', '=', 'other'), - ... ('company', '=', company.id), - ... ('name', '=', 'COGS'), - ... ]) - >>> create_chart.form.account_receivable = receivable - >>> create_chart.form.account_payable = payable - >>> create_chart.execute('create_properties') >>> stock_journal, = AccountJournal.find([('code', '=', 'STO')]) Create parties:: @@ -223,29 +166,22 @@ Create product:: Create payment term:: - >>> PaymentTerm = Model.get('account.invoice.payment_term') - >>> PaymentTermLine = Model.get('account.invoice.payment_term.line') - >>> payment_term = PaymentTerm(name='Direct') - >>> payment_term_line = PaymentTermLine(type='remainder', days=0) - >>> payment_term.lines.append(payment_term_line) + >>> payment_term = create_payment_term() >>> payment_term.save() Sale 50 products:: >>> config.user = sale_user.id >>> Sale = Model.get('sale.sale') - >>> SaleLine = Model.get('sale.line') >>> sale = Sale() >>> sale.party = customer >>> sale.payment_term = payment_term - >>> sale_line = SaleLine() - >>> sale.lines.append(sale_line) + >>> sale_line = sale.lines.new() >>> sale_line.product = product >>> sale_line.quantity = 50 - >>> sale.save() - >>> Sale.quote([sale.id], config.context) - >>> Sale.confirm([sale.id], config.context) - >>> Sale.process([sale.id], config.context) + >>> sale.click('quote') + >>> sale.click('confirm') + >>> sale.click('process') >>> sale.state u'processing' @@ -275,8 +211,7 @@ Create Purchase from Request:: Receive 50 products:: >>> config.user = stock_user.id - >>> ShipmentDrop = Model.get('stock.shipment.drop') - >>> ShipmentDrop.done([shipment.id], config.context) + >>> shipment.click('done') >>> shipment.state u'done' >>> stock_supplier.reload() @@ -297,14 +232,12 @@ Receive 50 products:: Open supplier invoice:: - >>> Invoice = Model.get('account.invoice') >>> config.user = purchase_user.id >>> purchase.reload() >>> invoice, = purchase.invoices >>> config.user = account_user.id >>> invoice.invoice_date = today - >>> invoice.save() - >>> Invoice.post([invoice.id], config.context) + >>> invoice.click('post') >>> invoice.state u'posted' >>> payable.reload() @@ -329,7 +262,7 @@ Open customer invoice:: >>> sale.reload() >>> invoice, = sale.invoices >>> config.user = account_user.id - >>> Invoice.post([invoice.id], config.context) + >>> invoice.click('post') >>> invoice.state u'posted' >>> receivable.reload() diff --git a/tests/tools.py b/tests/tools.py new file mode 100644 index 0000000000..d78cd794f2 --- /dev/null +++ b/tests/tools.py @@ -0,0 +1,20 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. +from proteus import Model + +from trytond.modules.company.tests.tools import get_company + + +def add_cogs_accounts(accounts, company=None, config=None): + "Add COGS to accounts" + Account = Model.get('account.account', config=config) + + if not company: + company = get_company() + + accounts['cogs'], = Account.find([ + ('kind', '=', 'other'), + ('company', '=', company.id), + ('name', '=', 'COGS'), + ]) + return accounts