first commit

This commit is contained in:
root
2026-03-14 09:42:12 +00:00
commit 0adbd20c2c
10991 changed files with 1646955 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

View File

@@ -0,0 +1,206 @@
============
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, assertEqual
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 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.account_category = account_category
>>> template.gross_price = Decimal('12.0000')
>>> template.list_price
Decimal('9.9174')
>>> template.save()
>>> goods, = template.products
>>> goods.gross_price = Decimal('14.0000')
>>> goods.list_price
Decimal('11.5702')
>>> template = ProductTemplate()
>>> template.name = 'service'
>>> template.default_uom = unit
>>> template.type = 'service'
>>> template.salable = True
>>> template.account_category = account_category
>>> template.list_price = Decimal('29.7520')
>>> template.gross_price = Decimal('36.0000')
>>> template.save()
>>> service, = 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 2 payment methods::
>>> cash_method = PaymentMethod(name="Cash")
>>> cash_method.account = accounts['cash']
>>> cash_method.cash = True
>>> cash_method.save()
>>> terminal_method = PaymentMethod(name="Terminal")
>>> accounts['terminal'], = accounts['cash'].duplicate(
... default={'name': "Terminal"})
>>> terminal_method.account = accounts['terminal']
>>> terminal_method.save()
Make a sale::
>>> sale = Sale(point=pos)
>>> line = sale.lines.new()
>>> line.product = goods
>>> line.unit_price
Decimal('12.0000')
>>> line.unit_list_price
Decimal('9.9174')
>>> line.unit_gross_price
Decimal('12.0000')
>>> line.quantity = 500
>>> line.amount
Decimal('6000.00')
>>> line = sale.lines.new()
>>> line.product = service
>>> line.quantity = 1
>>> sale.total
Decimal('6036.00')
>>> sale.total_tax
Decimal('1047.55')
>>> sale.save()
>>> sale.state
'open'
>>> sale.total
Decimal('6036.00')
>>> sale.total_tax
Decimal('1047.55')
Overpay by terminal::
>>> payment = sale.click('pay')
>>> payment.form.method = terminal_method
>>> payment.form.amount
Decimal('6036.00')
>>> payment.form.amount = Decimal('6100.00')
>>> payment.execute('pay')
>>> assertEqual(payment.form.method, cash_method)
>>> payment.form.amount
Decimal('-64.00')
>>> payment.execute('pay')
>>> sale.state
'done'
Post the sale::
>>> sale.click('post')
>>> sale.state
'posted'
Check stock move::
>>> move, = StockMove.find([
... ('origin.sale', '=', sale.id, 'sale.point.sale.line')
... ])
>>> assertEqual(move.product, goods)
>>> move.quantity
500.0
>>> assertEqual(move.from_location, storage_loc)
>>> assertEqual(move.to_location, customer_loc)
>>> move.state
'done'
Check account move::
>>> bool(sale.move)
True
>>> accounts['revenue'].reload()
>>> accounts['revenue'].debit, accounts['revenue'].credit
(Decimal('0.00'), Decimal('4988.45'))
>>> accounts['tax'].reload()
>>> accounts['tax'].debit, accounts['tax'].credit
(Decimal('0.00'), Decimal('1047.55'))
>>> accounts['cash'].reload()
>>> accounts['cash'].debit, accounts['cash'].credit
(Decimal('-64.00'), Decimal('0.00'))
>>> accounts['terminal'].reload()
>>> accounts['terminal'].debit, accounts['terminal'].credit
(Decimal('6100.00'), Decimal('0.00'))

View File

@@ -0,0 +1,118 @@
======================
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')

View File

