first commit
This commit is contained in:
2
modules/document_incoming_ocr_typless/tests/__init__.py
Normal file
2
modules/document_incoming_ocr_typless/tests/__init__.py
Normal 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.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,130 @@
|
||||
======================================
|
||||
Document Incoming OCR Typless Scenario
|
||||
======================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import os
|
||||
>>> 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
|
||||
>>> from trytond.tools import file_open
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules([
|
||||
... 'document_incoming_ocr_typless',
|
||||
... 'document_incoming_invoice'],
|
||||
... create_company, create_chart)
|
||||
|
||||
>>> Document = Model.get('document.incoming')
|
||||
>>> OCRService = Model.get('document.incoming.ocr.service')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> UoM = Model.get('product.uom')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create taxes::
|
||||
|
||||
>>> tax_10 = create_tax(Decimal('0.1'))
|
||||
>>> tax_10.save()
|
||||
>>> tax_20 = create_tax(Decimal('0.2'))
|
||||
>>> tax_20.save()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Set default supplier::
|
||||
|
||||
>>> suppplier = Party(name="Saber")
|
||||
>>> suppplier.save()
|
||||
|
||||
Create account category::
|
||||
|
||||
>>> account_category = ProductCategory(name="Accounting")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = accounts['expense']
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> hour, = UoM.find([('name', '=', "Hour")])
|
||||
>>> template = ProductTemplate(name="Service")
|
||||
>>> template.default_uom = hour
|
||||
>>> template.type = 'service'
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> service, = template.products
|
||||
|
||||
Setup Typless service::
|
||||
|
||||
>>> ocr_service = OCRService(type='typless')
|
||||
>>> ocr_service.typless_api_key = os.getenv('TYPLESS_API_KEY')
|
||||
>>> ocr_service.typless_document_type = os.getenv('TYPLESS_DOCUMENT_TYPE')
|
||||
>>> ocr_service.save()
|
||||
|
||||
Create incoming document::
|
||||
|
||||
>>> document = Document()
|
||||
>>> document.name = 'invoice.pdf'
|
||||
>>> with file_open(
|
||||
... 'document_incoming_ocr_typless/tests/'
|
||||
... 'supplier-invoice-sample.pdf',
|
||||
... mode='rb') as fp:
|
||||
... document.data = fp.read()
|
||||
>>> document.type = 'supplier_invoice'
|
||||
>>> document.save()
|
||||
|
||||
Process document::
|
||||
|
||||
>>> document.click('process')
|
||||
>>> invoice = document.result
|
||||
>>> assertEqual(invoice.party, suppplier)
|
||||
>>> invoice.reference
|
||||
'INV-0007'
|
||||
>>> invoice.invoice_date
|
||||
datetime.date(2023, 6, 28)
|
||||
>>> invoice.payment_term_date
|
||||
datetime.date(2023, 7, 28)
|
||||
>>> len(invoice.lines)
|
||||
2
|
||||
>>> line_service, = [l for l in invoice.lines if l.product]
|
||||
>>> assertEqual(line_service.product, service)
|
||||
>>> line_service.quantity
|
||||
23.0
|
||||
>>> line_service.unit_price
|
||||
Decimal('2.5000')
|
||||
>>> line_goods, = [l for l in invoice.lines if not l.product]
|
||||
>>> line_goods.quantity
|
||||
40.0
|
||||
>>> line_goods.unit_price
|
||||
Decimal('5.0000')
|
||||
>>> len(invoice.taxes)
|
||||
2
|
||||
>>> sorted([t.amount for t in invoice.taxes])
|
||||
[Decimal('5.75'), Decimal('40.00')]
|
||||
>>> sorted([t.base for t in invoice.taxes])
|
||||
[Decimal('57.50'), Decimal('200.00')]
|
||||
>>> assertEqual({t.tax for t in invoice.taxes}, {tax_10, tax_20})
|
||||
>>> invoice.untaxed_amount
|
||||
Decimal('257.50')
|
||||
>>> invoice.tax_amount
|
||||
Decimal('45.75')
|
||||
>>> invoice.total_amount
|
||||
Decimal('303.25')
|
||||
|
||||
Send feedback::
|
||||
|
||||
>>> document.click('ocr_send_feedback')
|
||||
Binary file not shown.
29
modules/document_incoming_ocr_typless/tests/test_module.py
Normal file
29
modules/document_incoming_ocr_typless/tests/test_module.py
Normal file
@@ -0,0 +1,29 @@
|
||||
# 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.pool import Pool
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
|
||||
|
||||
class DocumentIncomingOcrTyplessTestCase(ModuleTestCase):
|
||||
"Test Document Incoming Ocr Typless module"
|
||||
module = 'document_incoming_ocr_typless'
|
||||
|
||||
@with_transaction()
|
||||
def test_service_match(self):
|
||||
"Test Service match"
|
||||
pool = Pool()
|
||||
Service = pool.get('document.incoming.ocr.service')
|
||||
|
||||
for service, pattern, result in [
|
||||
(Service(type='typless', source=None), {}, False),
|
||||
(Service(type='typless', source=None),
|
||||
{'mime_type': 'application/pdf'}, True),
|
||||
(Service(type='typless', source=None),
|
||||
{'mime_type': 'application/octet-stream'}, False),
|
||||
]:
|
||||
with self.subTest(service=service, pattern=pattern):
|
||||
self.assertEqual(service.match(pattern), result)
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
15
modules/document_incoming_ocr_typless/tests/test_scenario.py
Normal file
15
modules/document_incoming_ocr_typless/tests/test_scenario.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
import os
|
||||
|
||||
from trytond.tests.test_tryton import TEST_NETWORK, load_doc_tests
|
||||
|
||||
|
||||
def load_tests(*args, **kwargs):
|
||||
if (not TEST_NETWORK
|
||||
or not (os.getenv('TYPLESS_API_KEY')
|
||||
and os.getenv('TYPLESS_DOCUMENT_TYPE'))):
|
||||
kwargs.setdefault('skips', set()).add(
|
||||
'scenario_document_incoming_ocr_typless.rst')
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
Reference in New Issue
Block a user