Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions febraban/cnab240/bradesco/multipag/file/header.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from febraban.cnab240.row import Row
from febraban.cnab240.characterType import alphaNumeric, numeric
from febraban.cnab240.characterType import alphaNumeric, alphaNumericRightAligned, numeric


class Header:
Expand Down Expand Up @@ -35,7 +35,7 @@ def setGeneratedFileDate(self, datetime):
def setSender(self, user):
structs = [
(17, 18, 1, numeric, "1" if len(user.identifier) == 11 else "2"),
(18, 32, 14, numeric, user.identifier),
(18, 32, 14, alphaNumericRightAligned, user.identifier),
(72, 102, 30, alphaNumeric, user.name)
]
self.content = Row.setStructs(structs=structs, content=self.content)
Expand Down
4 changes: 2 additions & 2 deletions febraban/cnab240/bradesco/multipag/file/headerLot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from febraban.cnab240.row import Row
from febraban.cnab240.characterType import alphaNumeric, numeric
from febraban.cnab240.characterType import alphaNumeric, alphaNumericRightAligned, numeric

class HeaderLot:

Expand All @@ -21,7 +21,7 @@ def defaultValues(self):
def setSender(self, user):
structs = [
(17, 18, 1, numeric, "1" if len(user.identifier) == 11 else "2"),
(18, 32, 14, numeric, user.identifier),
(18, 32, 14, alphaNumericRightAligned, user.identifier),
(72, 102, 30, alphaNumeric, user.name)
]
self.content = Row.setStructs(structs=structs, content=self.content)
Expand Down
2 changes: 1 addition & 1 deletion febraban/cnab240/bradesco/multipag/payment/darfPayment.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setTaxPaymentIdentifier(self, id):


def setTaxIdInfo(self, taxId):
taxId = "".join(c for c in taxId if c.isdigit())
taxId = "".join(c for c in taxId if c.isalnum()).upper()
taxIdType = "2" if len(taxId) == 11 else "1"
self.segmentN.setTaxIdType(taxIdType)
self.segmentN.setTaxId(taxId)
Expand Down
4 changes: 2 additions & 2 deletions febraban/cnab240/bradesco/multipag/payment/segmentN.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8
from febraban.cnab240.row import Row
from febraban.cnab240.characterType import alphaNumeric, numeric
from febraban.cnab240.characterType import alphaNumeric, alphaNumericRightAligned, numeric


class SegmentN:
Expand Down Expand Up @@ -80,7 +80,7 @@ def setTaxIdType(self, taxIdType):

def setTaxId(self, taxId):
structs = [
(118, 132, 14, numeric, taxId),
(118, 132, 14, alphaNumericRightAligned, taxId),
]
self.content = Row.setStructs(structs=structs, content=self.content)

Expand Down
3 changes: 2 additions & 1 deletion febraban/cnab240/characterType.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


numeric = "numeric"
alphaNumeric = "alphaNumeric"
alphaNumeric = "alphaNumeric"
alphaNumericRightAligned = "alphaNumericRightAligned"
4 changes: 2 additions & 2 deletions febraban/cnab240/itau/charge/file/header.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ....row import Row
from ....characterType import numeric, alphaNumeric
from ....characterType import numeric, alphaNumeric, alphaNumericRightAligned


class Header:
Expand All @@ -25,7 +25,7 @@ def setGeneratedFileDate(self, datetime):
def setSender(self, user):
structs = [
(17, 18, 1, numeric, "1" if len(user.identifier) == 11 else "2"),
(18, 32, 14, numeric, user.identifier),
(18, 32, 14, alphaNumericRightAligned, user.identifier),
(72, 102, 30, alphaNumeric, user.name)
]
self.content = Row.setStructs(structs=structs, content=self.content)
Expand Down
4 changes: 2 additions & 2 deletions febraban/cnab240/itau/charge/file/headerLot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ....row import Row
from ....characterType import numeric, alphaNumeric
from ....characterType import numeric, alphaNumeric, alphaNumericRightAligned


class HeaderLot:
Expand Down Expand Up @@ -28,7 +28,7 @@ def setGeneratedFileDate(self, datetime):
def setSender(self, user):
structs = [
(17, 18, 1, numeric, "1" if len(user.identifier) == 11 else "2"),
(18, 33, 15, numeric, user.identifier),
(18, 33, 15, alphaNumericRightAligned, user.identifier),
(73, 103, 30, alphaNumeric, user.name)
]
self.content = Row.setStructs(structs=structs, content=self.content)
Expand Down
6 changes: 3 additions & 3 deletions febraban/cnab240/itau/charge/slip/segmentQ.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from ....row import Row
from ....characterType import numeric, alphaNumeric
from ....characterType import numeric, alphaNumeric, alphaNumericRightAligned


