diff --git a/__init__.py b/__init__.py index 56db290..0c9d2d3 100644 --- a/__init__.py +++ b/__init__.py @@ -4,9 +4,14 @@ # full copyright notices and license terms. from trytond.pool import Pool -from .wizard_runreport import RunXRechnungReport +from .wizard_runreport import RunXRechnungReport, RunXRechnungReportStart +from .invoice import InvoiceLine def register(): + Pool.register( + InvoiceLine, + RunXRechnungReportStart, + module='account_invoice_xrechnung', type_='model') Pool.register( RunXRechnungReport, module='account_invoice_xrechnung', type_='wizard') diff --git a/invoice.py b/invoice.py new file mode 100644 index 0000000..05b5e6c --- /dev/null +++ b/invoice.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# This file is part of the cashbook-module from m-ds for Tryton. +# The COPYRIGHT file at the top level of this repository contains the +# full copyright notices and license terms. + +from trytond.pool import PoolMeta +from trytond.pyson import Eval, And, Or + + +class InvoiceLine(metaclass=PoolMeta): + __name__ = 'account.invoice.line' + + @classmethod + def __setup__(cls): + super(InvoiceLine, cls).__setup__() + cls.unit.states['required'] = Or( + cls.unit.states['required'], + And( + Eval('type') == 'line', + Eval('quantity', None) != None, + ), + ) + cls.unit.depends.extend(['type', 'quantity']) + +# end Invoice diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..b936445 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,24 @@ +# 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 trytond.tests.test_tryton +import unittest + +from trytond.modules.account_invoice_xrechnung.tests.test_invoice import InvoiceTestCase + + +__all__ = ['suite'] + + +class XRechnungTestCase(\ + InvoiceTestCase,\ + ): + 'Test xrechnung module' + module = 'account_invoice_xrechnung' + +# end XRechnungTestCase + +def suite(): + suite = trytond.tests.test_tryton.suite() + suite.addTests(unittest.TestLoader().loadTestsFromTestCase(XRechnungTestCase)) + return suite diff --git a/tests/test_invoice.py b/tests/test_invoice.py new file mode 100644 index 0000000..811b717 --- /dev/null +++ b/tests/test_invoice.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# This file is part of the cashbook-module from m-ds for 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, with_transaction + + +class InvoiceTestCase(ModuleTestCase): + 'Test invoice module' + module = 'account_invoice_xrechnung' + + @with_transaction() + def test_xrechnung(self): + """ run default tests + """ + pass + +# end InvoiceTestCase diff --git a/view/wizard_form.xml b/view/wizard_form.xml new file mode 100644 index 0000000..d301445 --- /dev/null +++ b/view/wizard_form.xml @@ -0,0 +1,11 @@ + + +
diff --git a/wizard_runreport.py b/wizard_runreport.py index 378c0f1..2e58629 100644 --- a/wizard_runreport.py +++ b/wizard_runreport.py @@ -4,20 +4,62 @@ # full copyright notices and license terms. from trytond.model import ModelView, fields -from trytond.wizard import Wizard, StateAction +from trytond.wizard import Wizard, StateView, StateReport from trytond.pool import Pool from trytond.transaction import Transaction +sel_edocument = [ + ('edocument.xrechnung.invoice', 'XRechnung UBL Invoice 2.1.1'), + ('edocument.uncefact.invoice', 'CII CrossIndustryInvoice D16B'), + ] + + +class RunXRechnungReportStart(ModelView): + 'eDocument Report' + __name__ = 'account_invoice_xrechnung.runrep.start' + + invoice = fields.Many2One(string='Invoice', readonly=True, + model_name='account.invoice', required=True) + edocument = fields.Selection(string='eDocument', required=True, + selection=sel_edocument) + + @classmethod + def default_edocument(cls): + """ default xrechnung + """ + return 'edocument.xrechnung.invoice' + +# end RunXRechnungReportStart + + class RunXRechnungReport(Wizard): - 'XRechnung Report' + 'eDocument Report' __name__ = 'account_invoice_xrechnung.runrep' start_state = 'open_' - #report_ = StateReport('cashbook.reprecon') - open_ = StateAction('account_invoice.act_invoice_form') + export = StateReport('account_invoice_xrechnung.export') + open_ = StateView( + model_name='account_invoice_xrechnung.runrep.start', + view='account_invoice_xrechnung.wiz_start_form', + buttons=[ + Button(string='Cancel', state='cleanup', icon='tryton-cancel'), + Button(string='Export', state='export', icon='tryton-export'), + ], + ) - def do_open_(self, action): + def default_open_(self): + """ set defaults + """ + context = Transaction().context + + result = { + 'edocument': 'edocument.xrechnung.invoice', + 'invoice': context.get('active_id', -1), + } + return result + + def do_export(self, action): """ run form """ pool = Pool() @@ -29,7 +71,8 @@ class RunXRechnungReport(Wizard): template = EDocument(invoice) invoice_string = template.render('XRechnung-2.2') print('\n## invoice_string:', invoice_string.decode('utf8')) - + with open('x-rechnung.xml', 'wt') as fhdl: + fhdl.write(invoice_string.decode('utf8')) return action, {} diff --git a/wizard_runreport.xml b/wizard_runreport.xml index 89b3371..5170e48 100644 --- a/wizard_runreport.xml +++ b/wizard_runreport.xml @@ -5,12 +5,19 @@ full copyright notices and license terms. -->