341 lines
9.7 KiB
ReStructuredText
341 lines
9.7 KiB
ReStructuredText
=================
|
|
Sale POS Scenario
|
|
=================
|
|
|
|
Imports::
|
|
|
|
>>> import datetime
|
|
>>> from dateutil.relativedelta import relativedelta
|
|
>>> from decimal import Decimal
|
|
>>> from operator import attrgetter
|
|
>>> from proteus import config, Model, Wizard, Report
|
|
>>> 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
|
|
>>> today = datetime.date.today()
|
|
|
|
Create database::
|
|
|
|
>>> config = config.set_trytond()
|
|
>>> config.pool.test = True
|
|
|
|
Install sale::
|
|
|
|
>>> Module = Model.get('ir.module')
|
|
>>> module, = Module.find([('name', '=', 'sale_pos')])
|
|
>>> module.click('install')
|
|
>>> Wizard('ir.module.install_upgrade').execute('upgrade')
|
|
|
|
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 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 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.category = category
|
|
>>> template.default_uom = unit
|
|
>>> template.type = 'goods'
|
|
>>> template.purchasable = True
|
|
>>> template.salable = True
|
|
>>> template.list_price = Decimal('10')
|
|
>>> template.cost_price = Decimal('5')
|
|
>>> template.cost_price_method = 'fixed'
|
|
>>> template.account_expense = expense
|
|
>>> template.account_revenue = revenue
|
|
>>> template.customer_taxes.append(tax)
|
|
>>> template.save()
|
|
>>> product.template = template
|
|
>>> product.save()
|
|
|
|
Create payment term::
|
|
|
|
>>> payment_term = create_payment_term()
|
|
>>> payment_term.save()
|
|
|
|
Create a shop::
|
|
|
|
>>> Shop = Model.get('sale.shop')
|
|
>>> PriceList = Model.get('product.price_list')
|
|
>>> Location = Model.get('stock.location')
|
|
>>> Sequence = Model.get('ir.sequence')
|
|
>>> warehouse, = Location.find([
|
|
... ('code', '=', 'WH'),
|
|
... ])
|
|
>>> price_list = PriceList()
|
|
>>> price_list.name = 'Default price list'
|
|
>>> price_list.save()
|
|
>>> shop = Shop()
|
|
>>> shop.name = 'Local shop'
|
|
>>> shop.warehouse = warehouse
|
|
>>> shop.shipment_method = 'order'
|
|
>>> shop.invoice_method = 'order'
|
|
>>> sequence, = Sequence.find([('code', '=', 'sale.sale')])
|
|
>>> shop.sale_sequence = sequence
|
|
>>> shop.payment_term = payment_term
|
|
>>> shop.price_list = price_list
|
|
>>> shop.party = customer
|
|
>>> shop.self_pick_up = True
|
|
>>> shop.save()
|
|
|
|
Create journals::
|
|
|
|
>>> StatementJournal = Model.get('account.statement.journal')
|
|
>>> sequence = Sequence(name='Satement',
|
|
... code='account.journal',
|
|
... company=company,
|
|
... )
|
|
>>> sequence.save()
|
|
>>> account_journal = Journal(name='Statement',
|
|
... type='statement',
|
|
... credit_account=cash,
|
|
... debit_account=cash,
|
|
... sequence=sequence,
|
|
... )
|
|
>>> account_journal.save()
|
|
>>> statement_journal = StatementJournal(name='Default',
|
|
... journal=account_journal,
|
|
... validation='balance',
|
|
... )
|
|
>>> statement_journal.save()
|
|
|
|
Create a device::
|
|
|
|
>>> Device = Model.get('sale.device')
|
|
>>> device = Device()
|
|
>>> device.shop = shop
|
|
>>> device.name = 'Default'
|
|
>>> device.journals.append(statement_journal)
|
|
>>> device.journal = statement_journal
|
|
>>> device.save()
|
|
|
|
Reload the context::
|
|
|
|
>>> User = Model.get('res.user')
|
|
>>> Group = Model.get('res.group')
|
|
>>> user, = User.find([('login', '=', 'admin')])
|
|
>>> user.shops.append(shop)
|
|
>>> user.shop = shop
|
|
>>> user.sale_device = device
|
|
>>> user.save()
|
|
>>> config._context = User.get_preferences(True, config.context)
|
|
|
|
Create sale user::
|
|
|
|
>>> shop = Shop(shop.id)
|
|
>>> 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.shops.append(shop)
|
|
>>> sale_user.shop = shop
|
|
>>> sale_user.sale_device = device
|
|
>>> sale_user.save()
|
|
|
|
Create stock user::
|
|
|
|
>>> shop = Shop(shop.id)
|
|
>>> 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.shops.append(shop)
|
|
>>> stock_user.shop = shop
|
|
>>> stock_user.sale_device = device
|
|
>>> stock_user.save()
|
|
|
|
Create account user::
|
|
|
|
>>> shop = Shop(shop.id)
|
|
>>> 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.shops.append(shop)
|
|
>>> account_user.shop = shop
|
|
>>> account_user.sale_device = device
|
|
>>> account_user.save()
|
|
|
|
Create an Inventory::
|
|
|
|
>>> config.user = stock_user.id
|
|
>>> Inventory = Model.get('stock.inventory')
|
|
>>> InventoryLine = Model.get('stock.inventory.line')
|
|
>>> 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'
|
|
|
|
Sale 2 products::
|
|
|
|
>>> config.user = sale_user.id
|
|
>>> Sale = Model.get('sale.sale')
|
|
>>> SaleLine = Model.get('sale.line')
|
|
>>> sale = Sale()
|
|
>>> sale.shop == shop
|
|
True
|
|
>>> sale.party == customer
|
|
True
|
|
>>> sale.payment_term == payment_term
|
|
True
|
|
>>> sale.price_list == price_list
|
|
True
|
|
>>> sale.invoice_method
|
|
'order'
|
|
>>> sale.shipment_method
|
|
'order'
|
|
>>> bool(sale.self_pick_up)
|
|
True
|
|
>>> sale_line = sale.lines.new()
|
|
>>> sale_line.product = product
|
|
>>> sale_line.quantity = 2.0
|
|
>>> sale.save()
|
|
>>> sale_line, = sale.lines
|
|
>>> sale_line.unit_price_w_tax
|
|
Decimal('11.000000')
|
|
>>> sale_line.amount_w_tax
|
|
Decimal('22.00')
|
|
>>> len(sale.shipments), len(sale.invoices), len(sale.payments)
|
|
(0, 0, 0)
|
|
|
|
Open statements for current device::
|
|
|
|
>>> Statement = Model.get('account.statement')
|
|
>>> len(Statement.find([('state', '=', 'draft')]))
|
|
0
|
|
>>> open_statment = Wizard('open.statement')
|
|
>>> open_statment.execute('create_')
|
|
>>> open_statment.form.result
|
|
u'Statement Default opened. \n'
|
|
>>> payment_statement, = Statement.find([('state', '=', 'draft')])
|
|
|
|
When the sale is paid moves and invoices are generated::
|
|
|
|
>>> pay_sale = Wizard('sale.payment', [sale])
|
|
>>> pay_sale.execute('pay_')
|
|
>>> payment_statement.reload()
|
|
>>> sale.reload()
|
|
>>> len(sale.shipments), len(sale.invoices), len(sale.payments)
|
|
(0, 1, 1)
|
|
|
|
Stock moves should be created for the sale::
|
|
|
|
>>> move, = sale.moves
|
|
>>> config.user = stock_user.id
|
|
>>> move.quantity
|
|
2.0
|
|
>>> move.product == product
|
|
True
|
|
>>> move.state
|
|
u'done'
|
|
|
|
An invoice should be created for the sale::
|
|
|
|
>>> invoice, = sale.invoices
|
|
>>> config.user = account_user.id
|
|
>>> invoice.state
|
|
u'posted'
|
|
>>> invoice.untaxed_amount
|
|
Decimal('20.00')
|
|
>>> invoice.tax_amount
|
|
Decimal('2.00')
|
|
>>> invoice.total_amount
|
|
Decimal('22.00')
|
|
|
|
When the statement is closed the invoices are paid and sale is done::
|
|
|
|
>>> close_statment = Wizard('close.statement')
|
|
>>> close_statment.execute('validate')
|
|
>>> close_statment.form.result
|
|
u'Statement Default - Default closed. \n'
|
|
>>> payment_statement.reload()
|
|
>>> payment_statement.state
|
|
u'validated'
|
|
>>> all(l.invoice == invoice for l in payment_statement.lines)
|
|
True
|
|
>>> payment_statement.balance
|
|
Decimal('22.00')
|
|
>>> invoice.reload()
|
|
>>> invoice.state
|
|
u'paid'
|
|
>>> config.user = sale_user.id
|
|
>>> sale.reload()
|
|
>>> sale.state
|
|
u'done'
|
|
|
|
Execute Reports::
|
|
|
|
>>> summary = Report('sale_pos.sales_summary')
|
|
>>> report = summary.execute([sale], {})
|
|
>>> party_summary = Report('sale_pos.sales_summary_by_party')
|
|
>>> party_report = party_summary.execute([sale], {})
|