Skip to content
Extraits de code Groupes Projets
Valider afff8bfb rédigé par Benjamin - Le Filament's avatar Benjamin - Le Filament
Parcourir les fichiers

[update] contract & invoice download

parent 8fb16637
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -161,8 +161,10 @@ class OperationsService(Component): ...@@ -161,8 +161,10 @@ class OperationsService(Component):
dans laquelle l'utilisateur ou sa société sont engagés dans laquelle l'utilisateur ou sa société sont engagés
""" """
operation = self.env["acc.operation"].browse(_id) operation = self.env["acc.operation"].browse(_id)
role = self._get_role(operation) role = self._get_role(operation)
base_url = self.env['ir.config_parameter'].sudo().get_param(
'web.base.url')
if not role.get("isIn"): if not role.get("isIn"):
return AccessError() return AccessError()
...@@ -175,21 +177,20 @@ class OperationsService(Component): ...@@ -175,21 +177,20 @@ class OperationsService(Component):
} }
if type == "invoice": if type == "invoice":
# Récupération de toutes les factures liées à l'opération spécifiée # Récupération de toutes les factures liées à l'opération spécifiée
acc_account_ids = self.env["acc.account"].search( acc_account_ids = self.env["acc.account"].sudo().search(
[("acc_operation_id", "=", _id)] [("acc_operation_id", "=", _id)]
) )
datas["documents"] = acc_account_ids.mapped(lambda n:
datas["documents"] = [] {
for n in acc_account_ids:
val = {
"id": n.id, "id": n.id,
"name": n.name, "name": n.name,
"date": n.date, "date": n.date,
"start_date": n.start_date, "start_date": n.start_date,
"end_date": n.end_date, "end_date": n.end_date,
"amount_total": n.amount_total, "amount_total": n.amount_total,
"url": base_url + n.get_portal_url(report_type="pdf"),
} }
datas["documents"].append(val) )
else: else:
# Récupération de toutes les factures liées à l'opération spécifiée # Récupération de toutes les factures liées à l'opération spécifiée
domain = [("acc_operation_id", "=", _id)] domain = [("acc_operation_id", "=", _id)]
...@@ -201,69 +202,20 @@ class OperationsService(Component): ...@@ -201,69 +202,20 @@ class OperationsService(Component):
domain += [("type", "=", "vente")] domain += [("type", "=", "vente")]
if role.get("isPmo"): if role.get("isPmo"):
domain_pmo += [("type", "!=", False)] domain_pmo += [("type", "!=", False)]
acc_contract_ids = self.env["acc.contract"].search(domain_pmo) acc_contract_ids = self.env["acc.contract"].sudo().search(domain_pmo)
else: else:
acc_contract_ids = self.env["acc.contract"].search(domain) acc_contract_ids = self.env["acc.contract"].sudo().search(domain)
datas["contracts"] = [] datas["contracts"] = acc_contract_ids.mapped(lambda n: {
for n in acc_contract_ids:
val = {
"id": n.id, "id": n.id,
"name": n.name, "name": n.name,
"start_date": n.start_date, "start_date": n.start_date,
"end_date": n.end_date, "end_date": n.end_date,
"type": n.type, "type": n.type,
# "seller": n.seller_id.name, "url": base_url + n.get_portal_url(),
# "buyer": n.buyer_id.name,
} }
datas["contracts"].append(val)
return datas
@restapi.method(
[(["/<int:id>/invoice"], "POST")],
cors="*",
crsf=False,
) )
def my_invoice_detail(self, _id, **kw): return datas
type = self.request.params.get("type", False)
if type == "invoice":
invoice_id = self.request.params.get("invoice_id", False)
invoice = self.env["acc.account"].browse(invoice_id)
if invoice:
invoice_sudo = invoice.with_user(SUPERUSER_ID).exists()
report_sudo = request.env.ref(
"acc_account.acc_account_invoices"
).with_user(SUPERUSER_ID)
pdf = report_sudo._render_qweb_pdf(
[invoice_sudo.id], data={"report_type": "pdf"}
)[0]
b64_pdf = base64.b64encode(pdf)
reporthttpheaders = [
("Content-Type", "application/pdf"),
("Content-Length", len(pdf)),
]
filename = "Facture.pdf"
reporthttpheaders.append(
("Content-Disposition", content_disposition(filename))
)
return request.make_response(b64_pdf)
else:
contract_id = self.request.params.get("invoice_id", False)
contract = self.env["acc.contract"].browse(contract_id)
if contract:
contract_sudo = contract.with_user(SUPERUSER_ID).exists()
reporthttpheaders = [
("Content-Type", "application/pdf"),
("Content-Length", len(contract_sudo.document)),
]
filename = "Contrat.pdf"
reporthttpheaders.append(
("Content-Disposition", content_disposition(filename))
)
return request.make_response(contract_sudo.document)
@restapi.method( @restapi.method(
[(["/<int:id>/pmo"], "POST")], [(["/<int:id>/pmo"], "POST")],
...@@ -683,6 +635,7 @@ class OperationsService(Component): ...@@ -683,6 +635,7 @@ class OperationsService(Component):
"start_date": {"type": "date", "nullable": True}, "start_date": {"type": "date", "nullable": True},
"end_date": {"type": "date", "nullable": True}, "end_date": {"type": "date", "nullable": True},
"amount_total": {"type": "float", "nullable": True}, "amount_total": {"type": "float", "nullable": True},
"url": {"type": "string", "nullable": True},
}, },
}, },
}, },
...@@ -694,6 +647,7 @@ class OperationsService(Component): ...@@ -694,6 +647,7 @@ class OperationsService(Component):
"id": {"type": "integer"}, "id": {"type": "integer"},
"name": {"type": "string"}, "name": {"type": "string"},
"type": {"type": "string", "nullable": True}, "type": {"type": "string", "nullable": True},
"url": {"type": "string", "nullable": True},
"seller": {"type": "string", "nullable": True}, "seller": {"type": "string", "nullable": True},
"buyer": {"type": "string", "nullable": True}, "buyer": {"type": "string", "nullable": True},
}, },
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter