diff --git a/l10n_br_account_product/sped/nfe/document.py b/l10n_br_account_product/sped/nfe/document.py
index 3af07cd1b..5307078fc 100644
--- a/l10n_br_account_product/sped/nfe/document.py
+++ b/l10n_br_account_product/sped/nfe/document.py
@@ -17,14 +17,13 @@
#along with this program. If not, see . #
###############################################################################
-import re
-import string
from datetime import datetime
from openerp import pooler
from openerp.osv import orm
from openerp.tools.translate import _
from openerp.addons.l10n_br_account.sped.document import FiscalDocument
+from openerp.addons.l10n_br_base.tools.misc import punctuation_rm
class NFe200(FiscalDocument):
@@ -83,7 +82,7 @@ def _serializer(self, cr, uid, ids, nfe_environment, context=None):
if inv.partner_shipping_id:
if inv.partner_id.id != inv.partner_shipping_id.id:
if nfe.infNFe.ide.tpNF.valor == '0':
- nfe.infNFe.retirada.CNPJ.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv.partner_shipping_id.cnpj_cpf or '')
+ nfe.infNFe.retirada.CNPJ.valor = punctuation_rm(inv.partner_shipping_id.cnpj_cpf)
nfe.infNFe.retirada.xLgr.valor = inv.partner_shipping_id.street or ''
nfe.infNFe.retirada.nro.valor = inv.partner_shipping_id.number or ''
nfe.infNFe.retirada.xCpl.valor = inv.partner_shipping_id.street2 or ''
@@ -92,7 +91,7 @@ def _serializer(self, cr, uid, ids, nfe_environment, context=None):
nfe.infNFe.retirada.xMun.valor = inv.partner_shipping_id.l10n_br_city_id.name or ''
nfe.infNFe.retirada.UF.valor = inv.address_invoice_id.state_id.code or ''
else:
- nfe.infNFe.entrega.CNPJ.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv.partner_shipping_id.cnpj_cpf or '')
+ nfe.infNFe.entrega.CNPJ.valor = punctuation_rm(inv.partner_shipping_id.cnpj_cpf)
nfe.infNFe.entrega.xLgr.valor = inv.partner_shipping_id.street or ''
nfe.infNFe.entrega.nro.valor = inv.partner_shipping_id.number or ''
nfe.infNFe.entrega.xCpl.valor = inv.partner_shipping_id.street2 or ''
@@ -111,21 +110,21 @@ def _serializer(self, cr, uid, ids, nfe_environment, context=None):
if inv_related.document_type == 'nf':
nfref.refNF.cUF.valor = inv_related.state_id and inv_related.state_id.ibge_code or '',
nfref.refNF.AAMM.valor = datetime.strptime(inv_related.date, '%Y-%m-%d').strftime('%y%m') or ''
- nfref.refNF.CNPJ.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv_related.cnpj_cpf or '')
+ nfref.refNF.CNPJ.valor = punctuation_rm(inv_related.cnpj_cpf)
nfref.refNF.mod.valor = inv_related.fiscal_document_id and inv_related.fiscal_document_id.code or ''
nfref.refNF.serie.valor = inv_related.serie or ''
nfref.refNF.nNF.valor = inv_related.internal_number or ''
elif inv_related.document_type == 'nfrural':
nfref.refNFP.cUF.valor = inv_related.state_id and inv_related.state_id.ibge_code or '',
nfref.refNFP.AAMM.valor = datetime.strptime(inv_related.date, '%Y-%m-%d').strftime('%y%m') or ''
- nfref.refNFP.IE.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv_related.inscr_est or '')
+ nfref.refNFP.IE.valor = punctuation_rm(inv_related.inscr_est)
nfref.refNFP.mod.valor = inv_related.fiscal_document_id and inv_related.fiscal_document_id.code or ''
nfref.refNFP.serie.valor = inv_related.serie or ''
nfref.refNFP.nNF.valor = inv_related.internal_number or ''
if inv_related.cpfcnpj_type == 'cnpj':
- nfref.refNFP.CNPJ.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv_related.cnpj_cpf or '')
+ nfref.refNFP.CNPJ.valor = punctuation_rm(inv_related.cnpj_cpf)
else:
- nfref.refNFP.CPF.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv_related.cnpj_cpf or '')
+ nfref.refNFP.CPF.valor = punctuation_rm(inv_related.cnpj_cpf)
elif inv_related.document_type == 'nfe':
nfref.refNFe.valor = inv_related.access_key or ''
elif inv_related.document_type == 'cte':
@@ -140,7 +139,7 @@ def _serializer(self, cr, uid, ids, nfe_environment, context=None):
#
# Emitente
#
- nfe.infNFe.emit.CNPJ.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv.company_id.partner_id.cnpj_cpf or '')
+ nfe.infNFe.emit.CNPJ.valor = punctuation_rm(inv.company_id.partner_id.cnpj_cpf)
nfe.infNFe.emit.xNome.valor = inv.company_id.partner_id.legal_name
nfe.infNFe.emit.xFant.valor = inv.company_id.partner_id.name
nfe.infNFe.emit.enderEmit.xLgr.valor = company.street or ''
@@ -150,16 +149,16 @@ def _serializer(self, cr, uid, ids, nfe_environment, context=None):
nfe.infNFe.emit.enderEmit.cMun.valor = '%s%s' % (company.state_id.ibge_code, company.l10n_br_city_id.ibge_code)
nfe.infNFe.emit.enderEmit.xMun.valor = company.l10n_br_city_id.name or ''
nfe.infNFe.emit.enderEmit.UF.valor = company.state_id.code or ''
- nfe.infNFe.emit.enderEmit.CEP.valor = re.sub('[%s]' % re.escape(string.punctuation), '', str(company.zip or '').replace(' ',''))
+ nfe.infNFe.emit.enderEmit.CEP.valor = punctuation_rm(company.zip)
nfe.infNFe.emit.enderEmit.cPais.valor = company.country_id.bc_code[1:]
nfe.infNFe.emit.enderEmit.xPais.valor = company.country_id.name
- nfe.infNFe.emit.enderEmit.fone.valor = re.sub('[%s]' % re.escape(string.punctuation), '', str(company.phone or '').replace(' ',''))
- nfe.infNFe.emit.IE.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv.company_id.partner_id.inscr_est or '')
+ nfe.infNFe.emit.enderEmit.fone.valor = punctuation_rm(company.phone or '').replace(' ', '')
+ nfe.infNFe.emit.IE.valor = punctuation_rm(inv.company_id.partner_id.inscr_est)
nfe.infNFe.emit.IEST.valor = ''
- nfe.infNFe.emit.IM.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv.company_id.partner_id.inscr_mun or '')
+ nfe.infNFe.emit.IM.valor = punctuation_rm(inv.company_id.partner_id.inscr_mun)
nfe.infNFe.emit.CRT.valor = inv.company_id.fiscal_type or ''
if inv.company_id.partner_id.inscr_mun:
- nfe.infNFe.emit.CNAE.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv.company_id.cnae_main_id.code or '')
+ nfe.infNFe.emit.CNAE.valor = punctuation_rm(inv.company_id.cnae_main_id.code)
#
# Destinatário
@@ -178,7 +177,7 @@ def _serializer(self, cr, uid, ids, nfe_environment, context=None):
else:
address_invoice_state_code = inv.partner_id.state_id.code
address_invoice_city = inv.partner_id.l10n_br_city_id.name or ''
- partner_cep = re.sub('[%s]' % re.escape(string.punctuation), '', str(inv.partner_id.zip or '').replace(' ',''))
+ partner_cep = punctuation_rm(inv.partner_id.zip)
# Se o ambiente for de teste deve ser
# escrito na razão do destinatário
@@ -188,10 +187,10 @@ def _serializer(self, cr, uid, ids, nfe_environment, context=None):
nfe.infNFe.dest.xNome.valor = inv.partner_id.legal_name or ''
if inv.partner_id.is_company:
- nfe.infNFe.dest.CNPJ.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv.partner_id.cnpj_cpf or '')
- nfe.infNFe.dest.IE.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv.partner_id.inscr_est or '')
+ nfe.infNFe.dest.CNPJ.valor = punctuation_rm(inv.partner_id.cnpj_cpf)
+ nfe.infNFe.dest.IE.valor = punctuation_rm(inv.partner_id.inscr_est)
else:
- nfe.infNFe.dest.CPF.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv.partner_id.cnpj_cpf or '')
+ nfe.infNFe.dest.CPF.valor = punctuation_rm(inv.partner_id.cnpj_cpf)
nfe.infNFe.dest.enderDest.xLgr.valor = inv.partner_id.street or ''
nfe.infNFe.dest.enderDest.nro.valor = inv.partner_id.number or ''
@@ -203,7 +202,7 @@ def _serializer(self, cr, uid, ids, nfe_environment, context=None):
nfe.infNFe.dest.enderDest.CEP.valor = partner_cep
nfe.infNFe.dest.enderDest.cPais.valor = partner_bc_code
nfe.infNFe.dest.enderDest.xPais.valor = inv.partner_id.country_id.name or ''
- nfe.infNFe.dest.enderDest.fone.valor = re.sub('[%s]' % re.escape(string.punctuation), '', str(inv.partner_id.phone or '').replace(' ',''))
+ nfe.infNFe.dest.enderDest.fone.valor = punctuation_rm(inv.partner_id.phone or '').replace(' ', '')
nfe.infNFe.dest.email.valor = inv.partner_id.email or ''
#
@@ -218,7 +217,7 @@ def _serializer(self, cr, uid, ids, nfe_environment, context=None):
det.prod.cProd.valor = inv_line.product_id.code or ''
det.prod.cEAN.valor = inv_line.product_id.ean13 or ''
det.prod.xProd.valor = inv_line.product_id.name or ''
- det.prod.NCM.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv_line.fiscal_classification_id.name or '')
+ det.prod.NCM.valor = punctuation_rm(inv_line.fiscal_classification_id.name)
det.prod.EXTIPI.valor = ''
det.prod.CFOP.valor = inv_line.cfop_id.code
det.prod.uCom.valor = inv_line.uos_id.name or ''
@@ -274,7 +273,7 @@ def _serializer(self, cr, uid, ids, nfe_environment, context=None):
det.imposto.ISSQN.vAliq.valor = str("%.2f" % inv_line.issqn_percent)
det.imposto.ISSQN.vISSQN.valor = str("%.2f" % inv_line.issqn_value)
det.imposto.ISSQN.cMunFG.valor = ('%s%s') % (inv.partner_id.state_id.ibge_code, inv.partner_id.l10n_br_city_id.ibge_code)
- det.imposto.ISSQN.cListServ.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv_line.service_type_id.code or '')
+ det.imposto.ISSQN.cListServ.valor = punctuation_rm(inv_line.service_type_id.code)
det.imposto.ISSQN.cSitTrib.valor = inv_line.issqn_type
# PIS
@@ -351,9 +350,9 @@ def _serializer(self, cr, uid, ids, nfe_environment, context=None):
nfe.infNFe.transp.modFrete.valor = inv.incoterm and inv.incoterm.freight_responsibility or '9'
if inv.carrier_id.partner_id.is_company:
- nfe.infNFe.transp.transporta.CNPJ.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv.carrier_id.partner_id.cnpj_cpf or '')
+ nfe.infNFe.transp.transporta.CNPJ.valor = punctuation_rm(inv.carrier_id.partner_id.cnpj_cpf)
else:
- nfe.infNFe.transp.transporta.CPF.valor = re.sub('[%s]' % re.escape(string.punctuation), '', inv.carrier_id.partner_id.cnpj_cpf or '')
+ nfe.infNFe.transp.transporta.CPF.valor = punctuation_rm(inv.carrier_id.partner_id.cnpj_cpf)
nfe.infNFe.transp.transporta.xNome.valor = inv.carrier_id.partner_id.legal_name or ''
nfe.infNFe.transp.transporta.IE.valor = inv.carrier_id.partner_id.inscr_est or ''
nfe.infNFe.transp.transporta.xEnder.valor = inv.carrier_id.partner_id.street or ''
diff --git a/l10n_br_account_product/sped/nfe/serializer/txt.py b/l10n_br_account_product/sped/nfe/serializer/txt.py
index c2560ee6d..e2e32e4d9 100644
--- a/l10n_br_account_product/sped/nfe/serializer/txt.py
+++ b/l10n_br_account_product/sped/nfe/serializer/txt.py
@@ -19,8 +19,6 @@
import time
from datetime import datetime
-import re
-import string
from unicodedata import normalize
from openerp.osv import osv
@@ -28,6 +26,8 @@
from openerp import netsvc
import pooler
+from openerp.addons.l10n_br_base.tools.misc import punctuation_rm
+
def nfe_export(cr, uid, ids, nfe_environment='1',
nfe_version='200', context=False):
@@ -88,10 +88,10 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
StrRegB14 = {
'cUF': '%s' % inv_related.state_id and inv_related.state_id.ibge_code or '',
'AAMM': datetime.strptime(inv_related.date, '%Y-%m-%d').strftime('%y%m') or '',
- 'CNPJ': (re.sub('[%s]' % re.escape(string.punctuation), '', inv_related.cnpj_cpf or '')),
+ 'CNPJ': punctuation_rm(inv_related.cnpj_cpf),
'Mod': inv_related.fiscal_document_id and inv_related.fiscal_document_id.code or '',
'serie': inv_related.serie or '',
- 'nNF': (re.sub('[%s]' % re.escape(string.punctuation), '', inv_related.internal_number or '')),
+ 'nNF': punctuation_rm(inv_related.internal_number),
}
StrB14 = 'B14|%s|%s|%s|%s|%s|%s|\n' % (StrRegB14['cUF'],
@@ -104,10 +104,10 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
StrRegB20a = {
'cUF': '%s' % inv_related.state_id and inv_related.state_id.ibge_code or '',
'AAMM': datetime.strptime(inv_related.date, '%Y-%m-%d').strftime('%y%m') or '',
- 'IE': (re.sub('[%s]' % re.escape(string.punctuation), '', inv_related.inscr_est or '')),
+ 'IE': punctuation_rm(inv_related.inscr_est),
'mod': inv_related.fiscal_document_id and inv_related.fiscal_document_id.code or '',
'serie': inv_related.serie or '',
- 'nNF': (re.sub('[%s]' % re.escape(string.punctuation), '', inv_related.internal_number or '')),
+ 'nNF': punctuation_rm(inv_related.internal_number),
}
StrB20a = 'B20a|%s|%s|%s|%s|%s|%s|\n' % (StrRegB20a['cUF'],
StrRegB20a['AAMM'], StrRegB20a['IE'], StrRegB20a['mod'],
@@ -117,13 +117,13 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
if inv_related.cpfcnpj_type == 'cnpj':
StrRegB20d = {
- 'CNPJ': (re.sub('[%s]' % re.escape(string.punctuation), '', inv_related.cnpj_cpf or ''))
+ 'CNPJ': punctuation_rm(inv_related.cnpj_cpf)
}
StrB20d = 'B20d|%s|\n' % StrRegB20d['CNPJ']
StrFile += StrB20d
else:
StrRegB20e = {
- 'CPF': (re.sub('[%s]' % re.escape(string.punctuation), '', inv_related.cnpj_cpf or ''))
+ 'CPF': punctuation_rm(inv_related.cnpj_cpf)
}
StrB20e = 'B20e|%s|\n' % StrRegB20e['CPF']
StrFile += StrB20e
@@ -151,10 +151,10 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
StrRegC = {
'XNome': normalize('NFKD',unicode(inv.company_id.partner_id.legal_name or '')).encode('ASCII','ignore'),
'XFant': normalize('NFKD',unicode(inv.company_id.partner_id.name or '')).encode('ASCII','ignore'),
- 'IE': re.sub('[%s]' % re.escape(string.punctuation), '', inv.company_id.partner_id.inscr_est or ''),
+ 'IE': punctuation_rm(inv.company_id.partner_id.inscr_est),
'IEST': '',
- 'IM': re.sub('[%s]' % re.escape(string.punctuation), '', inv.company_id.partner_id.inscr_mun or ''),
- 'CNAE': re.sub('[%s]' % re.escape(string.punctuation), '', inv.company_id.cnae_main_id.code or ''),
+ 'IM': punctuation_rm(inv.company_id.partner_id.inscr_mun),
+ 'CNAE': punctuation_rm(inv.company_id.cnae_main_id.code),
'CRT': inv.company_id.fiscal_type or '',
}
@@ -168,9 +168,9 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
StrFile += StrC
if inv.company_id.partner_id.is_company:
- StrC02 = 'C02|%s|\n' % (re.sub('[%s]' % re.escape(string.punctuation), '', inv.company_id.partner_id.cnpj_cpf or ''))
+ StrC02 = 'C02|%s|\n' % (punctuation_rm(inv.company_id.partner_id.cnpj_cpf))
else:
- StrC02 = 'C02a|%s|\n' % (re.sub('[%s]' % re.escape(string.punctuation), '', inv.company_id.partner_id.cnpj_cpf or ''))
+ StrC02 = 'C02a|%s|\n' % (punctuation_rm(inv.company_id.partner_id.cnpj_cpf))
StrFile += StrC02
@@ -186,10 +186,10 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
'CMun': '%s%s' % (company_addr_default.state_id.ibge_code, company_addr_default.l10n_br_city_id.ibge_code),
'XMun': normalize('NFKD',unicode(company_addr_default.l10n_br_city_id.name or '')).encode('ASCII','ignore'),
'UF': company_addr_default.state_id.code or '',
- 'CEP': re.sub('[%s]' % re.escape(string.punctuation), '', str(company_addr_default.zip or '').replace(' ','')),
+ 'CEP': punctuation_rm(company_addr_default.zip),
'cPais': address_company_bc_code or '',
'xPais': normalize('NFKD',unicode(company_addr_default.country_id.name or '')).encode('ASCII','ignore'),
- 'fone': re.sub('[%s]' % re.escape(string.punctuation), '', str(company_addr_default.phone or '').replace(' ','')),
+ 'fone': punctuation_rm(company_addr_default.phone or '').replace(' ', ''),
}
StrC05 = 'C05|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|\n' % (StrRegC05['XLgr'], StrRegC05['Nro'], StrRegC05['Cpl'], StrRegC05['Bairro'],
@@ -218,7 +218,7 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
address_invoice_state_code = inv.partner_id.state_id.code
address_invoice_city = normalize('NFKD',unicode(inv.partner_id.l10n_br_city_id.name or '')).encode('ASCII','ignore')
address_invoice_city_code = ('%s%s') % (inv.partner_id.state_id.ibge_code, inv.partner_id.l10n_br_city_id.ibge_code)
- partner_cep = re.sub('[%s]' % re.escape(string.punctuation), '', str(inv.partner_id.zip or '').replace(' ',''))
+ partner_cep = punctuation_rm(inv.partner_id.zip)
# Se o ambiente for de teste deve ser escrito na razão do destinatário
if nfe_environment == '2':
@@ -228,7 +228,7 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
StrRegE = {
'xNome': xNome,
- 'IE': re.sub('[%s]' % re.escape(string.punctuation), '', inv.partner_id.inscr_est or ''),
+ 'IE': punctuation_rm(inv.partner_id.inscr_est),
'ISUF': '',
'email': inv.partner_id.email or '',
}
@@ -238,16 +238,16 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
StrFile += StrE
if inv.partner_id.is_company:
- StrE0 = 'E02|%s|\n' % (re.sub('[%s]' % re.escape(string.punctuation), '', inv.partner_id.cnpj_cpf or ''))
+ StrE0 = 'E02|%s|\n' % (punctuation_rm(inv.partner_id.cnpj_cpf))
else:
- StrE0 = 'E03|%s|\n' % (re.sub('[%s]' % re.escape(string.punctuation), '', inv.partner_id.cnpj_cpf or ''))
+ StrE0 = 'E03|%s|\n' % (punctuation_rm(inv.partner_id.cnpj_cpf))
StrFile += StrE0
StrRegE05 = {
'xLgr': normalize('NFKD',unicode(inv.partner_id.street or '')).encode('ASCII','ignore'),
'nro': normalize('NFKD',unicode(inv.partner_id.number or '')).encode('ASCII','ignore'),
- 'xCpl': re.sub('[%s]' % re.escape(string.punctuation), '', normalize('NFKD',unicode(inv.partner_id.street2 or '' )).encode('ASCII','ignore')),
+ 'xCpl': punctuation_rm(normalize('NFKD',unicode(inv.partner_id.street2 or '' )).encode('ASCII','ignore')),
'xBairro': normalize('NFKD',unicode(inv.partner_id.district or 'Sem Bairro')).encode('ASCII','ignore'),
'cMun': address_invoice_city_code,
'xMun': address_invoice_city,
@@ -255,7 +255,7 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
'CEP': partner_cep,
'cPais': partner_bc_code,
'xPais': normalize('NFKD',unicode(inv.partner_id.country_id.name or '')).encode('ASCII','ignore'),
- 'fone': re.sub('[%s]' % re.escape(string.punctuation), '', str(inv.partner_id.phone or '').replace(' ','')),
+ 'fone': punctuation_rm(inv.partner_id.phone or '').replace(' ', ''),
}
StrE05 = 'E05|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|\n' % (StrRegE05['xLgr'], StrRegE05['nro'], StrRegE05['xCpl'], StrRegE05['xBairro'],
@@ -271,8 +271,8 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
StrRegG = {
'XLgr': normalize('NFKD',unicode(inv.partner_shipping_id.street or '',)).encode('ASCII','ignore'),
'Nro': normalize('NFKD',unicode(inv.partner_shipping_id.number or '')).encode('ASCII','ignore'),
- 'XCpl': re.sub('[%s]' % re.escape(string.punctuation), '', normalize('NFKD',unicode(inv.partner_shipping_id.street2 or '' )).encode('ASCII','ignore')),
- 'XBairro': re.sub('[%s]' % re.escape(string.punctuation), '', normalize('NFKD',unicode(inv.partner_shipping_id.district or 'Sem Bairro' )).encode('ASCII','ignore')),
+ 'XCpl': punctuation_rm(normalize('NFKD',unicode(inv.partner_shipping_id.street2 or '' )).encode('ASCII','ignore')),
+ 'XBairro': punctuation_rm(normalize('NFKD',unicode(inv.partner_shipping_id.district or 'Sem Bairro' )).encode('ASCII','ignore')),
'CMun': ('%s%s') % (inv.partner_shipping_id.state_id.ibge_code, inv.partner_shipping_id.l10n_br_city_id.ibge_code),
'XMun': normalize('NFKD',unicode(inv.partner_shipping_id.l10n_br_city_id.name or '')).encode('ASCII','ignore'),
'UF': inv.partner_shipping_id.state_id.code,
@@ -282,9 +282,9 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
StrFile += StrG
if inv.partner_id.is_company:
- StrG0 = 'G02|%s|\n' % (re.sub('[%s]' % re.escape(string.punctuation), '', inv.partner_id.cnpj_cpf or ''))
+ StrG0 = 'G02|%s|\n' % (punctuation_rm(inv.partner_id.cnpj_cpf))
else:
- StrG0 = 'G02a|%s|\n' % (re.sub('[%s]' % re.escape(string.punctuation), '', inv.partner_id.cnpj_cpf or ''))
+ StrG0 = 'G02a|%s|\n' % (punctuation_rm(inv.partner_id.cnpj_cpf))
StrFile += StrG0
@@ -349,8 +349,8 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
'nItemPed': '',
}
- StrRegI['NCM'] = re.sub('[%s]' % re.escape(string.punctuation),
- '', inv_line.fiscal_classification_id.name or '')
+ StrRegI['NCM'] = punctuation_rm(
+ inv_line.fiscal_classification_id.name)
StrI = 'I|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|\n' % (StrRegI['CProd'], StrRegI['CEAN'], StrRegI['XProd'], StrRegI['NCM'],
StrRegI['EXTIPI'], StrRegI['CFOP'], StrRegI['UCom'], StrRegI['QCom'],
@@ -764,7 +764,7 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
'VAliq': str("%.2f" % inv_line.issqn_percent),
'VISSQN': str("%.2f" % inv_line.issqn_value),
'CMunFG': ('%s%s') % (inv.partner_id.state_id.ibge_code, inv.partner_id.l10n_br_city_id.ibge_code),
- 'CListServ': re.sub('[%s]' % re.escape(string.punctuation), '', inv_line.service_type_id.code or ''),
+ 'CListServ': punctuation_rm(inv_line.service_type_id.code),
'cSitTrib': inv_line.issqn_type
}
@@ -780,7 +780,7 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
StrQ = 'Q|\n'
StrFile += StrQ
- if pis_cst in ('01') and inv_line.pis_percent > 0:
+ if pis_cst in ('01', '02') and inv_line.pis_percent > 0:
StrRegQ02 = {
'CST': pis_cst,
'VBC': str("%.2f" % inv_line.pis_base),
@@ -820,7 +820,7 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
StrFile += StrQ
- if cofins_cst in ('01') and inv_line.cofins_percent > 0:
+ if cofins_cst in ('01', '02') and inv_line.cofins_percent > 0:
StrRegS02 = {
'CST': cofins_cst,
'VBC': str("%.2f" % inv_line.cofins_base),
@@ -927,9 +927,9 @@ def nfe_export(cr, uid, ids, nfe_environment='1',
StrRegX03['XMun'] = normalize('NFKD', unicode(carrier_addr_default.l10n_br_city_id.name or '')).encode('ASCII', 'ignore')
if inv.carrier_id.partner_id.is_company:
- StrX0 = 'X04|%s|\n' % (re.sub('[%s]' % re.escape(string.punctuation), '', inv.carrier_id.partner_id.cnpj_cpf or ''))
+ StrX0 = 'X04|%s|\n' % (punctuation_rm(inv.carrier_id.partner_id.cnpj_cpf))
else:
- StrX0 = 'X05|%s|\n' % (re.sub('[%s]' % re.escape(string.punctuation), '', inv.carrier_id.partner_id.cnpj_cpf or ''))
+ StrX0 = 'X05|%s|\n' % (punctuation_rm(inv.carrier_id.partner_id.cnpj_cpf))
except AttributeError:
pass
StrX03 = 'X03|%s|%s|%s|%s|%s|\n' % (StrRegX03['XNome'], StrRegX03['IE'], StrRegX03['XEnder'], StrRegX03['UF'], StrRegX03['XMun'])
diff --git a/l10n_br_base/tools/__init__.py b/l10n_br_base/tools/__init__.py
index 9742b60c8..cc39249b8 100644
--- a/l10n_br_base/tools/__init__.py
+++ b/l10n_br_base/tools/__init__.py
@@ -18,3 +18,4 @@
###############################################################################
import fiscal
+import misc
diff --git a/l10n_br_base/tools/misc.py b/l10n_br_base/tools/misc.py
new file mode 100644
index 000000000..98edab273
--- /dev/null
+++ b/l10n_br_base/tools/misc.py
@@ -0,0 +1,27 @@
+# -*- encoding: utf-8 -*-
+###############################################################################
+# #
+# Copyright (C) 2014 Renato Lima - Akretion #
+# #
+#This program is free software: you can redistribute it and/or modify #
+#it under the terms of the GNU Affero General Public License as published by #
+#the Free Software Foundation, either version 3 of the License, or #
+#(at your option) any later version. #
+# #
+#This program is distributed in the hope that it will be useful, #
+#but WITHOUT ANY WARRANTY; without even the implied warranty of #
+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+#GNU Affero General Public License for more details. #
+# #
+#You should have received a copy of the GNU Affero General Public License #
+#along with this program. If not, see . #
+###############################################################################
+
+import re
+import string
+
+
+def punctuation_rm(string_value):
+ tmp_value = (re.sub('[%s]' % re.escape(string.punctuation), '',
+ string_value or ''))
+ return tmp_value