Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coopdevs OCB mirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coopdevs
Odoo
Coopdevs OCB mirror
Commits
0f0402a8
Commit
0f0402a8
authored
3 years ago
by
Christopher Ormaza
Browse files
Options
Downloads
Patches
Plain Diff
[FIX] base_vat: Use original version of stdnum for ecuadorian context
Part-of: odoo/odoo#76771
parent
0a07ddbc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
addons/base_vat/models/res_partner.py
+10
-52
10 additions, 52 deletions
addons/base_vat/models/res_partner.py
with
10 additions
and
52 deletions
addons/base_vat/models/res_partner.py
+
10
−
52
View file @
0f0402a8
...
...
@@ -262,60 +262,18 @@ class ResPartner(models.Model):
return
check
==
int
(
num
[
8
])
return
False
def
_checksum_ci_ec
(
self
,
number
):
"""
Calculate a checksum over the number.
"""
fold
=
lambda
x
:
x
-
9
if
x
>
9
else
x
return
sum
(
fold
((
2
,
1
)[
i
%
2
]
*
int
(
n
))
for
i
,
n
in
enumerate
(
number
))
%
10
def
_checksum_ruc_ec
(
self
,
number
,
weights
):
"""
Calculate a checksum over the number given the weights.
"""
return
sum
(
w
*
int
(
n
)
for
w
,
n
in
zip
(
weights
,
number
))
%
11
def
is_valid_ci_ec
(
self
,
vat
):
"""
Check if the number provided is a valid CI number. This checks the
length, formatting and check digit.
"""
if
len
(
vat
)
!=
10
:
return
False
if
not
vat
.
isdecimal
():
return
False
if
(
vat
[:
2
]
<
'
01
'
or
vat
[:
2
]
>
'
24
'
)
and
(
vat
[:
2
]
not
in
(
'
30
'
,
'
50
'
)):
return
False
if
vat
[
2
]
>
'
6
'
:
return
False
if
self
.
_checksum_ci_ec
(
vat
)
!=
0
:
return
False
return
True
def
is_valid_ruc_ec
(
self
,
vat
):
"""
Check if the number provided is a valid RUC number. This checks the
length, formatting, check digit and check sum.
"""
if
len
(
vat
)
!=
13
:
return
False
if
not
vat
.
isdecimal
():
return
False
if
(
vat
[:
2
]
<
'
01
'
or
vat
[:
2
]
>
'
24
'
)
and
(
vat
[:
2
]
not
in
(
'
30
'
,
'
50
'
)):
return
False
if
vat
[
2
]
<=
'
5
'
:
# 0..5 = natural RUC: CI plus establishment number
if
vat
[
-
3
:]
==
'
000
'
:
return
False
return
self
.
is_valid_ci_ec
(
vat
[:
10
])
elif
vat
[
2
]
==
'
6
'
:
# 6 = public RUC
#if vat[-4:] == '0000':
# return False
if
self
.
_checksum_ruc_ec
(
vat
[:
9
],
(
3
,
2
,
7
,
6
,
5
,
4
,
3
,
2
,
1
))
!=
0
:
return
False
elif
vat
[
2
]
==
'
9
'
:
# 9 = juridical RUC
if
vat
[
-
3
:]
==
'
000
'
:
return
False
if
self
.
_checksum_ruc_ec
(
vat
[:
10
],
(
4
,
3
,
2
,
7
,
6
,
5
,
4
,
3
,
2
,
1
))
!=
0
:
return
False
else
:
return
False
return
True
ci
=
stdnum
.
util
.
get_cc_module
(
"
ec
"
,
"
ci
"
)
ruc
=
stdnum
.
util
.
get_cc_module
(
"
ec
"
,
"
ruc
"
)
if
len
(
vat
)
==
10
:
return
ci
.
is_valid
(
vat
)
elif
len
(
vat
)
==
13
:
if
vat
[
2
]
==
"
6
"
and
ci
.
is_valid
(
vat
[:
10
]):
return
True
else
:
return
ruc
.
is_valid
(
vat
)
return
False
def
check_vat_ec
(
self
,
vat
):
vat
=
clean
(
vat
,
'
-.
'
).
upper
().
strip
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment