diff --git a/services/operation_services.py b/services/operation_services.py index 628b4c9de30b9337c23ca748d8dbae8d13d09cbc..d1d9b08ad0304fe233ee37139031fbfb1ee2e045 100644 --- a/services/operation_services.py +++ b/services/operation_services.py @@ -161,8 +161,10 @@ class OperationsService(Component): dans laquelle l'utilisateur ou sa société sont engagés """ operation = self.env["acc.operation"].browse(_id) - role = self._get_role(operation) + base_url = self.env['ir.config_parameter'].sudo().get_param( + 'web.base.url') + if not role.get("isIn"): return AccessError() @@ -175,21 +177,20 @@ class OperationsService(Component): } if type == "invoice": # 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)] ) - - datas["documents"] = [] - for n in acc_account_ids: - val = { + datas["documents"] = acc_account_ids.mapped(lambda n: + { "id": n.id, "name": n.name, "date": n.date, "start_date": n.start_date, "end_date": n.end_date, "amount_total": n.amount_total, + "url": base_url + n.get_portal_url(report_type="pdf"), } - datas["documents"].append(val) + ) else: # Récupération de toutes les factures liées à l'opération spécifiée domain = [("acc_operation_id", "=", _id)] @@ -201,70 +202,21 @@ class OperationsService(Component): domain += [("type", "=", "vente")] if role.get("isPmo"): 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: - acc_contract_ids = self.env["acc.contract"].search(domain) - - datas["contracts"] = [] - for n in acc_contract_ids: - val = { - "id": n.id, - "name": n.name, - "start_date": n.start_date, - "end_date": n.end_date, - "type": n.type, - # "seller": n.seller_id.name, - # "buyer": n.buyer_id.name, + acc_contract_ids = self.env["acc.contract"].sudo().search(domain) + + datas["contracts"] = acc_contract_ids.mapped(lambda n: { + "id": n.id, + "name": n.name, + "start_date": n.start_date, + "end_date": n.end_date, + "type": n.type, + "url": base_url + n.get_portal_url(), } - datas["contracts"].append(val) - + ) return datas - @restapi.method( - [(["/<int:id>/invoice"], "POST")], - cors="*", - crsf=False, - ) - def my_invoice_detail(self, _id, **kw): - 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( [(["/<int:id>/pmo"], "POST")], input_param=restapi.CerberusValidator("_validator_get_pmo"), @@ -683,6 +635,7 @@ class OperationsService(Component): "start_date": {"type": "date", "nullable": True}, "end_date": {"type": "date", "nullable": True}, "amount_total": {"type": "float", "nullable": True}, + "url": {"type": "string", "nullable": True}, }, }, }, @@ -694,6 +647,7 @@ class OperationsService(Component): "id": {"type": "integer"}, "name": {"type": "string"}, "type": {"type": "string", "nullable": True}, + "url": {"type": "string", "nullable": True}, "seller": {"type": "string", "nullable": True}, "buyer": {"type": "string", "nullable": True}, },