mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms_api_rest: add account_journals service and remove get_payment_methods in properties service
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
51
pms_api_rest/services/pms_account_journal_service.py
Normal file
51
pms_api_rest/services/pms_account_journal_service.py
Normal file
@@ -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
|
||||
@@ -88,39 +88,6 @@ class PmsPropertyService(Component):
|
||||
|
||||
return res
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:property_id>/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(
|
||||
[
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user