diff --git a/pms_api_rest/datamodels/pms_account_journal.py b/pms_api_rest/datamodels/pms_account_journal.py index 6c96239bd..76a076b04 100644 --- a/pms_api_rest/datamodels/pms_account_journal.py +++ b/pms_api_rest/datamodels/pms_account_journal.py @@ -3,6 +3,11 @@ from marshmallow import fields from odoo.addons.datamodel.core import Datamodel +class PmsAccountJournalSearchParam(Datamodel): + _name = "pms.account.journal.search.param" + pmsPropertyId = fields.Integer(required=False, allow_none=False) + + class PmsAccountJournalInfo(Datamodel): _name = "pms.account.journal.info" id = fields.Integer(required=False, allow_none=True) diff --git a/pms_api_rest/services/__init__.py b/pms_api_rest/services/__init__.py index 7a0fe8067..6017095d1 100644 --- a/pms_api_rest/services/__init__.py +++ b/pms_api_rest/services/__init__.py @@ -32,5 +32,7 @@ from . import pms_cancelation_rule_service from . import pms_agency_service from . import pms_service_service from . import pms_service_line_service + from . import res_lang_service from . import pms_account_payment_terms_service +from . import pms_account_journal_service diff --git a/pms_api_rest/services/pms_account_journal_service.py b/pms_api_rest/services/pms_account_journal_service.py new file mode 100644 index 000000000..d39215bf6 --- /dev/null +++ b/pms_api_rest/services/pms_account_journal_service.py @@ -0,0 +1,51 @@ +from odoo.addons.base_rest import restapi +from odoo.addons.base_rest_datamodel.restapi import Datamodel +from odoo.addons.component.core import Component + + +class PmsAccountJournalService(Component): + _inherit = "base.rest.service" + _name = "pms.account.journal.service" + _usage = "account-journals" + _collection = "pms.services" + + @restapi.method( + [ + ( + [ + "/", + ], + "GET", + ) + ], + input_param=Datamodel("pms.account.journal.search.param"), + output_param=Datamodel("pms.account.journal.info", is_list=True), + auth="jwt_api_pms", + ) + def get_method_payments(self, account_journal_search_param): + domain = [] + if account_journal_search_param.pmsPropertyId: + domain.extend( + [ + "|", + ( + "pms_property_ids", + "in", + account_journal_search_param.pmsPropertyId, + ), + ("pms_property_ids", "=", False), + ] + ) + PmsAccountJournalInfo = self.env.datamodels["pms.account.journal.info"] + result_account_journals = [] + for account_journal in self.env["account.journal"].search( + domain, + ): + result_account_journals.append( + PmsAccountJournalInfo( + id=account_journal.id, + name=account_journal.name, + allowedPayments=account_journal.allowed_pms_payments, + ) + ) + return result_account_journals diff --git a/pms_api_rest/services/pms_property_service.py b/pms_api_rest/services/pms_property_service.py index d889e3237..8b00af54d 100644 --- a/pms_api_rest/services/pms_property_service.py +++ b/pms_api_rest/services/pms_property_service.py @@ -88,39 +88,6 @@ class PmsPropertyService(Component): return res - @restapi.method( - [ - ( - [ - "//payment-methods", - ], - "GET", - ) - ], - output_param=Datamodel("pms.account.journal.info", is_list=True), - auth="jwt_api_pms", - ) - def get_method_payments_property(self, property_id): - - pms_property = self.env["pms.property"].search([("id", "=", property_id)]) - PmsAccountJournalInfo = self.env.datamodels["pms.account.journal.info"] - res = [] - if not pms_property: - pass - else: - for method in pms_property._get_payment_methods(automatic_included=True): - payment_method = self.env["account.journal"].search( - [("id", "=", method.id)] - ) - res.append( - PmsAccountJournalInfo( - id=payment_method.id, - name=payment_method.name, - allowedPayments=payment_method.allowed_pms_payments, - ) - ) - return res - @restapi.method( [ (