From dafa8174337fb797258b39db4d66c0d3b1575247 Mon Sep 17 00:00:00 2001 From: Albert Cervera i Areny Date: Sat, 18 Aug 2018 23:55:49 +0200 Subject: [PATCH] Migrate to python 3. --- account.py | 6 ++---- company.py | 3 +-- invoice.py | 20 ++++++++------------ party.py | 3 +-- payment_type.py | 3 +-- setup.py | 5 +---- 6 files changed, 14 insertions(+), 26 deletions(-) diff --git a/account.py b/account.py index d85f515..cdce2cf 100644 --- a/account.py +++ b/account.py @@ -43,8 +43,7 @@ REPORT_TYPES = [ ] -class TaxTemplate: - __metaclass__ = PoolMeta +class TaxTemplate(metaclass=PoolMeta): __name__ = 'account.tax.template' report_type = fields.Selection(REPORT_TYPES, 'Report Type', sort=False) @@ -57,8 +56,7 @@ class TaxTemplate: return res -class Tax(): - __metaclass__ = PoolMeta +class Tax(metaclass=PoolMeta): __name__ = 'account.tax' report_type = fields.Selection(REPORT_TYPES, 'Report Type', sort=False) diff --git a/company.py b/company.py index 8c0b761..87ed499 100644 --- a/company.py +++ b/company.py @@ -6,9 +6,8 @@ from trytond.pool import PoolMeta __all__ = ['Company'] -class Company: +class Company(metaclass=PoolMeta): __name__ = 'company.company' - __metaclass__ = PoolMeta facturae_certificate = fields.Binary('Factura-e Certificate', help='The certificate to generate the XAdES electronic firm for ' 'invoices.') diff --git a/invoice.py b/invoice.py index e5eb493..c29d0da 100644 --- a/invoice.py +++ b/invoice.py @@ -110,10 +110,10 @@ _slugify_hyphenate_re = re.compile(r'[-\s]+') def slugify(value): - if not isinstance(value, unicode): - value = unicode(value) + if not isinstance(value, str): + value = str(value) value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore') - value = unicode(_slugify_strip_re.sub('', value).strip().lower()) + value = str(_slugify_strip_re.sub('', value).strip().lower()) return _slugify_hyphenate_re.sub('-', value) @@ -121,9 +121,8 @@ def module_path(): return os.path.dirname(os.path.abspath(__file__)) -class Invoice: +class Invoice(metaclass=PoolMeta): __name__ = 'account.invoice' - __metaclass__ = PoolMeta credited_invoices = fields.Function(fields.One2Many('account.invoice', None, 'Credited Invoices'), 'get_credited_invoices', searcher='search_credited_invoices') @@ -435,7 +434,7 @@ class Invoice: facturae_schema.assertValid(etree.fromstring(xml_string)) logger.debug("Factura-e XML of invoice %s validated", self.rec_name) - except Exception, e: + except Exception as e: logger.warning("Error validating generated Factura-e file", exc_info=True) logger.debug(xml_string) @@ -508,9 +507,8 @@ class Invoice: return signed_file_content -class InvoiceLine: +class InvoiceLine(metaclass=PoolMeta): __name__ = 'account.invoice.line' - __metaclass__ = PoolMeta @property def taxes_outputs(self): @@ -544,17 +542,15 @@ class InvoiceLine: return res -class CreditInvoiceStart: +class CreditInvoiceStart(metaclass=PoolMeta): __name__ = 'account.invoice.credit.start' - __metaclass__ = PoolMeta rectificative_reason_code = fields.Selection( [(x[0], x[1]) for x in RECTIFICATIVE_REASON_CODES], 'Rectificative Reason Code', required=True, sort=False) -class CreditInvoice: +class CreditInvoice(metaclass=PoolMeta): __name__ = 'account.invoice.credit' - __metaclass__ = PoolMeta def do_credit(self, action): with Transaction().set_context( diff --git a/party.py b/party.py index de7f0f8..40a974a 100644 --- a/party.py +++ b/party.py @@ -6,9 +6,8 @@ from trytond.pool import PoolMeta __all__ = ['Party'] -class Party: +class Party(metaclass=PoolMeta): __name__ = 'party.party' - __metaclass__ = PoolMeta facturae_person_type = fields.Selection([ (None, ''), ('J', 'Legal Entity'), diff --git a/payment_type.py b/payment_type.py index 501635c..834d8a2 100644 --- a/payment_type.py +++ b/payment_type.py @@ -6,9 +6,8 @@ from trytond.pool import PoolMeta __all__ = ['PaymentType'] -class PaymentType: +class PaymentType(metaclass=PoolMeta): __name__ = 'account.payment.type' - __metaclass__ = PoolMeta facturae_type = fields.Selection([ (None, ''), ('01', 'In cash'), diff --git a/setup.py b/setup.py index 3b441e1..39e3126 100644 --- a/setup.py +++ b/setup.py @@ -5,10 +5,7 @@ from setuptools import setup import re import os import io -try: - from configparser import ConfigParser -except ImportError: - from ConfigParser import ConfigParser +from configparser import ConfigParser MODULE = 'account_invoice_facturae' PREFIX = 'nantic'