2022-10-17 15:20:25 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# This file is part of the edcoment-module for Tryton.
|
|
|
|
# The COPYRIGHT file at the top level of this repository contains the
|
|
|
|
# full copyright notices and license terms.
|
|
|
|
|
|
|
|
import genshi.template
|
2022-10-18 15:33:17 +00:00
|
|
|
import os, html
|
|
|
|
from trytond.exceptions import UserError
|
|
|
|
from trytond.i18n import gettext
|
2022-10-17 15:20:25 +00:00
|
|
|
from trytond.modules.edocument_uncefact.edocument import Invoice
|
2022-10-18 15:33:17 +00:00
|
|
|
from decimal import Decimal
|
2022-10-17 15:20:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Invoice(Invoice):
|
|
|
|
'EDocument XRechnung'
|
|
|
|
__name__ = 'edocument.xrechnung.invoice'
|
|
|
|
|
2022-10-19 15:15:56 +00:00
|
|
|
def sales_order_nums(self):
|
|
|
|
""" get string of sale-numbers
|
|
|
|
"""
|
|
|
|
if getattr(self.invoice, 'sales', None) is not None:
|
|
|
|
return ', '.join([x.number for x in self.invoice.sales])
|
|
|
|
|
2022-10-18 15:33:17 +00:00
|
|
|
def prepaid_amount(self, invoice):
|
|
|
|
""" compute already paid amount
|
|
|
|
"""
|
|
|
|
return invoice.total_amount - invoice.amount_to_pay
|
|
|
|
|
2022-10-19 15:15:56 +00:00
|
|
|
def invoice_note(self):
|
|
|
|
""" get 'description' + 'comment'
|
|
|
|
"""
|
|
|
|
notes = []
|
|
|
|
if self.invoice.description:
|
|
|
|
notes.append(self.invoice.description)
|
|
|
|
|
|
|
|
if self.invoice.comment:
|
|
|
|
notes.extend(self.invoice.comment.split('\n'))
|
|
|
|
if len(notes) > 0:
|
|
|
|
return '; '.join(notes)
|
|
|
|
|
|
|
|
def invoice_line_tax(self, line):
|
|
|
|
""" get tax of invoice-line,
|
|
|
|
fire exception if no/multiple taxes exists
|
|
|
|
"""
|
|
|
|
if len(line.invoice_taxes) != 1:
|
|
|
|
raise UserError(gettext(
|
|
|
|
'edocument_xrechnung.msg_linetax_invalid_number',
|
|
|
|
linename = line.rec_name,
|
|
|
|
numtax = len(line.invoice_taxes),
|
|
|
|
))
|
|
|
|
|
|
|
|
allowed_cat = ['AE', 'L', 'M', 'E', 'S', 'Z', 'G', 'O', 'K', 'B']
|
|
|
|
if not line.invoice_taxes[0].tax.unece_category_code in allowed_cat:
|
|
|
|
raise UserError(gettext(
|
|
|
|
'edocument_xrechnung.msg_linetax_invalid_catcode',
|
|
|
|
taxname = line.invoice_taxes[0].tax.rec_name,
|
|
|
|
allowed = ', '.join(allowed_cat),
|
|
|
|
))
|
|
|
|
|
|
|
|
return line.invoice_taxes[0].tax
|
|
|
|
|
|
|
|
def taxident_data(self, tax_identifier):
|
|
|
|
""" get tax-scheme-id and codes
|
|
|
|
"""
|
|
|
|
result = {
|
|
|
|
'code': None,
|
|
|
|
'id': None,
|
|
|
|
}
|
|
|
|
|
|
|
|
if tax_identifier:
|
|
|
|
if tax_identifier.type == 'de_vat':
|
|
|
|
result['code'] = 'DE%s' % tax_identifier.code
|
|
|
|
result['id'] = 'VAT'
|
|
|
|
return result
|
|
|
|
|
2022-10-18 15:33:17 +00:00
|
|
|
def tax_rate(self, tax):
|
|
|
|
""" get tax-rate in procent
|
|
|
|
"""
|
2022-10-19 15:15:56 +00:00
|
|
|
return (tax.rate * Decimal('100.0')).quantize(Decimal('0.01'))
|
|
|
|
|
|
|
|
def uom_unece_code(self, line):
|
|
|
|
""" 'line': invoice.line
|
|
|
|
"""
|
|
|
|
if len(line.unit.unece_code or '') == 0:
|
|
|
|
raise UserError(gettext(
|
|
|
|
'edocument_xrechnung.msg_uom_code_missing',
|
|
|
|
uomname = line.unit.rec_name,
|
|
|
|
))
|
|
|
|
return line.unit.unece_code
|
2022-10-18 15:33:17 +00:00
|
|
|
|
|
|
|
def tax_category_code(self, tax):
|
|
|
|
""" read tax-category, fire exception if missing
|
|
|
|
"""
|
2022-10-19 15:15:56 +00:00
|
|
|
if len(tax.unece_category_code or '') == 0:
|
2022-10-18 15:33:17 +00:00
|
|
|
raise UserError(gettext(
|
|
|
|
'edocument_xrechnung.mds_tax_category_missing',
|
|
|
|
taxname = tax.rec_name,
|
|
|
|
))
|
2022-10-19 15:15:56 +00:00
|
|
|
return tax.unece_category_code
|
2022-10-18 15:33:17 +00:00
|
|
|
|
|
|
|
def quote_text(self, text):
|
|
|
|
""" replace critical chars
|
|
|
|
"""
|
|
|
|
if text is not None:
|
|
|
|
return html.quote(text)
|
|
|
|
|
2022-10-17 15:20:25 +00:00
|
|
|
def _get_template(self, version):
|
|
|
|
""" load our own template if 'version' is ours
|
|
|
|
"""
|
|
|
|
if version == 'XRechnung-2.2':
|
|
|
|
loader = genshi.template.TemplateLoader(
|
|
|
|
os.path.join(os.path.dirname(__file__), 'template'),
|
|
|
|
auto_reload=True)
|
|
|
|
return loader.load(os.path.join(version, 'XRechnung.xml'))
|
|
|
|
else :
|
|
|
|
return super(Invoice, self)._get_template(version)
|
|
|
|
|
|
|
|
# end Invoice
|