diff --git a/pms_api_rest/datamodels/__init__.py b/pms_api_rest/datamodels/__init__.py index bba5766fd..75bef6942 100644 --- a/pms_api_rest/datamodels/__init__.py +++ b/pms_api_rest/datamodels/__init__.py @@ -53,7 +53,7 @@ from . import pms_account_payment_term from . import pms_room_closure_reason from . import pms_report from . import pms_cash_register -from . import pms_payment_report_input +from . import pms_transaction_report from . import pms_folio_sale_line from . import pms_invoice_line from . import pms_mail diff --git a/pms_api_rest/datamodels/pms_account_payment_term.py b/pms_api_rest/datamodels/pms_account_payment_term.py index 2bfd8d53d..74e15fb1b 100644 --- a/pms_api_rest/datamodels/pms_account_payment_term.py +++ b/pms_api_rest/datamodels/pms_account_payment_term.py @@ -3,7 +3,7 @@ from marshmallow import fields from odoo.addons.datamodel.core import Datamodel -class PmsAccountPaymentTermInfo(Datamodel): - _name = "pms.account.payment.term.info" +class PmsAccountTransactiontTermInfo(Datamodel): + _name = "pms.account.transaction.term.info" id = fields.Integer(required=False, allow_none=True) name = fields.String(required=False, allow_none=True) diff --git a/pms_api_rest/datamodels/pms_mail.py b/pms_api_rest/datamodels/pms_mail.py index d91094f16..211335834 100644 --- a/pms_api_rest/datamodels/pms_mail.py +++ b/pms_api_rest/datamodels/pms_mail.py @@ -9,4 +9,3 @@ class PmsMailInfo(Datamodel): bodyMail = fields.String(required=False, allow_none=True) partnerIds = fields.List(fields.Integer(), required=False) emailAddresses = fields.List(fields.String(), required=False) - pmsPropertyCc = fields.Boolean(required=False, allow_none=True) diff --git a/pms_api_rest/datamodels/pms_transaction.py b/pms_api_rest/datamodels/pms_transaction.py index 28465f816..529548933 100644 --- a/pms_api_rest/datamodels/pms_transaction.py +++ b/pms_api_rest/datamodels/pms_transaction.py @@ -26,6 +26,7 @@ class PmsTransactionsResults(Datamodel): class PmsTransactionInfo(Datamodel): _name = "pms.transaction.info" id = fields.Integer(required=False, allow_none=True) + name = fields.String(required=False, allow_none=True) date = fields.String(required=False, allow_none=True) journalId = fields.Integer(required=False, allow_none=True) amount = fields.Float(required=False, allow_none=True) diff --git a/pms_api_rest/datamodels/pms_payment_report_input.py b/pms_api_rest/datamodels/pms_transaction_report.py similarity index 68% rename from pms_api_rest/datamodels/pms_payment_report_input.py rename to pms_api_rest/datamodels/pms_transaction_report.py index ccc5c0928..fb5d097fa 100644 --- a/pms_api_rest/datamodels/pms_payment_report_input.py +++ b/pms_api_rest/datamodels/pms_transaction_report.py @@ -3,14 +3,14 @@ from marshmallow import fields from odoo.addons.datamodel.core import Datamodel -class PmsPaymentReportSearchParam(Datamodel): - _name = "pms.payment.report.search.param" +class PmsTransactionReportSearchParam(Datamodel): + _name = "pms.transaction.report.search.param" dateFrom = fields.String(required=False, allow_none=True) dateTo = fields.String(required=False, allow_none=True) pmsPropertyId = fields.Integer(required=False, allow_none=True) -class PmsPaymentReportInput(Datamodel): - _name = "pms.payment.report" +class PmsTransactionReportInput(Datamodel): + _name = "pms.transaction.report" fileName = fields.String(required=False, allow_none=True) binary = fields.String(required=False, allow_none=True) diff --git a/pms_api_rest/models/account_payment.py b/pms_api_rest/models/account_payment.py index f6c3be67a..5d5eb8750 100644 --- a/pms_api_rest/models/account_payment.py +++ b/pms_api_rest/models/account_payment.py @@ -15,22 +15,22 @@ class AccountPayment(models.Model): string="PMS API Transaction Type", help="Transaction type for PMS API", compute="_compute_pms_api_transaction_type", - store=True, ) @api.depends("payment_type", "partner_type") def _compute_pms_api_transaction_type(self): for record in self: if record.is_internal_transfer: - return "internal_transfer" - if record.partner_type == "customer": + record.pms_api_transaction_type = "internal_transfer" + elif record.partner_type == "customer": if record.payment_type == "inbound": - return "customer_payment" + record.pms_api_transaction_type = "customer_inbound" else: - return "customer_refund" - if record.partner_type == "supplier": + record.pms_api_transaction_type = "customer_outbound" + elif record.partner_type == "supplier": if record.payment_type == "inbound": - return "supplier_payment" + record.pms_api_transaction_type = "supplier_outbound" else: - return "supplier_refund" - return False + record.pms_api_transaction_type = "supplier_inbound" + else: + record.pms_api_transaction_type = False diff --git a/pms_api_rest/services/__init__.py b/pms_api_rest/services/__init__.py index 371cd165c..cab141501 100644 --- a/pms_api_rest/services/__init__.py +++ b/pms_api_rest/services/__init__.py @@ -35,7 +35,7 @@ from . import pms_service_line_service from . import pms_room_closure_reason_service from . import res_lang_service -from . import pms_account_payment_service +from . import pms_transaction_service from . import pms_account_payment_terms_service from . import pms_account_journal_service from . import pms_invoice_service diff --git a/pms_api_rest/services/pms_account_payment_terms_service.py b/pms_api_rest/services/pms_account_payment_terms_service.py index 14e428108..1589d0014 100644 --- a/pms_api_rest/services/pms_account_payment_terms_service.py +++ b/pms_api_rest/services/pms_account_payment_terms_service.py @@ -18,12 +18,14 @@ class PmsAccountPaymentTermService(Component): "GET", ) ], - output_param=Datamodel("pms.account.payment.term.info", is_list=True), + output_param=Datamodel("pms.account.transaction.term.info", is_list=True), auth="jwt_api_pms", ) def get_account_payment_terms(self): - PmsAccountPaymenttermInfo = self.env.datamodels["pms.account.payment.term.info"] + PmsAccountPaymenttermInfo = self.env.datamodels[ + "pms.account.transaction.term.info" + ] res = [] for payment_term in self.env["account.payment.term"].search([]): res.append( diff --git a/pms_api_rest/services/pms_folio_service.py b/pms_api_rest/services/pms_folio_service.py index 69403a867..277116468 100644 --- a/pms_api_rest/services/pms_folio_service.py +++ b/pms_api_rest/services/pms_folio_service.py @@ -167,7 +167,7 @@ class PmsFolioService(Component): [ ( [ - "//payments", + "//transactions", ], "GET", ) @@ -176,13 +176,13 @@ class PmsFolioService(Component): output_param=Datamodel("pms.transaction.info", is_list=True), auth="jwt_api_pms", ) - def get_folio_payments(self, folio_id, pms_search_param): + def get_folio_transactions(self, folio_id, pms_search_param): domain = list() domain.append(("id", "=", folio_id)) if pms_search_param.pmsPropertyId: domain.append(("pms_property_id", "=", pms_search_param.pmsPropertyId)) folio = self.env["pms.folio"].search(domain) - payments = [] + transactions = [] PmsTransactiontInfo = self.env.datamodels["pms.transaction.info"] if not folio: pass @@ -192,7 +192,8 @@ class PmsFolioService(Component): # else: if folio.payment_ids: for payment in folio.payment_ids: - payments.append( + payment._compute_pms_api_transaction_type() + transactions.append( PmsTransactiontInfo( id=payment.id, amount=round(payment.amount, 2), @@ -200,10 +201,10 @@ class PmsFolioService(Component): date=datetime.combine( payment.date, datetime.min.time() ).isoformat(), - transactionTypeCode=payment.pms_api_transaction_type, + transactionType=payment.pms_api_transaction_type, ) ) - return payments + return transactions @restapi.method( [ diff --git a/pms_api_rest/services/pms_partner_service.py b/pms_api_rest/services/pms_partner_service.py index 44d0c1603..a8460f9b6 100644 --- a/pms_api_rest/services/pms_partner_service.py +++ b/pms_api_rest/services/pms_partner_service.py @@ -233,7 +233,7 @@ class PmsPartnerService(Component): journalId=payment.journal_id.id, date=payment.date.strftime("%d/%m/%Y"), reference=payment.ref, - transactionTypeCode=payment.pms_api_transaction_type, + transactionType=payment.pms_api_transaction_type, ) ) return payments diff --git a/pms_api_rest/services/pms_transaction_service.py b/pms_api_rest/services/pms_transaction_service.py index 2d4cd298c..cd7ca46cc 100644 --- a/pms_api_rest/services/pms_transaction_service.py +++ b/pms_api_rest/services/pms_transaction_service.py @@ -1,10 +1,9 @@ from datetime import datetime -from odoo import _ -from odoo.odoo import fields -from odoo.odoo.exceptions import ValidationError -from odoo.odoo.tools import get_lang +from odoo import _, fields +from odoo.exceptions import ValidationError from odoo.osv import expression +from odoo.tools import get_lang from odoo.addons.base_rest import restapi from odoo.addons.base_rest_datamodel.restapi import Datamodel @@ -95,13 +94,23 @@ class PmsTransactionService(Component): ) amount_result = 0 if group_transactions: - for item in group_transactions: - total_inbound = ( - item["amount"] if item["payment_type"] == "inbound" else 0 - ) - total_outbound = ( - item["amount"] if item["payment_type"] == "outbound" else 0 - ) + total_inbound = next( + ( + item["amount"] + for item in group_transactions + if item["payment_type"] == "inbound" + ), + 0, + ) + total_outbound = next( + ( + item["amount"] + for item in group_transactions + if item["payment_type"] == "outbound" + ), + 0, + ) + amount_result = total_inbound - total_outbound amount_result = total_inbound - total_outbound for transaction in self.env["account.payment"].search( domain, @@ -113,7 +122,7 @@ class PmsTransactionService(Component): PmsTransactiontInfo( id=transaction.id, name=transaction.name if transaction.name else None, - amount=transaction.amount, + amount=round(transaction.amount, 2), journalId=transaction.journal_id.id if transaction.journal_id else None, @@ -128,14 +137,13 @@ class PmsTransactionService(Component): createUid=transaction.create_uid if transaction.create_uid else None, - transactionType=transaction.pms_api_transaction_type, + transactionType=transaction.pms_api_transaction_type or None, ) ) - return PmsTransactionResults( - payments=result_transactions, - total=amount_result, - totalPayments=total_transactions, + transactions=result_transactions, + total=round(amount_result, 2), + totalTransactions=total_transactions, ) @restapi.method( @@ -163,7 +171,7 @@ class PmsTransactionService(Component): partnerName=transaction.partner_id.name if transaction.partner_id else None, reference=transaction.ref if transaction.ref else None, createUid=transaction.create_uid.id if transaction.create_uid else None, - transactionType=transaction.pms_api_transaction_type, + transactionType=transaction.pms_api_transaction_type or None, ) @restapi.method( @@ -352,19 +360,19 @@ class PmsTransactionService(Component): [ ( [ - "/payment-report", + "/transactions-report", ], "GET", ) ], - input_param=Datamodel("pms.payment.report.search.param", is_list=False), - output_param=Datamodel("pms.payment.report", is_list=False), + input_param=Datamodel("pms.transaction.report.search.param", is_list=False), + output_param=Datamodel("pms.transaction.report", is_list=False), auth="jwt_api_pms", ) - def payment_report(self, pms_payment_report_search_param): - pms_property_id = pms_payment_report_search_param.pmsPropertyId - date_from = pms_payment_report_search_param.dateFrom - date_to = pms_payment_report_search_param.dateTo + def transactions_report(self, pms_transaction_report_search_param): + pms_property_id = pms_transaction_report_search_param.pmsPropertyId + date_from = pms_transaction_report_search_param.dateFrom + date_to = pms_transaction_report_search_param.dateTo report_wizard = self.env["cash.daily.report.wizard"].create( { "date_start": date_from, @@ -375,7 +383,7 @@ class PmsTransactionService(Component): result = report_wizard._export() file_name = result["xls_filename"] base64EncodedStr = result["xls_binary"] - PmsResponse = self.env.datamodels["pms.payment.report"] + PmsResponse = self.env.datamodels["pms.transaction.report"] # REVIEW: Reuse pms.report.info by modifying the fields # to support different types of documents? # proposal: contentBase64 = fields.String,