diff --git a/services/operation_services.py b/services/operation_services.py index 490e5e4ef50e9cabde10b459f4dd8a37ee7bce4a..07ed716400c773b80b26fbf82df501fc39cc1f1c 100644 --- a/services/operation_services.py +++ b/services/operation_services.py @@ -180,12 +180,13 @@ class OperationsService(Component): """ 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") + base_url = self.env['ir.config_parameter'].sudo().get_param( + 'web.base.url') if not role.get("isIn"): return AccessError() - self.request.params.get("type", False) + type = self.request.params.get("type", False) datas = { "role": role, @@ -209,46 +210,29 @@ class OperationsService(Component): } ) if acc_account_ids else [] else: - # Récupération de toutes les factures liées à l'opération spécifiée - acc_account_ids = self.env["acc.account"].search( - [("acc_operation_id", "=", _id)] - ) - 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"), - } - ) - # Récupération de toutes les factures liées à l'opération spécifiée domain = [("acc_operation_id", "=", _id)] domain_pmo = [("acc_operation_id", "=", _id)] role = self._get_role(operation) - if role.get("isConsumer") or role.get("isProductor"): - domain += [("type", "=", "vente_achat")] + if role.get("isConsumer"): + domain += [("type", "=", "achat")] + if role.get("isProductor"): + domain += [("type", "=", "vente")] if role.get("isPmo"): domain_pmo += [("type", "!=", False)] acc_contract_ids = self.env["acc.contract"].sudo().search(domain_pmo) else: 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(), - } - ) if acc_contract_ids else [] + 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(), } - ) + ) if acc_contract_ids else [] return datas @restapi.method(