# -*- coding: utf-8 -*- # This file is part of the account-invoice-xrechnung-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, StateTransition, StateAction, Button) from trytond.transaction import Transaction from trytond.pyson import Bool, Eval sel_invoice_type = [ ('out', 'Customer Invoice'), ('in', 'Supplier Invoice')] class ImportXmlStart(ModelView): 'eDocument Import' __name__ = 'account_invoice_xrechnung.import.start' company = fields.Many2One( string='Company', model_name='company.company', required=True, readonly=True) invoice_type = fields.Selection( string='Invoice Type', required=True, selection=sel_invoice_type) file_ = fields.Binary( string="ZIP or XML-File", required=True) # end ImportStart class ImportXmlShowcontent(ModelView): 'eDocument Import' __name__ = 'account_invoice_xrechnung.import.showcontent' company = fields.Many2One( string='Company', model_name='company.company', required=True, readonly=True) invoice_type = fields.Selection( string='Invoice Type', required=True, readonly=True, selection=sel_invoice_type) # end ImportXmlShowcontent class ImportXml(Wizard): 'eDocument Import' __name__ = 'account_invoice_xrechnung.import' start_state = 'start' start = StateView( model_name='account_invoice_xrechnung.import.start', view='account_invoice_xrechnung.import_start_form', buttons=[ Button(string='Cancel', state='end', icon='tryton-cancel'), Button( string='Upload', state='doupload', icon='tryton-open', states={'readonly': ~Bool(Eval('file_'))}), ]) doupload = StateTransition() showcontent = StateView( model_name='account_invoice_xrechnung.import.showcontent', view='account_invoice_xrechnung.import_content_form', buttons=[ Button(string='Cancel', state='end', icon='tryton-cancel'), Button(string='Back', state='start', icon='tryton-back'), Button(string='Import', state='doimport', icon='tryton-open'), ]) doimport = StateTransition() invoices_out = StateAction('account_invoice.act_invoice_out_form') invoices_in = StateAction('account_invoice.act_invoice_in_form') def default_start(self, fields): """ fill fields of start-form """ context = Transaction().context inv_type = getattr(getattr( self, 'showcontent', {}), 'invoice_type', None) result = { 'company': context.get('company', None), 'invoice_type': inv_type if inv_type else 'in', 'file_': getattr(self.start, 'file_', None)} return result def default_showcontent(self, fields): """ fill fields of start-form """ context = Transaction().context inv_type = getattr(self.start, 'invoice_type') result = { 'company': context.get('company', None), 'invoice_type': inv_type if inv_type else 'in'} return result def transition_doupload(self): """ load file, detect content """ self.showcontent.company = self.start.company self.showcontent.invoice_type = self.start.invoice_type return 'showcontent' def transition_doimport(self): """ create invoices """ return 'end' def do_invoices_out(self, action): """ show created customer invoices """ data = {} data['res_id'] = [] action['views'].reverse() return action, data def do_invoices_in(self, action): """ show created supplier invoices """ data = {} data['res_id'] = [] action['views'].reverse() return action, data # end ImportXml