Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def consultar_and_recover(cls, invoices):
for invoice in invoices:
ws = cls.get_ws_afip(invoice=invoice)
if not invoice.invoice_date:
raise UserError(gettext(
'account_invoice_ar.msg_missing_invoice_date'))
ws.Reprocesar = True
ws, error = invoice.create_pyafipws_invoice(ws)
cbte_nro = int(invoice.number[-8:])
cae = ws.CompConsultar(invoice.invoice_type.invoice_type,
invoice.pos.number, cbte_nro, reproceso=True)
if cae and ws.EmisionTipo == 'CAE':
# la factura se recupera y puede pasar a estado posted
logger.info('se ha reprocesado invoice %s', invoice.id)
if not invoice.transactions:
invoice.save_afip_tr(ws, msg='Reprocesar=S')
tipo_cbte = invoice.invoice_type.invoice_type
punto_vta = invoice.pos.number
vto = ws.Vencimiento
cae_due = ''.join([c for c in str(vto)
if c.isdigit()])
required_test(
getattr(record, field_name), field_name, field)
# validate size
if hasattr(field, 'size') and field.size is not None:
for record in records:
if isinstance(field.size, PYSON):
field_size = _record_eval_pyson(record, field.size)
else:
field_size = field.size
size = len(getattr(record, field_name) or '')
if (size > field_size >= 0):
error_args = cls.__names__(field_name)
error_args['size'] = size
error_args['max_size'] = field_size
raise SizeValidationError(
gettext('ir.msg_size_validation_record',
**error_args))
def digits_test(value, digits, field_name):
def raise_error(value):
error_args = cls.__names__(field_name)
error_args['digits'] = digits[1]
error_args['value'] = repr(value)
raise DigitsValidationError(
gettext('ir.msg_digits_validation_record',
**error_args))
if (value is None
or not digits
or any(d is None for d in digits)):
return
if isinstance(value, Decimal):
exp = Decimal('.'.join(['0', '0' * digits[1]]))
def check_condition(cls, triggers):
'''
Check condition
'''
for trigger in triggers:
try:
PYSONDecoder(noeval=True).decode(trigger.condition)
except Exception:
raise ConditionError(
gettext('ir.msg_trigger_invalid_condition',
condition=trigger.condition,
trigger=trigger.rec_name))
def get_many2one(relation, value):
if not value:
return None
Relation = pool.get(relation)
res = Relation.search([
('rec_name', '=', value),
], limit=2)
if len(res) < 1:
raise ImportDataError(gettext(
'ir.msg_relation_not_found',
value=value,
model=relation))
elif len(res) > 1:
raise ImportDataError(
gettext('ir.msg_too_many_relations_found',
value=value,
model=relation))
else:
res = res[0].id
return res
return credit
credit.pos = self.pos
credit.invoice_date = Date.today()
invoice_type, invoice_type_desc = INVOICE_CREDIT_AFIP_CODE[
(self.invoice_type.invoice_type)
]
sequences = PosSequence.search([
('pos', '=', credit.pos),
('invoice_type', '=', invoice_type)
])
if len(sequences) == 0:
raise UserError(gettext(
'account_invoice_ar.msg_missing_sequence', invoice_type_desc))
elif len(sequences) > 1:
raise UserError(gettext(
'account_invoice_ar.msg_too_many_sequences',
invoice_type_desc))
else:
credit.invoice_type = sequences[0]
if self.pos.pos_type == 'electronic':
credit.pyafipws_concept = self.pyafipws_concept
if self.pyafipws_concept in ['2', '3']:
credit.pyafipws_billing_start_date = (
self.pyafipws_billing_start_date)
credit.pyafipws_billing_end_date = (
self.pyafipws_billing_end_date)
if self.invoice_type.invoice_type in ['19', '20', '21']:
credit.pyafipws_incoterms = self.pyafipws_incoterms
credit.pyafipws_licenses = self.pyafipws_licenses
def delete(cls, records):
for module in records:
if module.state in (
'activated',
'to upgrade',
'to remove',
'to activate',
):
raise AccessError(gettext('ir.msg_module_delete_state'))
return super(Module, cls).delete(records)
def delete(cls, langs):
pool = Pool()
Config = pool.get('ir.configuration')
Translation = pool.get('ir.translation')
for lang in langs:
if lang.code == Config.get_language():
raise DeleteDefaultError(
gettext('ir.msg_language_delete_default'))
# Clear cache
cls._lang_cache.clear()
cls._code_cache.clear()
super(Lang, cls).delete(langs)
Translation._get_language_cache.clear()
_parents.clear()
def check_unique_reference(self):
invoice = self.search([
('id', '!=', self.id),
('type', '=', self.type),
('party', '=', self.party.id),
('tipo_comprobante', '=', self.tipo_comprobante),
('reference', '=', self.reference),
('state', '!=', 'cancel'),
])
if len(invoice) > 0:
raise UserError(gettext(
'account_invoice_ar.msg_reference_unique'))
def get_ws_afip(cls, invoice=None, batch=False):
'''
Connect to WSAA AFIP and get webservice wsfe or wsfex
'''
if batch is False and invoice:
service = invoice.pos.pyafipws_electronic_invoice_service
elif batch is True:
service = 'wsfe'
else:
logger.error('AFIP web service is unknown')
raise UserError(gettext(
'account_invoice_ar.msg_webservice_unknown'))
(company, auth_data) = cls.authenticate_afip(service=service)
# TODO: get wsdl url from DictField?
if service == 'wsfe':
ws = WSFEv1()
if company.pyafipws_mode_cert == 'homologacion':
WSDL = 'https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL'
elif company.pyafipws_mode_cert == 'produccion':
WSDL = (
'https://servicios1.afip.gov.ar/wsfev1/service.asmx?WSDL')
elif service == 'wsfex':
ws = WSFEXv1()
if company.pyafipws_mode_cert == 'homologacion':
WSDL = 'https://wswhomo.afip.gov.ar/wsfexv1/service.asmx?WSDL'
elif company.pyafipws_mode_cert == 'produccion':
transaction = Transaction()
for field_name in field_names:
if field_name not in cls._fields:
continue
field = cls._fields[field_name]
# Check required fields
if (field.required
and field.sql_type()
and field_name not in ('create_uid', 'create_date')):
if values.get(field_name) is None:
raise RequiredValidationError(
gettext('ir.msg_required_validation_record',
**cls.__names__(field_name)))
for name, _, error in cls._sql_constraints:
if backend.TableHandler.convert_name(name) in str(exception):
raise SQLConstraintError(gettext(error))
# Check foreign key in last because this can raise false positive
# if the target is created during the same transaction.
for field_name in field_names:
if field_name not in cls._fields:
continue
field = cls._fields[field_name]
if isinstance(field, fields.Many2One) and values.get(field_name):
Model = pool.get(field.model_name)
create_records = transaction.create_records.get(
field.model_name, set())
delete_records = transaction.delete_records.get(
field.model_name, set())
target_records = Model.search([
('id', '=', field.sql_format(values[field_name])),
], order=[])
if not ((