189 lines
5.5 KiB
ReStructuredText
189 lines
5.5 KiB
ReStructuredText
=============================
|
|
Account Invoice Shop Scenario
|
|
=============================
|
|
|
|
Imports::
|
|
|
|
>>> import datetime
|
|
>>> from dateutil.relativedelta import relativedelta
|
|
>>> from decimal import Decimal
|
|
>>> from operator import attrgetter
|
|
>>> from proteus import config, 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
|
|
>>> from trytond.modules.account_invoice.tests.tools import \
|
|
... set_fiscalyear_invoice_sequences, create_payment_term
|
|
>>> from trytond.modules.sale_shop.tests.tools import create_shop
|
|
>>> today = datetime.date.today()
|
|
|
|
Install sale::
|
|
|
|
>>> config = activate_modules('account_invoice_shop')
|
|
|
|
Create company::
|
|
|
|
>>> _ = create_company()
|
|
>>> company = get_company()
|
|
|
|
Reload the context::
|
|
|
|
>>> User = Model.get('res.user')
|
|
>>> config._context = User.get_preferences(True, config.context)
|
|
|
|
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 payment term::
|
|
|
|
>>> payment_term = create_payment_term()
|
|
>>> payment_term.save()
|
|
|
|
Create product price list::
|
|
|
|
>>> ProductPriceList = Model.get('product.price_list')
|
|
>>> product_price_list = ProductPriceList()
|
|
>>> product_price_list.name = 'Price List'
|
|
>>> product_price_list.company = company
|
|
>>> product_price_list.save()
|
|
|
|
Create parties::
|
|
|
|
>>> Party = Model.get('party.party')
|
|
>>> supplier = Party(name='Supplier')
|
|
>>> supplier.save()
|
|
>>> customer = Party(name='Customer')
|
|
>>> customer.save()
|
|
|
|
Create category::
|
|
|
|
>>> ProductCategory = Model.get('product.category')
|
|
>>> category = ProductCategory(name='Category')
|
|
>>> category.save()
|
|
|
|
Create product::
|
|
|
|
>>> ProductUom = Model.get('product.uom')
|
|
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
|
>>> ProductTemplate = Model.get('product.template')
|
|
>>> Product = Model.get('product.product')
|
|
>>> product = Product()
|
|
>>> template = ProductTemplate()
|
|
>>> template.name = 'product'
|
|
>>> template.default_uom = unit
|
|
>>> template.type = 'goods'
|
|
>>> template.list_price = Decimal('40')
|
|
>>> template.cost_price = Decimal('25')
|
|
>>> template.account_expense = expense
|
|
>>> template.account_revenue = revenue
|
|
>>> template.salable = True
|
|
>>> template.customer_taxes.append(tax)
|
|
>>> template.save()
|
|
>>> product.template = template
|
|
>>> product.save()
|
|
|
|
Create an Inventory::
|
|
|
|
>>> Inventory = Model.get('stock.inventory')
|
|
>>> InventoryLine = Model.get('stock.inventory.line')
|
|
>>> Location = Model.get('stock.location')
|
|
>>> storage, = Location.find([
|
|
... ('code', '=', 'STO'),
|
|
... ])
|
|
>>> inventory = Inventory()
|
|
>>> inventory.location = storage
|
|
>>> inventory.save()
|
|
>>> inventory_line = InventoryLine(product=product, inventory=inventory)
|
|
>>> inventory_line.quantity = 100.0
|
|
>>> inventory_line.expected_quantity = 0.0
|
|
>>> inventory.save()
|
|
>>> inventory_line.save()
|
|
>>> Inventory.confirm([inventory.id], config.context)
|
|
>>> inventory.state
|
|
u'done'
|
|
|
|
Create Sale Shop::
|
|
|
|
>>> shop = create_shop(payment_term, product_price_list)
|
|
>>> shop.save()
|
|
|
|
Save Sale Shop User::
|
|
|
|
>>> user, = User.find([])
|
|
>>> user.shops.append(shop)
|
|
>>> user.shop = shop
|
|
>>> user.save()
|
|
|
|
Invoice 5 products::
|
|
|
|
>>> Invoice = Model.get('account.invoice')
|
|
>>> InvoiceLine = Model.get('account.invoice.line')
|
|
>>> invoice = Invoice()
|
|
>>> invoice.party = customer
|
|
>>> invoice.payment_term = payment_term
|
|
>>> invoice_line = InvoiceLine()
|
|
>>> invoice.lines.append(invoice_line)
|
|
>>> invoice_line.product = product
|
|
>>> invoice_line.quantity = 2.0
|
|
>>> invoice_line.unit_price = product.list_price
|
|
>>> invoice_line = InvoiceLine()
|
|
>>> invoice.lines.append(invoice_line)
|
|
>>> invoice_line.product = product
|
|
>>> invoice_line.quantity = 3.0
|
|
>>> invoice_line.unit_price = product.list_price
|
|
>>> invoice.save()
|
|
>>> invoice.state
|
|
u'draft'
|
|
|
|
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 = 'order'
|
|
>>> sale_line = SaleLine()
|
|
>>> sale.lines.append(sale_line)
|
|
>>> sale_line.product = product
|
|
>>> sale_line.quantity = 2.0
|
|
>>> sale_line = SaleLine()
|
|
>>> sale.lines.append(sale_line)
|
|
>>> sale_line.product = product
|
|
>>> sale_line.quantity = 3.0
|
|
>>> sale.save()
|
|
>>> sale.state
|
|
u'draft'
|
|
>>> sale.click('quote')
|
|
>>> sale.click('confirm')
|
|
>>> sale.click('process')
|
|
>>> sale.state
|
|
u'processing'
|
|
>>> invoice, = sale.invoices
|
|
>>> invoice.shop == shop
|
|
True
|