class SegmentQ:
Expand Down Expand Up @@ -38,7 +38,7 @@ def setPositionInLot(self, index):
def setPayer(self, user):
structs = [
(17, 18, 1, numeric, "1" if len(user.identifier) == 11 else "2"), # 1 - CPF/ 2 - CNPJ
(18, 33, 15, numeric, user.identifier), # CPF/CNPJ do Pagador
(18, 33, 15, alphaNumericRightAligned, user.identifier), # CPF/CNPJ do Pagador

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comentario desalinhado

(33, 63, 30, alphaNumeric, user.name) # Nome do Pagador
]
self.content = Row.setStructs(structs=structs, content=self.content)
Expand All @@ -56,7 +56,7 @@ def setPayerAddress(self, address):
def setGuarantor(self, user):
structs = [
(153, 154, 1, numeric, "1" if len(user.identifier) == 11 else "2"), # 1 - CPF/ 2 - CNPJ
(154, 169, 15, numeric, user.identifier), # CPF/CNPJ do Sacador Avalista
(154, 169, 15, alphaNumericRightAligned, user.identifier), # CPF/CNPJ do Sacador Avalista

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alinhar o comentario

(169, 199, 30, alphaNumeric, user.name) # Nome do Sacador Avalista
]
self.content = Row.setStructs(structs=structs, content=self.content)
4 changes: 2 additions & 2 deletions febraban/cnab240/itau/sispag/file/header.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

from ....row import Row
from ....characterType import numeric, alphaNumeric
from ....characterType import numeric, alphaNumeric, alphaNumericRightAligned


class Header:
Expand Down Expand Up @@ -30,7 +30,7 @@ def setGeneratedFileDate(self, datetime):
def setSender(self, user):
structs = [
(17, 18, 1, numeric, "1" if len(user.identifier) == 11 else "2"),
(18, 32, 14, numeric, user.identifier),
(18, 32, 14, alphaNumericRightAligned, user.identifier),
(72, 102, 30, alphaNumeric, user.name)
]
self.content = Row.setStructs(structs=structs, content=self.content)
Expand Down
4 changes: 2 additions & 2 deletions febraban/cnab240/itau/sispag/file/headerLot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

from ....row import Row
from ....characterType import numeric, alphaNumeric
from ....characterType import numeric, alphaNumeric, alphaNumericRightAligned


class HeaderLot:
Expand All @@ -22,7 +22,7 @@ def defaultValues(self):
def setSender(self, user):
structs = [
(17, 18, 1, numeric, "1" if len(user.identifier) == 11 else "2"),
(18, 32, 14, numeric, user.identifier),
(18, 32, 14, alphaNumericRightAligned, user.identifier),
(72, 102, 30, alphaNumeric, user.name)
]
self.content = Row.setStructs(structs=structs, content=self.content)
Expand Down
2 changes: 1 addition & 1 deletion febraban/cnab240/itau/sispag/payment/darfPayment.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def setRevenueCode(self, code):
self.segmentN.setRevenueCode(code)

def setTaxIdInfo(self, taxId):
taxId = "".join(c for c in taxId if c.isdigit())
taxId = "".join(c for c in taxId if c.isalnum()).upper()
taxIdType = "1" if len(taxId) == 11 else "2"
self.segmentN.setTaxIdType(taxIdType)
self.segmentN.setTaxId(taxId)
Expand Down
2 changes: 1 addition & 1 deletion febraban/cnab240/itau/sispag/payment/fgtsPayment.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setRevenueCode(self, code):
self.segmentN.setRevenueCode(code)

def setTaxIdInfo(self, taxId):
taxId = "".join(c for c in taxId if c.isdigit())
taxId = "".join(c for c in taxId if c.isalnum()).upper()
taxIdType = "1" if len(taxId) == 14 else "2"
self.segmentN.setTaxIdType(taxIdType)
self.segmentN.setTaxId(taxId)
Expand Down
6 changes: 3 additions & 3 deletions febraban/cnab240/itau/sispag/payment/segmentJ52.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8

from ....row import Row
from ....characterType import numeric, alphaNumeric
from ....characterType import numeric, alphaNumeric, alphaNumericRightAligned


class SegmentJ52:
Expand Down Expand Up @@ -31,15 +31,15 @@ def setSenderBank(self, bank):
def setSender(self, user):
structs = [
(19, 20, 1, numeric, "1" if len(user.identifier) == 11 else "2"),
(20, 35, 15, numeric, user.identifier),
(20, 35, 15, alphaNumericRightAligned, user.identifier),
(35, 75, 40, alphaNumeric, user.name)
]
self.content = Row.setStructs(structs=structs, content=self.content)

