exprt wizard begonnen

This commit is contained in:
Frederik Jaeckel 2022-10-19 17:47:47 +02:00
parent 7b160d84af
commit 00dd70e877
7 changed files with 142 additions and 8 deletions

View file

@ -4,9 +4,14 @@
# full copyright notices and license terms. # full copyright notices and license terms.
from trytond.pool import Pool from trytond.pool import Pool
from .wizard_runreport import RunXRechnungReport from .wizard_runreport import RunXRechnungReport, RunXRechnungReportStart
from .invoice import InvoiceLine
def register(): def register():
Pool.register(
InvoiceLine,
RunXRechnungReportStart,
module='account_invoice_xrechnung', type_='model')
Pool.register( Pool.register(
RunXRechnungReport, RunXRechnungReport,
module='account_invoice_xrechnung', type_='wizard') module='account_invoice_xrechnung', type_='wizard')

25
invoice.py Normal file
View file

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

24
tests/__init__.py Normal file
View file

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

19
tests/test_invoice.py Normal file
View file

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

11
view/wizard_form.xml Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!-- 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. -->
<form col="4">
<label name="invoice"/>
<field name="invoice"/>
<label name="edocument"/>
<field name="edocument"/>
</form>

View file

@ -4,20 +4,62 @@
# full copyright notices and license terms. # full copyright notices and license terms.
from trytond.model import ModelView, fields 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.pool import Pool
from trytond.transaction import Transaction 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): class RunXRechnungReport(Wizard):
'XRechnung Report' 'eDocument Report'
__name__ = 'account_invoice_xrechnung.runrep' __name__ = 'account_invoice_xrechnung.runrep'
start_state = 'open_' start_state = 'open_'
#report_ = StateReport('cashbook.reprecon') export = StateReport('account_invoice_xrechnung.export')
open_ = StateAction('account_invoice.act_invoice_form') 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 """ run form
""" """
pool = Pool() pool = Pool()
@ -29,7 +71,8 @@ class RunXRechnungReport(Wizard):
template = EDocument(invoice) template = EDocument(invoice)
invoice_string = template.render('XRechnung-2.2') invoice_string = template.render('XRechnung-2.2')
print('\n## invoice_string:', invoice_string.decode('utf8')) print('\n## invoice_string:', invoice_string.decode('utf8'))
with open('x-rechnung.xml', 'wt') as fhdl:
fhdl.write(invoice_string.decode('utf8'))
return action, {} return action, {}

View file

@ -5,12 +5,19 @@ full copyright notices and license terms. -->
<tryton> <tryton>
<data> <data>
<record model="ir.ui.view" id="wiz_start_form">
<field name="model">account_invoice_xrechnung.runrep.start</field>
<field name="type">form</field>
<field name="priority" eval="10"/>
<field name="name">wizard_form</field>
</record>
<record model="ir.action.wizard" id="act_wizard_report"> <record model="ir.action.wizard" id="act_wizard_report">
<field name="name">XRechnung Report</field> <field name="name">XRechnung Report</field>
<field name="wiz_name">account_invoice_xrechnung.runrep</field> <field name="wiz_name">account_invoice_xrechnung.runrep</field>
</record> </record>
<record model="ir.action.keyword" id="wizrecon_line-keyword"> <record model="ir.action.keyword" id="wizrecon_line-keyword">
<field name="keyword">form_action</field> <field name="keyword">form_print</field>
<field name="model">account.invoice,-1</field> <field name="model">account.invoice,-1</field>
<field name="action" ref="act_wizard_report"/> <field name="action" ref="act_wizard_report"/>
</record> </record>