diff --git a/services/auth_services.py b/services/auth_services.py index 9716ec11738cc6fe805e8cebbb7614f8c961ff28..049562b2d8bd514fc5b7c67bf154835031572596 100644 --- a/services/auth_services.py +++ b/services/auth_services.py @@ -276,7 +276,7 @@ class AuthService(Component): return {} @restapi.method( - [(["/my-account"], "GET")], + [(["/mon-compte"], "GET")], input_param=restapi.CerberusValidator("_validator_get_my_account"), output_param=restapi.CerberusValidator("_validator_return_my_account"), cors="*", @@ -284,17 +284,18 @@ class AuthService(Component): ) def get_my_account(self): user_id = self.env["res.users"].browse(self.request.uid) + user = { - "company": user_id.partner_id.parent_id.name, + "company": user_id.partner_id.parent_id.name or "", "name": user_id.name, - "firstname": user_id.firstname, + "firstname": user_id.firstname or "", "lastname": user_id.lastname, "login": user_id.login, } return user @restapi.method( - [(["/my-account"], "POST")], + [(["/mon-compte"], "POST")], input_param=restapi.CerberusValidator("_validator_set_my_account"), output_param=restapi.CerberusValidator("_validator_return_my_account"), cors="*", @@ -311,9 +312,9 @@ class AuthService(Component): } ) user = { - "company": user_id.partner_id.parent_id.name, + "company": user_id.partner_id.parent_id.name or "", "name": user_id.name, - "firstname": user_id.firstname, + "firstname": user_id.firstname or "", "lastname": user_id.lastname, "login": user_id.login, } @@ -411,7 +412,7 @@ class AuthService(Component): "login": {"type": "string"}, "firstname": {"type": "string", "nullable": True}, "lastname": {"type": "string", "nullable": True}, - "name": {"type": "string"}, + "name": {"type": "string", "nullable": True}, "company": {"type": "string", "nullable": True}, } diff --git a/services/operation_services.py b/services/operation_services.py index 86c3e7cb924468276d013cffae17b49e554637e3..490e5e4ef50e9cabde10b459f4dd8a37ee7bce4a 100644 --- a/services/operation_services.py +++ b/services/operation_services.py @@ -1,12 +1,9 @@ # © 2021 Le Filament (<http://www.le-filament.com>) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -import base64 from datetime import datetime -from odoo import SUPERUSER_ID from odoo.exceptions import AccessError -from odoo.http import content_disposition, request from odoo.addons.base_rest import restapi from odoo.addons.component.core import Component @@ -106,6 +103,27 @@ class OperationsService(Component): power_tot = (0, 0) cons_rate = prod_rate = 0 + nb_conso = ( + self.env["acc.counter"] + .sudo() + .search_count( + [ + ("acc_operation_id", "=", operation.id), + ("is_delivery", "=", True), + ] + ) + ) + nb_prod = ( + self.env["acc.counter"] + .sudo() + .search_count( + [ + ("acc_operation_id", "=", operation.id), + ("is_injection", "=", True), + ] + ) + ) + datas = { "role": role, "id": operation.id, @@ -121,8 +139,8 @@ class OperationsService(Component): if operation.distribution_key else None, "pmo": operation.sudo().pmo_id.name, - "consumer_nb": len(operation.sudo().acc_delivery_ids), - "productor_nb": len(operation.sudo().acc_injection_ids), + "consumer_nb": nb_conso, + "productor_nb": nb_prod, "power_install": power_install, "image": operation.image_256.decode("utf-8") if operation.image_256 @@ -162,13 +180,12 @@ 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() - type = self.request.params.get("type", False) + self.request.params.get("type", False) datas = { "role": role, @@ -192,29 +209,46 @@ 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"): - domain += [("type", "=", "achat")] - if role.get("isProductor"): - domain += [("type", "=", "vente")] + if role.get("isConsumer") or role.get("isProductor"): + domain += [("type", "=", "vente_achat")] 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(), + 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 [] } - ) if acc_contract_ids else [] + ) return datas @restapi.method( @@ -625,6 +659,7 @@ class OperationsService(Component): "id": {"type": "integer"}, "name": {"type": "string"}, "documents": { + "nullable": True, "type": "list", "schema": { "type": "dict", @@ -640,6 +675,7 @@ class OperationsService(Component): }, }, "contracts": { + "nullable": True, "type": "list", "schema": { "type": "dict",