Files
tradon/modules/sale_point/tests/scenario_sale_point_tax_excluded.rst
2026-03-14 09:42:12 +00:00

145 lines
3.7 KiB
ReStructuredText

============
POS Scenario
============
Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, create_tax, 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)
Get models::
>>> 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')
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
>>> fiscalyear.click('create_period')
Get accounts::
>>> accounts = get_accounts()
Create tax::
>>> tax = create_tax(Decimal('.21'))
>>> tax.save()
Create account categories::
>>> account_category = ProductCategory(name="Account Category")
>>> account_category.accounting = True
>>> account_category.account_revenue = accounts['revenue']
>>> account_category.customer_taxes.append(tax)
>>> 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.list_price = Decimal('10.0000')
>>> template.account_category = account_category
>>> 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.tax_included = False
>>> 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 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.unit_price
Decimal('10.0000')
>>> line.unit_list_price
Decimal('10.0000')
>>> line.unit_gross_price
Decimal('12.1000')
>>> line.quantity = 5
>>> line.amount
Decimal('50.00')
>>> sale.total
Decimal('60.50')
>>> sale.total_tax
Decimal('10.50')
>>> sale.save()
>>> sale.state
'open'
>>> sale.total
Decimal('60.50')
>>> sale.total_tax
Decimal('10.50')
Add payment::
>>> payment = sale.payments.new()
>>> payment.method = cash_method
>>> sale.save()
>>> sale.amount_to_pay
Decimal('0.00')
>>> sale.click('process')
>>> sale.state
'done'
Post the sale::
>>> sale.click('post')
>>> sale.state
'posted'