Migrate to python 3

This commit is contained in:
Albert Cervera i Areny 2018-10-11 15:32:09 +02:00
parent 3be36bbc79
commit 835fe2595a
8 changed files with 38 additions and 40 deletions

View File

@ -10,9 +10,8 @@ from .aeat import (BOOK_KEY, SEND_SPECIAL_REGIME_KEY,
__all__ = ['TemplateTax', 'Tax'] __all__ = ['TemplateTax', 'Tax']
class TemplateTax: class TemplateTax(metaclass=PoolMeta):
__name__ = 'account.tax.template' __name__ = 'account.tax.template'
__metaclass__ = PoolMeta
sii_book_key = fields.Selection(BOOK_KEY, 'Book Key') sii_book_key = fields.Selection(BOOK_KEY, 'Book Key')
sii_issued_key = fields.Selection(SEND_SPECIAL_REGIME_KEY, 'Issued Key') sii_issued_key = fields.Selection(SEND_SPECIAL_REGIME_KEY, 'Issued Key')
@ -37,9 +36,8 @@ class TemplateTax:
return res return res
class Tax: class Tax(metaclass=PoolMeta):
__name__ = 'account.tax' __name__ = 'account.tax'
__metaclass__ = PoolMeta
sii_book_key = fields.Selection(BOOK_KEY, 'Book Key') sii_book_key = fields.Selection(BOOK_KEY, 'Book Key')
sii_issued_key = fields.Selection(SEND_SPECIAL_REGIME_KEY, 'Issued Key') sii_issued_key = fields.Selection(SEND_SPECIAL_REGIME_KEY, 'Issued Key')

View File

@ -222,14 +222,14 @@ def remove_accents(unicode_string):
except UnicodeDecodeError: except UnicodeDecodeError:
return unicode_string_bak return unicode_string_bak
if not isinstance(unicode_string, unicode): if not isinstance(unicode_string, str):
return unicode_string return unicode_string
# From http://www.leccionespracticas.com/uncategorized/eliminar-tildes-con-python-solucionado # From http://www.leccionespracticas.com/uncategorized/eliminar-tildes-con-python-solucionado
unicode_string_nfd = ''.join( unicode_string_nfd = ''.join(
(c for c in unicodedata.normalize('NFD', unicode_string) (c for c in unicodedata.normalize('NFD', unicode_string)
if (unicodedata.category(c) != 'Mn' if (unicodedata.category(c) != 'Mn'
or c in (u'\u0327', u'\u0303')) # ç or ñ or c in ('\u0327', '\u0303')) # ç or ñ
)) ))
# It converts nfd to nfc to allow unicode.decode() # It converts nfd to nfc to allow unicode.decode()
return unicodedata.normalize('NFC', unicode_string_nfd) return unicodedata.normalize('NFC', unicode_string_nfd)

View File

@ -15,9 +15,8 @@ __all__ = ['Company']
_logger = getLogger(__name__) _logger = getLogger(__name__)
class Company: class Company(metaclass=PoolMeta):
__name__ = 'company.company' __name__ = 'company.company'
__metaclass__ = PoolMeta
pem_certificate = fields.Binary('PEM Certificate') pem_certificate = fields.Binary('PEM Certificate')
encrypted_private_key = fields.Binary('Encrypted Private Key') encrypted_private_key = fields.Binary('Encrypted Private Key')

View File

@ -22,8 +22,7 @@ _SII_INVOICE_KEYS = ['sii_book_key', 'sii_issued_key', 'sii_received_key',
'sii_intracomunity_key'] 'sii_intracomunity_key']
class Invoice: class Invoice(metaclass=PoolMeta):
__metaclass__ = PoolMeta
__name__ = 'account.invoice' __name__ = 'account.invoice'
sii_book_key = fields.Selection(BOOK_KEY, 'SII Book Key') sii_book_key = fields.Selection(BOOK_KEY, 'SII Book Key')
@ -219,8 +218,7 @@ class Invoice:
cls.raise_user_warning(warning_name, 'invoices_sii', invoices_sii) cls.raise_user_warning(warning_name, 'invoices_sii', invoices_sii)
class Sale: class Sale(metaclass=PoolMeta):
__metaclass__ = PoolMeta
__name__ = 'sale.sale' __name__ = 'sale.sale'
def create_invoice(self): def create_invoice(self):
@ -239,8 +237,7 @@ class Sale:
return invoice return invoice
class Purchase: class Purchase(metaclass=PoolMeta):
__metaclass__ = PoolMeta
__name__ = 'purchase.purchase' __name__ = 'purchase.purchase'
def create_invoice(self): def create_invoice(self):

View File

@ -7,9 +7,8 @@ from . import aeat
__all__ = ['Party'] __all__ = ['Party']
class Party: class Party(metaclass=PoolMeta):
__name__ = 'party.party' __name__ = 'party.party'
__metaclass__ = PoolMeta
sii_identifier_type = fields.Selection(aeat.PARTY_IDENTIFIER_TYPE, sii_identifier_type = fields.Selection(aeat.PARTY_IDENTIFIER_TYPE,
'SII Identifier Type') 'SII Identifier Type')

View File

@ -5,10 +5,7 @@ from setuptools import setup
import re import re
import os import os
import io import io
try: from configparser import ConfigParser
from configparser import ConfigParser
except ImportError:
from ConfigParser import ConfigParser
MODULE = 'aeat_sii' MODULE = 'aeat_sii'
PREFIX = 'trytonspain' PREFIX = 'trytonspain'

View File

@ -70,6 +70,16 @@ Create party::
>>> party = Party(name='Party') >>> party = Party(name='Party')
>>> party.save() >>> party.save()
Create account category::
>>> ProductCategory = Model.get('product.category')
>>> account_category = ProductCategory(name="Account Category")
>>> account_category.accounting = True
>>> account_category.account_expense = expense
>>> account_category.account_revenue = revenue
>>> account_category.customer_taxes.append(tax)
>>> account_category.save()
Create product:: Create product::
>>> ProductUom = Model.get('product.uom') >>> ProductUom = Model.get('product.uom')
@ -83,11 +93,9 @@ Create product::
>>> template.type = 'service' >>> template.type = 'service'
>>> template.list_price = Decimal('40') >>> template.list_price = Decimal('40')
>>> template.cost_price = Decimal('25') >>> template.cost_price = Decimal('25')
>>> template.account_expense = expense >>> template.account_category = account_category
>>> template.account_revenue = revenue
>>> template.customer_taxes.append(tax)
>>> template.save() >>> template.save()
>>> product.template = template >>> product, = template.products
>>> product.save() >>> product.save()
Create payment term:: Create payment term::
@ -120,11 +128,11 @@ Create invoice::
>>> line.unit_price = Decimal(20) >>> line.unit_price = Decimal(20)
>>> invoice.save() >>> invoice.save()
>>> invoice.sii_book_key >>> invoice.sii_book_key
u'E' 'E'
>>> invoice.sii_operation_key >>> invoice.sii_operation_key
u'F1' 'F1'
>>> invoice.sii_issued_key >>> invoice.sii_issued_key
u'01' '01'
>>> invoice.sii_book_key = 'I' >>> invoice.sii_book_key = 'I'
>>> invoice.sii_operation_key = 'F2' >>> invoice.sii_operation_key = 'F2'
@ -143,7 +151,7 @@ Create invoice::
True True
>>> invoice.click('post') >>> invoice.click('post')
>>> invoice.state >>> invoice.state
u'posted' 'posted'
Create Credit invoice:: Create Credit invoice::
@ -164,11 +172,11 @@ Create Credit invoice::
>>> invoice.sii_operation_key = 'R1' >>> invoice.sii_operation_key = 'R1'
>>> invoice.save() >>> invoice.save()
>>> invoice.sii_book_key >>> invoice.sii_book_key
u'E' 'E'
>>> invoice.sii_operation_key >>> invoice.sii_operation_key
u'R1' 'R1'
>>> invoice.sii_issued_key >>> invoice.sii_issued_key
u'01' '01'
>>> invoice.sii_book_key = 'I' >>> invoice.sii_book_key = 'I'
>>> invoice.sii_operation_key = 'F2' >>> invoice.sii_operation_key = 'F2'
@ -184,7 +192,7 @@ Create Credit invoice::
True True
>>> invoice.click('post') >>> invoice.click('post')
>>> invoice.state >>> invoice.state
u'posted' 'posted'
Create AEAT Report:: Create AEAT Report::
@ -196,7 +204,7 @@ Create AEAT Report::
>>> report.book = 'E' >>> report.book = 'E'
>>> report.save() >>> report.save()
>>> report.state >>> report.state
u'draft' 'draft'
>>> report.click('load_invoices') >>> report.click('load_invoices')
>>> len(report.lines) >>> len(report.lines)
2 2
@ -208,7 +216,7 @@ Credit invoice with refund::
>>> credit.execute('credit') >>> credit.execute('credit')
>>> invoice.reload() >>> invoice.reload()
>>> invoice.state >>> invoice.state
u'paid' 'paid'
>>> credit, = Invoice.find([('total_amount', '<', 0)]) >>> credit, = Invoice.find([('total_amount', '<', 0)])
>>> credit.sii_operation_key >>> credit.sii_operation_key
u'R1' 'R1'

View File

@ -3,21 +3,21 @@
# copyright notices and license terms. # copyright notices and license terms.
import unicodedata import unicodedata
src_chars = u"/*+?¿!$[]{}@#`^:;<>=~%\\" src_chars = "/*+?¿!$[]{}@#`^:;<>=~%\\"
dst_chars = u"________________________" dst_chars = "________________________"
def normalize(text): def normalize(text):
if isinstance(text, unicode): if isinstance(text, str):
text = text.encode('utf-8') text = text.encode('utf-8')
return text return text
def unaccent(text): def unaccent(text):
if isinstance(text, bytes): if isinstance(text, bytes):
text = unicode(text, 'utf-8') text = str(text, 'utf-8')
output = text output = text
for c in xrange(len(src_chars)): for c in range(len(src_chars)):
if c >= len(dst_chars): if c >= len(dst_chars):
break break
output = output.replace(src_chars[c], dst_chars[c]) output = output.replace(src_chars[c], dst_chars[c])