Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BI Som Connexio Api
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
Business Intelligence
Som Connexió
BI Som Connexio Api
Commits
8fcd1ff2
Commit
8fcd1ff2
authored
1 year ago
by
Jordi Isidro Llobet
Browse files
Options
Downloads
Patches
Plain Diff
readaptació a facturació
parent
96afeca4
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/api.py
+74
-68
74 additions, 68 deletions
app/api.py
app/crud.py
+2
-2
2 additions, 2 deletions
app/crud.py
app/models.py
+74
-18
74 additions, 18 deletions
app/models.py
app/schemas.py
+1
-2
1 addition, 2 deletions
app/schemas.py
with
151 additions
and
90 deletions
app/api.py
+
74
−
68
View file @
8fcd1ff2
...
@@ -150,35 +150,37 @@ def read_invoices(
...
@@ -150,35 +150,37 @@ def read_invoices(
,
limit
=
limit
)
,
limit
=
limit
)
return
values
return
values
@app.get
(
"
/invoices_oc_start/
"
,
tags
=
[
"
Data
"
,
"
Invoice
"
])
# @app.get("/invoices_oc_start/", tags=["Data", "Invoice"])
def
invoices_oc_start
(
# def invoices_oc_start(
current_user
:
schemas
.
ApiUser
=
Depends
(
get_current_active_user
),
# current_user: schemas.ApiUser = Depends(get_current_active_user),
db
:
Session
=
Depends
(
get_db
)
# db: Session = Depends(get_db)
):
# ):
values
=
crud
.
start_invoices_oc
(
db
)
# values = crud.start_invoices_oc(db)
return
values
# return values
# Es registra que es volen generar factures per un billing_run_id i es crida a odoo per que registri els valors
@app.post
(
"
/invoices_oc/
"
,
tags
=
[
"
Data
"
,
"
Invoice
"
])
@app.post
(
"
/invoices_oc/
"
,
tags
=
[
"
Data
"
,
"
Invoice
"
])
def
send_invoice_contracts
(
def
send_invoice_contracts
(
contractinvoice
:
schemas
.
ApiContractInvoiceCreate
,
contractinvoice
:
schemas
.
ApiContractInvoiceCreate
,
current_user
:
schemas
.
ApiUser
=
Depends
(
get_current_active_user
),
current_user
:
schemas
.
ApiUser
=
Depends
(
get_current_active_user
),
db
:
Session
=
Depends
(
get_db
)
db
:
Session
=
Depends
(
get_db
)
):
):
values
=
crud
.
get_invoices_oc
(
db
,
contract_codes
=
contractinvoice
.
contracts
,
invoice
=
contractinvoice
.
invoice
)
values
=
crud
.
get_invoices_oc
(
db
,
billing_run_uuid
=
contractinvoice
.
billing_run_uuid
)
return
values
return
values
@app.get
(
"
/invoices_oc_lines/
"
,
tags
=
[
"
Data
"
,
"
Invoice
"
])
#
def
get_invoices_oc_lines
(
# @app.get("/invoices_oc_lines/", tags=["Data", "Invoice"])
invoice
:
str
,
# def get_invoices_oc_lines(
current_user
:
schemas
.
ApiUser
=
Depends
(
get_current_active_user
),
# invoice: str,
db
:
Session
=
Depends
(
get_db
)
# current_user: schemas.ApiUser = Depends(get_current_active_user),
):
# db: Session = Depends(get_db)
values
=
crud
.
get_invoices_oc_lines
(
db
,
invoice
)
# ):
return
values
# values = crud.get_invoices_oc_lines(db, invoice)
# return values
# retorna el fitxer pdf d'una factura
@app.get
(
"
/invoices_oc_pdf/
"
,
tags
=
[
"
Data
"
,
"
Invoice
"
])
@app.get
(
"
/invoices_oc_pdf/
"
,
tags
=
[
"
Data
"
,
"
Invoice
"
])
def
read_invoices_oc_pdf
(
def
read_invoices_oc_pdf
(
invoice
:
str
,
invoice
:
str
,
...
@@ -188,6 +190,10 @@ def read_invoices_oc_pdf(
...
@@ -188,6 +190,10 @@ def read_invoices_oc_pdf(
values
=
crud
.
get_invoices_oc_pdf
(
db
,
invoice
)
values
=
crud
.
get_invoices_oc_pdf
(
db
,
invoice
)
return
values
return
values
# Odoo ho invoca quan s'ha de generar una factura pdf.
# Aquest procés insereix a external.invoice_generator la factura a generar, però el proceś de generació es fa a través d'airflow
# Al acabar el procés d'airflow s'ha de cridar a Odoo informant de la ubicació del pdf
@app.get
(
"
/invoices_oc_generate_pdf/
"
,
tags
=
[
"
Data
"
,
"
Invoice
"
])
@app.get
(
"
/invoices_oc_generate_pdf/
"
,
tags
=
[
"
Data
"
,
"
Invoice
"
])
def
invoice_genrate_pdf
(
def
invoice_genrate_pdf
(
invoice
:
str
,
invoice
:
str
,
...
@@ -216,54 +222,54 @@ def read_invoices_detail(
...
@@ -216,54 +222,54 @@ def read_invoices_detail(
return
values
return
values
#
@app.get
(
"
/opendata/contracts
"
,
tags
=
[
"
Opendata
"
])
#
@app.get("/opendata/contracts", tags=["Opendata"])
def
read_contracts_detail
(
#
def read_contracts_detail(
metric
:
str
,
#
metric: str,
granularity
:
str
=
'
mes
'
,
#
granularity: str = 'mes',
comarca
:
str
=
None
,
#
comarca: str = None,
provincia
:
str
=
None
,
#
provincia: str = None,
ccaa
:
str
=
None
,
#
ccaa: str = None,
poblacio
:
str
=
None
,
#
poblacio: str = None,
codipostal
:
str
=
None
,
#
codipostal: str = None,
geography_level
:
str
=
'
Global
'
,
#
geography_level: str = 'Global',
tecnologia
:
str
=
None
,
#
tecnologia: str = None,
tipus_persona
:
str
=
None
,
#
tipus_persona: str = None,
from_date
:
datetime
.
date
=
None
,
#
from_date: datetime.date = None,
to_date
:
datetime
.
date
=
None
,
#
to_date: datetime.date = None,
skip
:
int
=
0
,
#
skip: int = 0,
limit
:
int
=
None
,
#
limit: int = None,
current_user
:
schemas
.
ApiUser
=
Depends
(
get_current_active_user
),
#
current_user: schemas.ApiUser = Depends(get_current_active_user),
db
:
Session
=
Depends
(
get_db
)
#
db: Session = Depends(get_db)
):
#
):
values
=
crud
.
get_contracts_data
(
db
,
metric
=
metric
,
granularity
=
granularity
,
comarca
=
comarca
,
#
values = crud.get_contracts_data(db, metric=metric, granularity=granularity, comarca=comarca,
provincia
=
provincia
,
ccaa
=
ccaa
,
poblacio
=
poblacio
,
codipostal
=
codipostal
,
#
provincia=provincia, ccaa=ccaa, poblacio=poblacio, codipostal=codipostal,
geography_level
=
geography_level
,
tecnologia
=
tecnologia
,
tipus_persona
=
tipus_persona
,
#
geography_level=geography_level,tecnologia=tecnologia, tipus_persona=tipus_persona,
from_date
=
from_date
,
to_date
=
to_date
,
skip
=
skip
,
limit
=
limit
)
#
from_date=from_date, to_date=to_date, skip=skip, limit=limit)
return
values
#
return values
#
#
#
@app.get
(
"
/opendata/members
"
,
tags
=
[
"
Opendata
"
])
#
@app.get("/opendata/members", tags=["Opendata"])
def
read_members_detail
(
#
def read_members_detail(
metric
:
str
,
#
metric: str,
granularity
:
str
=
'
mes
'
,
#
granularity: str = 'mes',
comarca
:
str
=
None
,
#
comarca: str = None,
provincia
:
str
=
None
,
#
provincia: str = None,
ccaa
:
str
=
None
,
#
ccaa: str = None,
poblacio
:
str
=
None
,
#
poblacio: str = None,
codipostal
:
str
=
None
,
#
codipostal: str = None,
geography_level
:
str
=
'
Global
'
,
#
geography_level: str = 'Global',
tipus_persona
:
str
=
None
,
#
tipus_persona: str = None,
from_date
:
datetime
.
date
=
None
,
#
from_date: datetime.date = None,
to_date
:
datetime
.
date
=
None
,
#
to_date: datetime.date = None,
skip
:
int
=
0
,
#
skip: int = 0,
limit
:
int
=
None
,
#
limit: int = None,
current_user
:
schemas
.
ApiUser
=
Depends
(
get_current_active_user
),
#
current_user: schemas.ApiUser = Depends(get_current_active_user),
db
:
Session
=
Depends
(
get_db
)
#
db: Session = Depends(get_db)
):
#
):
values
=
crud
.
get_members_data
(
db
,
metric
=
metric
,
granularity
=
granularity
,
comarca
=
comarca
,
#
values = crud.get_members_data(db, metric=metric, granularity=granularity, comarca=comarca,
provincia
=
provincia
,
ccaa
=
ccaa
,
poblacio
=
poblacio
,
codipostal
=
codipostal
,
#
provincia=provincia, ccaa=ccaa, poblacio=poblacio, codipostal=codipostal,
geography_level
=
geography_level
,
tipus_persona
=
tipus_persona
,
#
geography_level=geography_level, tipus_persona=tipus_persona,
from_date
=
from_date
,
to_date
=
to_date
,
skip
=
skip
,
limit
=
limit
)
#
from_date=from_date, to_date=to_date, skip=skip, limit=limit)
return
values
#
return values
This diff is collapsed.
Click to expand it.
app/crud.py
+
2
−
2
View file @
8fcd1ff2
...
@@ -64,8 +64,8 @@ def start_invoices_oc(db):
...
@@ -64,8 +64,8 @@ def start_invoices_oc(db):
db
.
commit
()
db
.
commit
()
return
[]
return
[]
def
get_invoices_oc
(
db
,
contract_codes
,
invoice
):
def
get_invoices_oc
(
db
,
billing_run_uuid
):
registries
=
get_invoice_oc
(
db
,
contract_codes
,
invoice
)
registries
=
get_invoice_oc
(
db
,
billing_run_uuid
)
return
registries
return
registries
def
get_invoices_oc_lines
(
db
,
invoice
):
def
get_invoices_oc_lines
(
db
,
invoice
):
...
...
This diff is collapsed.
Click to expand it.
app/models.py
+
74
−
18
View file @
8fcd1ff2
import
ast
import
ast
import
uuid
import
uuid
from
sqlalchemy
import
Boolean
,
Column
,
Integer
,
String
from
sqlalchemy
import
Boolean
,
Column
,
Integer
,
String
import
requests
from
pandas
import
DataFrame
from
.database
import
Base
from
.database
import
Base
...
@@ -15,27 +17,81 @@ class ApiUser(Base):
...
@@ -15,27 +17,81 @@ class ApiUser(Base):
hashed_password
=
Column
(
String
,
nullable
=
False
)
hashed_password
=
Column
(
String
,
nullable
=
False
)
is_active
=
Column
(
Boolean
,
default
=
True
)
is_active
=
Column
(
Boolean
,
default
=
True
)
'''
{
"
groupCode
"
:
"
string
"
, --> group_code
"
invoiceDate
"
: 0, --> CURRENT_DATE?
"
invoiceLines
"
: [
{
"
description
"
:
"
string
"
, --> description_cat
"
accountingCode
"
:
"
string
"
, ???
"
amountWithoutTax
"
: 0, --> preu
"
amountWithTax
"
: 0, --> amount_with_tax
"
amountTax
"
: 0, --> amount_tax
"
taxCode
"
:
"
string
"
, --> tax_code
"
productCode
"
:
"
string
"
, --> code
}
]
}
'''
def
get_invoice_oc
(
con
,
billing_run_uuid
):
def
get_invoice_oc
(
con
,
contract_codes
,
invoice
):
statement
=
"""
fltr_contracts
=
""
select oi.description_cat, oi.code
ccin
=
"'
xx
'"
,sum(oi.amount_without_tax) as preu
for
contract
in
contract_codes
:
,sum(oi.amount_tax) as amount_tax
ccin
+=
"
,
'"
+
str
(
contract
)
+
"'
"
,sum(oi.amount_with_tax) as amount_with_tax
qry
=
"
insert into external.invoicing_contracts values (
'
{}
'
,
'
{}
'
)
"
.
format
(
str
(
contract
),
invoice
)
, oi.tax_percent, ocg.code as group_code, oi.tax_code
con
.
execute
(
qry
)
from external.opencell_invoices oi
con
.
commit
()
join odoo_contract_contract occ on oi.odoo_code = occ.code
ccin
=
ccin
.
replace
(
'
xx,
'
,
''
)
join odoo_contract_group ocg on occ.contract_group_id = ocg.id
fltr_contracts
=
"
and odoo_code in (
"
+
ccin
+
"
)
"
where 1=1
and billing_run_uuid=
'"""
+
billing_run_uuid
+
"'
"
+
\
statement
=
"
select description_cat, code , sum(amount_without_tax) as preu, tax_percent
"
\
"""
group by oi.description_cat, oi.code, oi.tax_percent , oi.billing_run_uuid, ocg.code, oi.tax_code
"
from external.opencell_invoices
"
\
having sum(oi.amount_without_tax)<>0
"""
"
where 1=1
"
+
fltr_contracts
+
"
"
\
"
group by description_cat, code, tax_percent
"
\
# statement = """
"
having sum(amount_without_tax)<>0
"
# select oi.description_cat, oi.code
# ,sum(oi.amount_without_tax) as preu
columns
=
[
'
description_cat
'
,
'
code
'
,
'
preu
'
,
'
tax_percent
'
]
# ,sum(oi.amount_tax) as amount_tax
# ,sum(oi.amount_with_tax) as amount_with_tax
# , oi.tax_percent, substring(msidsn,4,3) as group_code, oi.tax_code
# from external.opencell_invoices oi
# join odoo_contract_contract occ on oi.odoo_code = occ.code
# where 1=1
# and substring(msidsn,4,3) in ('015', '043', '329')
# group by oi.description_cat, oi.code, oi.tax_percent , oi.billing_run_uuid, substring(msidsn,4,3), oi.tax_code
# having sum(oi.amount_without_tax)<>0
# """
columns
=
[
'
description_cat
'
,
'
code
'
,
'
preu
'
,
'
amount_tax
'
,
'
amount_with_tax
'
,
'
tax_percent
'
,
'
group_code
'
,
'
tax_code
'
]
registries
=
con
.
execute
(
statement
)
registries
=
con
.
execute
(
statement
)
df
=
DataFrame
(
registries
.
fetchall
())
df
.
columns
=
registries
.
keys
()
group
=
df
.
groupby
(
by
=
'
group_code
'
)
for
x
in
group
:
data
=
{
"
groupCode
"
:
x
[
0
],
"
invoiceDate
"
:
0
,
"
invoiceLines
"
:
[],
}
df2
=
df
.
loc
[
df
[
'
group_code
'
]
==
x
[
0
]]
for
index
,
row
in
df2
.
iterrows
():
invoiceline
=
{
"
description
"
:
row
[
'
description_cat
'
],
"
amountWithoutTax
"
:
float
(
round
(
row
[
'
preu
'
],
2
)),
"
amountWithTax
"
:
float
(
round
(
row
[
'
amount_with_tax
'
],
2
)),
"
amountTax
"
:
float
(
round
(
row
[
'
amount_tax
'
],
2
)),
"
taxCode
"
:
row
[
'
tax_code
'
],
"
productCode
"
:
row
[
'
code
'
],
}
data
[
"
invoiceLines
"
].
append
(
invoiceline
)
print
(
data
)
# TODO fer la crida a odoo per cada grup_code de billing_run_id
# API_ENDPOINT = "http://pastebin.com/api/api_post.php"
# r = requests.post(url=API_ENDPOINT, data=data)
return
[
dict
(
zip
(
columns
,
t
))
for
t
in
registries
]
return
[
dict
(
zip
(
columns
,
t
))
for
t
in
registries
]
...
...
This diff is collapsed.
Click to expand it.
app/schemas.py
+
1
−
2
View file @
8fcd1ff2
...
@@ -30,5 +30,4 @@ class ApiUser(ApiUserBase):
...
@@ -30,5 +30,4 @@ class ApiUser(ApiUserBase):
class
ApiContractInvoiceCreate
(
BaseModel
):
class
ApiContractInvoiceCreate
(
BaseModel
):
contracts
:
List
[
int
]
billing_run_uuid
:
str
invoice
:
str
\ No newline at end of file
\ No newline at end of file
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