96 lines
2.9 KiB
Python
96 lines
2.9 KiB
Python
# -*- 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.model import ModelView, fields
|
|
from trytond.wizard import Wizard, StateView, StateReport, Button
|
|
from trytond.pool import Pool
|
|
from trytond.exceptions import UserError
|
|
from trytond.i18n import gettext
|
|
from trytond.transaction import Transaction
|
|
|
|
|
|
sel_edocument = [
|
|
('edocument.xrechnung.invoice', 'XRechnung UBL Invoice 2.1.1'),
|
|
('edocument.uncefact.invoice', 'CII CrossIndustryInvoice D16B'),
|
|
]
|
|
|
|
edoc_versions = {
|
|
'edocument.xrechnung.invoice': 'XRechnung-2.2',
|
|
'edocument.uncefact.invoice': '16B-CII',
|
|
}
|
|
|
|
|
|
class RunXRechnungReportStart(ModelView):
|
|
'eDocument Export'
|
|
__name__ = 'account_invoice_xrechnung.runrep.start'
|
|
|
|
invoice = fields.Many2One(
|
|
string='Invoice', readonly=True,
|
|
model_name='account.invoice', required=True)
|
|
state = fields.Char(
|
|
string='State', readonly=True, states={'invisible': True})
|
|
edocument = fields.Selection(
|
|
string='Type', required=True, selection=sel_edocument)
|
|
as_zip = fields.Boolean(string='ZIP-File')
|
|
|
|
@classmethod
|
|
def default_as_zip(cls):
|
|
""" default: True
|
|
"""
|
|
return True
|
|
|
|
@classmethod
|
|
def default_edocument(cls):
|
|
""" default xrechnung
|
|
"""
|
|
return 'edocument.xrechnung.invoice'
|
|
|
|
# end RunXRechnungReportStart
|
|
|
|
|
|
class RunXRechnungReport(Wizard):
|
|
'eDocument Export'
|
|
__name__ = 'account_invoice_xrechnung.runrep'
|
|
|
|
start_state = 'start'
|
|
export = StateReport('account_invoice_xrechnung.export')
|
|
start = StateView(
|
|
model_name='account_invoice_xrechnung.runrep.start',
|
|
view='account_invoice_xrechnung.wiz_start_form',
|
|
buttons=[
|
|
Button(string='Cancel', state='end', icon='tryton-cancel'),
|
|
Button(string='Export', state='export', icon='tryton-export'),
|
|
],
|
|
)
|
|
|
|
def default_start(self, fields):
|
|
""" set defaults
|
|
"""
|
|
context = Transaction().context
|
|
Invoice = Pool().get('account.invoice')
|
|
|
|
invoice = Invoice.browse([context.get('active_id', -1)])
|
|
result = {
|
|
'edocument': 'edocument.xrechnung.invoice',
|
|
'invoice': context.get('active_id', -1),
|
|
'state': invoice[0].state if len(invoice) > 0 else '',
|
|
}
|
|
return result
|
|
|
|
def do_export(self, action):
|
|
""" run export
|
|
"""
|
|
if self.start.state != 'posted':
|
|
raise UserError(gettext(
|
|
'account_invoice_xrechnung.msg_invoice_must_posted',
|
|
invname=self.start.invoice.rec_name,
|
|
))
|
|
return action, {
|
|
'invoice': self.start.invoice.id,
|
|
'edocument': self.start.edocument,
|
|
'as_zip': self.start.as_zip,
|
|
}
|
|
|
|
# end RunXRechnungReport
|