-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rtc: Update AEC XML document validations #199
base: develop
Are you sure you want to change the base?
Conversation
|
||
tz_utils.validate_dt_tz(value, tz) | ||
|
||
current_date_in_tz = tz_utils.get_now_tz_aware().astimezone(tz) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK it is not necessary to .astimezone(tz)
when comparing TZ-aware datetime values, because the "real" underlying datetime is not affected by the TZ used for representation. Am I right @jtrh ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I was wrong (see my latest review)
@yaselc please update PR regarding the referenced documentation |
490fc71
to
7c6d1ea
Compare
if isinstance(v, datetime): | ||
tz_utils.validate_dt_tz(v, cls.DATETIME_FIELDS_TZ) | ||
validate_cesion_fecha(v, cls.DATETIME_FIELDS_TZ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inconsistent naming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@glarrain that is the naming convention adopted for the validators of the cesion's fields e.g:
https://github.com/fyntex/lib-cl-sii-python/blob/058bf1704eb5ca403763541c5f731a126a0933c8/cl_sii/rtc/data_models.py#L37
https://github.com/fyntex/lib-cl-sii-python/blob/058bf1704eb5ca403763541c5f731a126a0933c8/cl_sii/rtc/data_models.py#L50
cl_sii/rtc/data_models.py
Outdated
|
||
now_tz_aware = tz_utils.get_now_tz_aware() | ||
|
||
if not (value.date() <= now_tz_aware.date()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not correct because the output of now_tz_aware.date()
depends on the TZ of now_tz_aware
, which has not been set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Let's bring back current_date_in_tz = tz_utils.get_now_tz_aware().astimezone(tz)
.
if isinstance(v, datetime): | ||
tz_utils.validate_dt_tz(v, cls.DATETIME_FIELDS_TZ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to nesting tz_utils.validate_dt_tz()
into validate_cesion_fecha()
?
cl_sii/rtc/data_models.py
Outdated
|
||
if not (value.date() <= now_tz_aware.date()): | ||
raise ValueError( | ||
'Value of "fecha_cesion_dt" must be before or equal to the current day.', value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value of "current day" depends on the timezone
cesion_value: date, dte_value: date | ||
) -> None: | ||
""" | ||
Validate 'fecha_ultimo_vencimiento' of the "cesión" is after or equal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any documentation for this rule?
cl_sii/rtc/data_models.py
Outdated
@@ -321,6 +351,9 @@ class CesionL0: | |||
- Same timestamp as the "Registro AoR DTE" event ``DTE Cedido``. | |||
- The above statements were empirically verified for | |||
``CesionNaturalKey(dte_key=DteNaturalKey(Rut('99***140-4'), 33, 3105), seq=2)``. | |||
- When receiving an XML AEC document, the SII validates this date is before or | |||
equal to the current day. | |||
Source: (https://www.sii.cl/factura_electronica/ins_tecnico.pdf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reference a permalink please, and indicate exactly where in that document the rule is (and perhaps even quote some text, if possible)
Also, please update the PR description and all the commits messages so we have stable references (SII's hosted static files can not be trusted) |
Also, since this PR involves a critical part of validation, please run it against many many many real cases (you will need to code something for that I suppose). I'd also like to know the difference (timedelta) between What if we add a warning (for more than X seconds of difference) instead of the "validation" that we are removing? @jtrh your thoughts on this please |
I would keep the validation of |
cl_sii/rtc/data_models.py
Outdated
|
||
if not (value.date() <= now_tz_aware.date()): | ||
raise ValueError( | ||
'Value of "fecha_cesion_dt" must be before or equal to the current day.', value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the value of fecha_cesion_dt
(value
), I would include the value of current day in the exception message so that it's clear to the user which date was used for the comparison, which is especially useful when debugging time zone--related issues.
Also, I would do the above change in a separate pull request. The other validations are nice-to-haves, but I think we should prioritize this one so we can speed up the fix of https://github.com/fyntex/fd-cl-data/issues/671. |
7c6d1ea
to
e0b1809
Compare
LGTM. @jtrh your call. |
@jtrh I moved this specific validation to PR #208, with an analysis of a representative set of AEC, because I still have doubts about it. |
f132946
to
656b66e
Compare
CC: @jtrobles-cdd |
Is this PR ready for a new review? |
The 'cedente_rut' should be the DTE's 'emisor_rut' or the last 'cesionario_rut' when the sequence is greater than 2 Condition sourced from document "Instructivo Técnico Registro Público Electrónico de Transferencia de Crédito" Source: (https://github.com/cl-sii-extraoficial/archivos-oficiales/blob/master/src/docs/rtc/2013-02-11-instructivo-tecnico.pdf)
…th dte Validate 'fecha_ultimo_vencimiento' of the "cesión" is after or equal to 'fecha_emision' of the DTE. Source: (https://github.com/cl-sii-extraoficial/archivos-oficiales/blob/master/src/docs/rtc/2013-02-11-instructivo-tecnico.pdf)
656b66e
to
b1ca3c7
Compare
Codecov Report
@@ Coverage Diff @@
## develop #199 +/- ##
===========================================
+ Coverage 81.02% 81.16% +0.13%
===========================================
Files 32 32
Lines 2525 2565 +40
Branches 375 384 +9
===========================================
+ Hits 2046 2082 +36
+ Misses 306 305 -1
- Partials 173 178 +5
Continue to review full report at Codecov.
|
It's now... thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking into account what @ycouce-cdd and me discussed yesterday (2021-05-24), are there any validations that should be removed because they conflict with the SII's de facto rules?
It took me a long time to answer, sorry for that, but practice showed us that one thing is what the rules say and another is how they are applied. Obviously, it is not wise to implement validations that probably the SII's own system doesn't apply, it would only make sense if we wanted to generate our own AECs, but I would not use it to restrict the ones we accept. |
Add new validators to
rtc.data_models
described in the document "Instructivo Técnico Registro Público Electrónico de Transferencia de Crédito" (retrieved on 2021-03-03)Source: Instructivo Técnico Registro Público Electrónico de Transferencia de Crédito
rtc.data_models_aec
: Thecedente_rut
should be the DTE'semisor_rut
or the lastcesionario_rut
when the sequence is greater than 1rtc.data_models
: Thefecha_cesion_dt
should be before or equal to the current dayrtc.data_models
: Thefecha_ultimo_vencimiento
should be after or equal to thefecha_emision
of the DTE