@@ -0,0 +1,159 @@
===================
POS Scenario Return
===================
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, assertEqual
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.account_category = account_category
>>> template.gross_price = Decimal('12.0000')
>>> template.list_price
Decimal('9.9174')
>>> template.save()
>>> goods, = template.products
Get journal::
>>> journal_revenue, = Journal.find([('type', '=', 'revenue')], limit=1)
Get stock locations::
>>> storage_loc, = Location.find([('code', '=', 'STO')])
>>> input_loc, = Location.find([('code', '=', 'IN')])
>>> 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.return_location = input_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.quantity = -1
>>> sale.save()
>>> sale.total
Decimal('-12.00')
Add payment::
>>> payment = sale.payments.new()
>>> payment.method = cash_method
>>> payment.amount
Decimal('-12.00')
>>> sale.save()
>>> sale.amount_to_pay
Decimal('0.00')
>>> sale.click('process')
>>> sale.state
'done'
Post the sale::
>>> sale.click('post')
>>> sale.state
'posted'
Check stock move::
>>> line, = sale.lines
>>> move, = line.moves
>>> assertEqual(move.product, goods)
>>> assertEqual(move.from_location, customer_loc)
>>> assertEqual(move.to_location, input_loc)
>>> move.state
'done'
Check account move::
>>> bool(sale.move)
True
>>> accounts['revenue'].reload()
>>> accounts['revenue'].debit, accounts['revenue'].credit
(Decimal('9.92'), Decimal('0.00'))
>>> accounts['tax'].reload()
>>> accounts['tax'].debit, accounts['tax'].credit
(Decimal('2.08'), Decimal('0.00'))
>>> accounts['cash'].reload()
>>> accounts['cash'].debit, accounts['cash'].credit
(Decimal('0.00'), Decimal('12.00'))

View File

@@ -0,0 +1,172 @@
====================
POS Session 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')
>>> Session = Model.get('sale.point.cash.session')
>>> TransferType = Model.get('sale.point.cash.transfer.type')
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.salable = True
>>> template.account_category = account_category
>>> template.gross_price = Decimal('20.0000')
>>> template.save()
>>> product, = 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 cash payment method::
>>> cash_method = PaymentMethod(name="Cash")
>>> cash_method.account = accounts['cash']
>>> cash_method.cash = True
>>> cash_method.save()
Create transfer type::
>>> transfer_type = TransferType(name="Bank")
>>> transfer_type.journal, = Journal.find([('type', '=', 'cash')], limit=1)
>>> accounts['bank'], = accounts['cash'].duplicate(default={'name': "Bank"})
>>> transfer_type.account = accounts['bank']
>>> transfer_type.save()
Create an initial cash session::
>>> session = Session(point=pos)
>>> transfer = session.transfers.new(point=pos)
>>> transfer.type = transfer_type
>>> transfer.amount = Decimal('100.00')
>>> session.end_amount = Decimal('100.00')
>>> session.save()
>>> session.start_amount
Decimal('0')
>>> session.balance
Decimal('100.00')
>>> session.end_amount
Decimal('100.00')
>>> session.click('close')
>>> session.state
'closed'
>>> session.click('post')
>>> session.state
'posted'
>>> transfer, = session.transfers
>>> transfer.state
'posted'
>>> transfer.move.state
'posted'
>>> accounts['bank'].reload()
>>> accounts['bank'].balance
Decimal('-100.00')
Make a sale::
>>> sale = Sale(point=pos)
>>> line = sale.lines.new()
>>> line.product = product
>>> line.quantity = 1
>>> sale.save()
>>> sale.total
Decimal('20.00')
Pay by cash::
>>> payment = sale.click('pay')
>>> payment.form.method = cash_method
>>> payment.form.amount
Decimal('20.00')
>>> payment.execute('pay')
>>> sale.state
'done'
>>> payment, = sale.payments
Check the new session::
>>> session = payment.session
>>> session.state
'open'
>>> session.start_amount
Decimal('100.00')
>>> session.balance
Decimal('20.00')
Try to close::
>>> session.click('close')
Traceback (most recent call last):
...
SessionValidationError: ...
>>> session.end_amount = Decimal('120.00')
>>> session.click('close')
>>> session.state
'closed'

View File

@@ -0,0 +1,144 @@
============
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'

View File

@@ -0,0 +1,12 @@
# 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 trytond.tests.test_tryton import ModuleTestCase
class POSTestCase(ModuleTestCase):
"Test POS module"
module = 'sale_point'
del ModuleTestCase

View File

@@ -0,0 +1,8 @@
# 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 trytond.tests.test_tryton import load_doc_tests
def load_tests(*args, **kwargs):
return load_doc_tests(__name__, __file__, *args, **kwargs)