first commit
This commit is contained in:
2
modules/account_invoice_watermark/tests/__init__.py
Normal file
2
modules/account_invoice_watermark/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.
Binary file not shown.
@@ -0,0 +1,97 @@
|
||||
==================================
|
||||
Account Invoice Watermark Scenario
|
||||
==================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Report
|
||||
>>> 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.account_invoice_watermark.tests.tools import pdf_contains
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... 'account_invoice_watermark', create_company, create_chart)
|
||||
|
||||
>>> ActionReport = Model.get('ir.action.report')
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> Journal = Model.get('account.journal')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> PaymentMethod = Model.get('account.invoice.payment.method')
|
||||
|
||||
Convert invoice report to PDF::
|
||||
|
||||
>>> invoice_report, = ActionReport.find([
|
||||
... ('report_name', '=', 'account.invoice'),
|
||||
... ])
|
||||
>>> invoice_report.extension = 'pdf'
|
||||
>>> invoice_report.save()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear())
|
||||
>>> fiscalyear.click('create_period')
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
|
||||
Create payment method::
|
||||
|
||||
>>> journal_cash, = Journal.find([('type', '=', 'cash')])
|
||||
>>> payment_method = PaymentMethod()
|
||||
>>> payment_method.name = 'Cash'
|
||||
>>> payment_method.journal = journal_cash
|
||||
>>> payment_method.credit_account = accounts['cash']
|
||||
>>> payment_method.debit_account = accounts['cash']
|
||||
>>> payment_method.save()
|
||||
|
||||
Create party::
|
||||
|
||||
>>> party = Party(name='Party')
|
||||
>>> party.save()
|
||||
|
||||
Create invoice::
|
||||
|
||||
>>> invoice = Invoice()
|
||||
>>> invoice.party = party
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.account = accounts['revenue']
|
||||
>>> line.quantity = 10
|
||||
>>> line.unit_price = Decimal('4.2000')
|
||||
>>> invoice.save()
|
||||
|
||||
Print draft invoice::
|
||||
|
||||
>>> invoice_report = Report('account.invoice')
|
||||
>>> content = invoice_report.execute([invoice])[1]
|
||||
>>> pdf_contains(content, "DRAFT")
|
||||
True
|
||||
|
||||
Print posted invoice::
|
||||
|
||||
>>> invoice.click('post')
|
||||
>>> content = invoice_report.execute([invoice])[1]
|
||||
>>> pdf_contains(content, "DRAFT")
|
||||
False
|
||||
>>> pdf_contains(content, "PAID")
|
||||
False
|
||||
|
||||
Print paid invoice::
|
||||
|
||||
>>> pay = invoice.click('pay')
|
||||
>>> pay.form.payment_method = payment_method
|
||||
>>> pay.execute('choice')
|
||||
>>> invoice.state
|
||||
'paid'
|
||||
>>> content = invoice_report.execute([invoice])[1]
|
||||
>>> pdf_contains(content, "PAID")
|
||||
True
|
||||
12
modules/account_invoice_watermark/tests/test_module.py
Normal file
12
modules/account_invoice_watermark/tests/test_module.py
Normal 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 AccountInvoiceWatermarkTestCase(ModuleTestCase):
|
||||
'Test Account Invoice Watermark module'
|
||||
module = 'account_invoice_watermark'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
10
modules/account_invoice_watermark/tests/test_scenario.py
Normal file
10
modules/account_invoice_watermark/tests/test_scenario.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# 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 shutil
|
||||
|
||||
from trytond.tests.test_tryton import load_doc_tests
|
||||
|
||||
if shutil.which('soffice') and shutil.which('mutool'):
|
||||
def load_tests(*args, **kwargs):
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
20
modules/account_invoice_watermark/tests/tools.py
Normal file
20
modules/account_invoice_watermark/tests/tools.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# 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
|
||||
import subprocess
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
__all__ = ['pdf_contains']
|
||||
|
||||
|
||||
def pdf_contains(pdf, text):
|
||||
with TemporaryDirectory() as dirname:
|
||||
input_file = os.path.join(dirname, 'input.pdf')
|
||||
output_file = os.path.join(dirname, 'output.text')
|
||||
with open(input_file, 'wb') as fp:
|
||||
fp.write(pdf)
|
||||
subprocess.check_call([
|
||||
'mutool', 'convert', '-F', 'text',
|
||||
'-o', output_file, input_file])
|
||||
with open(output_file, 'r') as fp:
|
||||
return text in fp.read()
|
||||
Reference in New Issue
Block a user