def setReceiverTaxId(self, receiverTaxId):
structs = [
(75, 76, 1, numeric, "1" if len(receiverTaxId) == 11 else "2"),
(76, 91, 15, numeric, receiverTaxId),
(76, 91, 15, alphaNumericRightAligned, receiverTaxId),
]
self.content = Row.setStructs(structs=structs, content=self.content)

Expand Down
4 changes: 2 additions & 2 deletions febraban/cnab240/itau/sispag/payment/segmentN.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
# Pagamento de Contas de Concessionárias e Tributos sem código de barras # Página 31
from ....row import Row
from ....characterType import numeric, alphaNumeric
from ....characterType import numeric, alphaNumeric, alphaNumericRightAligned


class SegmentN:
Expand Down Expand Up @@ -57,7 +57,7 @@ def setTaxIdType(self, taxIdType):

def setTaxId(self, taxId):
structs = [
(24, 38, 14, alphaNumeric, taxId),
(24, 38, 14, alphaNumericRightAligned, taxId),
]
self.content = Row.setStructs(structs=structs, content=self.content)

Expand Down
11 changes: 6 additions & 5 deletions febraban/cnab240/libs/middlewares/row.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
from re import match
from ...characterType import alphaNumeric, numeric
from ...characterType import alphaNumeric, numeric, alphaNumericRightAligned


def validateFormatter(func):
def wrapper(self, string, charactersType, numberOfCharacters, defaultCharacter):
if type(numberOfCharacters) != int:
raise ValueError("numberOfCharacters must be Integer")

if charactersType not in [alphaNumeric, numeric]:
raise ValueError("charactersType must be alphaNumeric or numeric")
if charactersType not in [alphaNumeric, numeric, alphaNumericRightAligned]:
raise ValueError("charactersType must be alphaNumeric, numeric or alphaNumericRightAligned")

if not isinstance(string, str):
raise ValueError("(%s,%s) is not an allowed value. It must be string" % (str(string), str(type(string))))

regex = {
alphaNumeric: r'^[A-Za-z0-9\s\-]+$',
numeric: r'^[0-9]+$'
alphaNumeric: r'^[A-Za-z0-9\s\-]+$',
numeric: r'^[0-9]+$',
alphaNumericRightAligned: r'^[A-Z0-9]+$',
}[charactersType]
if string and not match(regex, string):
raise ValueError("You add %s that is a non %s value" % (string, charactersType))
Expand Down
15 changes: 7 additions & 8 deletions febraban/cnab240/row.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .libs.middlewares.row import validateFormatter
from .characterType import numeric, alphaNumeric
from .characterType import numeric, alphaNumeric, alphaNumericRightAligned


class Row:
Expand All @@ -11,7 +11,7 @@ def setStructs(cls, structs, content):
string=str(value),
charactersType=type,
numberOfCharacters=len,
defaultCharacter={numeric: "0", alphaNumeric: " "}[type]
defaultCharacter={numeric: "0", alphaNumeric: " ", alphaNumericRightAligned: "0"}[type]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

para alfanumerico é para completar com espaço e não com zero. Zero é usado somente para o numerico

)
content = content[:start] + replacement + content[start+len:]
return content
Expand All @@ -25,14 +25,13 @@ def __formatted(cls, string, charactersType, numberOfCharacters, defaultCharacte

Args:
string: String to be completed
charactersType: Can be .numeric or .alphaNumeric
charactersType: Can be .numeric, .alphaNumeric or .alphaNumericRightAligned
numberOfCharacters: Integer that represents the max string len
defaultCharacter: Single string with default character to be completed if string is short
Returns:
String formatted
"""
if type(string) != str: return defaultCharacter * numberOfCharacters
if len(string) > numberOfCharacters: return string[:numberOfCharacters]
if charactersType == numeric: return defaultCharacter * (numberOfCharacters - len(string)) + string

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

porque foi removido essa condicional ?

if charactersType == alphaNumeric: return string + defaultCharacter * (numberOfCharacters - len(string))
return string
if type(string) != str: return defaultCharacter * numberOfCharacters
if len(string) > numberOfCharacters: return string[:numberOfCharacters]
if charactersType == alphaNumeric: return string + defaultCharacter * (numberOfCharacters - len(string))
return defaultCharacter * (numberOfCharacters - len(string)) + string
2 changes: 1 addition & 1 deletion febraban/cnab240/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class User:

def __init__(self, name, identifier, bank=None, address=None):
self.name = name
self.identifier = identifier
self.identifier = identifier.upper() if isinstance(identifier, str) else identifier
self.bank = bank
self.address = address

Expand Down
Loading