119 lines
3.4 KiB
ReStructuredText
119 lines
3.4 KiB
ReStructuredText
======================
|
|
POS Reporting Scenario
|
|
======================
|
|
|
|
Imports::
|
|
|
|
>>> from decimal import Decimal
|
|
|
|
>>> from proteus import Model
|
|
>>> from trytond.modules.account.tests.tools import (
|
|
... create_chart, create_fiscalyear, get_accounts)
|
|
>>> from trytond.modules.account_invoice.tests.tools import (
|
|
... set_fiscalyear_invoice_sequences)
|
|
>>> from trytond.modules.company.tests.tools import create_company
|
|
>>> from trytond.tests.tools import activate_modules
|
|
|
|
Activate modules::
|
|
|
|
>>> config = activate_modules('sale_point', create_company, create_chart)
|
|
|
|
>>> Journal = Model.get('account.journal')
|
|
>>> Location = Model.get('stock.location')
|
|
>>> POS = Model.get('sale.point')
|
|
>>> PaymentMethod = Model.get('sale.point.payment.method')
|
|
>>> ProductCategory = Model.get('product.category')
|
|
>>> ProductTemplate = Model.get('product.template')
|
|
>>> ProductUom = Model.get('product.uom')
|
|
>>> Sale = Model.get('sale.point.sale')
|
|
>>> SequenceStrict = Model.get('ir.sequence.strict')
|
|
>>> SequenceType = Model.get('ir.sequence.type')
|
|
>>> StockMove = Model.get('stock.move')
|
|
|
|
Create fiscal year::
|
|
|
|
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
|
|
>>> fiscalyear.click('create_period')
|
|
|
|
Get accounts::
|
|
|
|
>>> accounts = get_accounts()
|
|
|
|
Create account categories::
|
|
|
|
>>> account_category = ProductCategory(name="Account Category")
|
|
>>> account_category.accounting = True
|
|
>>> account_category.account_revenue = accounts['revenue']
|
|
>>> account_category.save()
|
|
|
|
Create product::
|
|
|
|
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
|
|
|
>>> template = ProductTemplate()
|
|
>>> template.name = 'product'
|
|
>>> template.default_uom = unit
|
|
>>> template.type = 'goods'
|
|
>>> template.salable = True
|
|
>>> template.account_category = account_category
|
|
>>> template.gross_price = Decimal('12.0000')
|
|
>>> template.save()
|
|
>>> goods, = template.products
|
|
|
|
Get journal::
|
|
|
|
>>> journal_revenue, = Journal.find([('type', '=', 'revenue')], limit=1)
|
|
|
|
Get stock locations::
|
|
|
|
>>> storage_loc, = Location.find([('code', '=', 'STO')])
|
|
>>> customer_loc, = Location.find([('code', '=', 'CUS')])
|
|
|
|
Create POS::
|
|
|
|
>>> pos = POS(name="POS")
|
|
>>> pos.journal = journal_revenue
|
|
>>> pos.sequence = SequenceStrict(name="POS", company=pos.company)
|
|
>>> pos.sequence.sequence_type, = SequenceType.find(
|
|
... [('name', '=', "POS")], limit=1)
|
|
>>> pos.sequence.save()
|
|
>>> pos.storage_location = storage_loc
|
|
>>> pos.customer_location = customer_loc
|
|
>>> pos.save()
|
|
|
|
Create a payment method::
|
|
|
|
>>> cash_method = PaymentMethod(name="Cash")
|
|
>>> cash_method.account = accounts['cash']
|
|
>>> cash_method.cash = True
|
|
>>> cash_method.save()
|
|
|
|
Make a sale::
|
|
|
|
>>> sale = Sale(point=pos)
|
|
>>> line = sale.lines.new()
|
|
>>> line.product = goods
|
|
>>> line.quantity = 1
|
|
>>> sale.save()
|
|
|
|
>>> payment = sale.click('pay')
|
|
>>> payment.form.method = cash_method
|
|
>>> payment.execute('pay')
|
|
|
|
Check sale reporting::
|
|
|
|
>>> Reporting = Model.get('sale.reporting.main')
|
|
>>> context = dict(
|
|
... from_date=fiscalyear.start_date,
|
|
... to_date=fiscalyear.end_date,
|
|
... period='month')
|
|
>>> with config.set_context(context=context):
|
|
... reports = Reporting.find([])
|
|
>>> len(reports)
|
|
1
|
|
>>> report, = reports
|
|
>>> report.number
|
|
1
|
|
>>> report.revenue
|
|
Decimal('12.00')
|