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,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

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 AccountInvoiceWatermarkTestCase(ModuleTestCase):
'Test Account Invoice Watermark module'
module = 'account_invoice_watermark'
del ModuleTestCase

View 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)

View 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()