diff --git a/.github.dev/workflows/test.yml b/.github.dev/workflows/test.yml new file mode 100644 index 00000000..378b490d --- /dev/null +++ b/.github.dev/workflows/test.yml @@ -0,0 +1,52 @@ +name: Tests + +on: + pull_request: + branches: + - "16.0*" + push: + branches: + - "16.0" + +jobs: + test: + runs-on: ubuntu-22.04 + container: ghcr.io/oca/oca-ci/py3.10-odoo16.0:latest + + services: + postgres: + image: postgres:12.0 + env: + POSTGRES_USER: odoo + POSTGRES_PASSWORD: odoo + POSTGRES_DB: odoo + ports: + - 5432:5432 + + env: + EXCLUDE: "connector_pms_wubook" # Module with broken tests. To be refactored. + + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Install custom dependencies + run: pip install -r modules_requirements.txt + - name: Install addons and dependencies + run: oca_install_addons + + - name: Initialize test db + run: oca_init_test_database + + - name: Run tests + run: oca_run_tests + + - name: Coverage summary + run: | + echo "## 📊 Coverage Report" >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + coverage report >> $GITHUB_STEP_SUMMARY + echo '```' >> $GITHUB_STEP_SUMMARY + echo "" >> $GITHUB_STEP_SUMMARY + echo "**Total:** $(coverage report | tail -1 | awk '{print $NF}')" >> $GITHUB_STEP_SUMMARY diff --git a/pms_api_rest/services/pms_partner_service.py b/pms_api_rest/services/pms_partner_service.py index 2e0154f3..7441360d 100644 --- a/pms_api_rest/services/pms_partner_service.py +++ b/pms_api_rest/services/pms_partner_service.py @@ -754,6 +754,7 @@ def check_document_number(self, document_number, document_type_id, country_id): { "name": document_number, "category_id": document_type, + "country_id": country, } ) ) diff --git a/pms_api_rest/services/pms_reservation_service.py b/pms_api_rest/services/pms_reservation_service.py index b05db661..5b7c3a6d 100644 --- a/pms_api_rest/services/pms_reservation_service.py +++ b/pms_api_rest/services/pms_reservation_service.py @@ -838,10 +838,6 @@ def write_reservation_checkin_partner( pms_checkin_partner_info.relationship ) - # if not partner_id we need to force compute to create partner - if not checkin_partner.partner_id: - checkin_partner._compute_partner_id() - return checkin_partner.id @restapi.method( @@ -1082,9 +1078,6 @@ def create_reservation_checkin_partner( else False, ) ) - # if not partner_id we need to force compute to create partner - if not checkin_partner_last.partner_id: - checkin_partner_last._compute_partner_id() return checkin_partner_last.id else: raise MissingError( diff --git a/pms_fastapi/__init__.py b/pms_fastapi/__init__.py index 817912b3..d9c52042 100644 --- a/pms_fastapi/__init__.py +++ b/pms_fastapi/__init__.py @@ -1,3 +1,3 @@ -from . import models from . import schemas from . import routers +from . import models diff --git a/pms_fastapi/models/res_partner.py b/pms_fastapi/models/res_partner.py index e3ed0faa..9911a715 100644 --- a/pms_fastapi/models/res_partner.py +++ b/pms_fastapi/models/res_partner.py @@ -100,3 +100,20 @@ def _phone_get_number_fields(self): """This method returns the fields to use to find the number to use to send an SMS on a record.""" return ["mobile", "phone"] + + def set_fiscal_document_data( + self, fiscal_id_number=False, fiscal_id_number_type=False + ): + """ + Set the fiscal document data for the partner if the type is vat, + Otherwise will be set by other module. + The function can receive only one of the two parameters, in that case + the other parameter will be taken from the partner record. + """ + if not fiscal_id_number and not fiscal_id_number_type: + return + if not fiscal_id_number: + fiscal_id_number = self.vat + if not fiscal_id_number_type: + fiscal_id_number_type = "vat" + self.write({"vat": fiscal_id_number}) diff --git a/pms_fastapi/routers/contact.py b/pms_fastapi/routers/contact.py index d5272e44..85651ac3 100644 --- a/pms_fastapi/routers/contact.py +++ b/pms_fastapi/routers/contact.py @@ -183,8 +183,17 @@ def _prepare_write_res_partner_vals( def create_contact(self, data: ContactInsert): vals = self._prepare_create_res_partner_vals(data) - return self.env["res.partner"].sudo().create(vals) + res = self.env["res.partner"].sudo().create(vals) + if data.fiscalIdNumberType or data.fiscalIdNumber: + res.set_fiscal_document_data(data.fiscalIdNumber, data.fiscalIdNumberType) + return res def update_contact(self, data: ContactUpdate, contact_id: int): vals = self._prepare_write_res_partner_vals(data) - return self.env["res.partner"].sudo().browse(contact_id).write(vals) + partner = self.env["res.partner"].sudo().browse(contact_id) + res = partner.write(vals) + if data.fiscalIdNumberType or data.fiscalIdNumber: + partner.set_fiscal_document_data( + data.fiscalIdNumber, data.fiscalIdNumberType + ) + return res diff --git a/pms_fastapi/schemas/guest.py b/pms_fastapi/schemas/guest.py index b212b850..6be7c52c 100644 --- a/pms_fastapi/schemas/guest.py +++ b/pms_fastapi/schemas/guest.py @@ -46,7 +46,7 @@ def from_res_partner(cls, partner): class GuestSearch(BaseSearch): def __init__( self, - pmsProperty: int | None = Query( + pmsPropertyId: int | None = Query( default=None, description="Filter guests of the given property.", ), @@ -102,10 +102,10 @@ def __init__( ), ] = None, ): - if not isinstance(pmsProperty, QueryType): - self.pmsProperty = pmsProperty + if not isinstance(pmsPropertyId, QueryType): + self.pmsPropertyId = pmsPropertyId else: - self.pmsProperty = None + self.pmsPropertyId = None if not isinstance(globalSearch, QueryType): self.globalSearch = globalSearch else: @@ -153,9 +153,9 @@ def __init__( def to_odoo_domain(self, env: api.Environment) -> list: domain = [] - if self.pmsProperty: + if self.pmsPropertyId: domain += [ - ("pms_checkin_partner_ids.pms_property_id", "=", self.pmsProperty) + ("pms_checkin_partner_ids.pms_property_id", "=", self.pmsPropertyId) ] else: domain += [ @@ -225,7 +225,7 @@ def to_odoo_domain(self, env: api.Environment) -> list: return domain def to_odoo_context(self, env: api.Environment) -> dict: - if self.pmsProperty: - return {"pms_property_ids": [self.pmsProperty]} + if self.pmsPropertyId: + return {"pms_property_ids": [self.pmsPropertyId]} else: return {"pms_property_ids": env.user.pms_property_ids.ids} diff --git a/pms_fastapi/schemas/pms_property.py b/pms_fastapi/schemas/pms_property.py index eb1ec351..d77ffbda 100644 --- a/pms_fastapi/schemas/pms_property.py +++ b/pms_fastapi/schemas/pms_property.py @@ -25,6 +25,7 @@ def from_pms_property(cls, pms_property): class PropertySummary(PropertyId): image: AnyHttpUrl | None = None currency: CurrencySummary + timezone: str | None = None @classmethod def from_pms_property(cls, pms_property): @@ -40,4 +41,6 @@ def from_pms_property(cls, pms_property): ) if image_url: data["image"] = image_url + if pms_property.tz: + data["timezone"] = pms_property.tz return cls(**data) diff --git a/pms_fastapi/tests/common.py b/pms_fastapi/tests/common.py index 2b7c796b..22fca72b 100644 --- a/pms_fastapi/tests/common.py +++ b/pms_fastapi/tests/common.py @@ -8,7 +8,7 @@ from odoo.addons.fastapi.dependencies import fastapi_endpoint -class CommonTestRoomdooApi(FastAPITransactionCase): +class CommonTestPmsApi(FastAPITransactionCase): @classmethod def setUpClass(cls) -> None: super().setUpClass() @@ -49,6 +49,7 @@ def setUpClass(cls) -> None: cls.test_company = cls.env["res.company"].create( { "name": "Company 1", + "vat": "ES11111111H", } ) cls.test_property = cls.env["pms.property"].create( diff --git a/pms_fastapi/tests/test_agencies.py b/pms_fastapi/tests/test_agencies.py index 0066a7c0..4846f503 100644 --- a/pms_fastapi/tests/test_agencies.py +++ b/pms_fastapi/tests/test_agencies.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class TestAgenciesEndpoints(CommonTestRoomdooApi): +class TestAgenciesEndpoints(CommonTestPmsApi): def test_agencies_get(self): with self._create_test_client() as test_client: response = self._login(test_client) diff --git a/pms_fastapi/tests/test_contact_id_numbers.py b/pms_fastapi/tests/test_contact_id_numbers.py index 52635777..9431d211 100644 --- a/pms_fastapi/tests/test_contact_id_numbers.py +++ b/pms_fastapi/tests/test_contact_id_numbers.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class TestContactIdNumberEndpoints(CommonTestRoomdooApi): +class TestContactIdNumberEndpoints(CommonTestPmsApi): @classmethod def setUpClass(cls) -> None: super().setUpClass() diff --git a/pms_fastapi/tests/test_contacts.py b/pms_fastapi/tests/test_contacts.py index a92ae575..04e8fc1d 100644 --- a/pms_fastapi/tests/test_contacts.py +++ b/pms_fastapi/tests/test_contacts.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class TestContactsEndpoints(CommonTestRoomdooApi): +class TestContactsEndpoints(CommonTestPmsApi): @classmethod def setUpClass(cls) -> None: super().setUpClass() diff --git a/pms_fastapi/tests/test_countries.py b/pms_fastapi/tests/test_countries.py index 1c214002..e8a9818c 100644 --- a/pms_fastapi/tests/test_countries.py +++ b/pms_fastapi/tests/test_countries.py @@ -1,11 +1,11 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi from ..schemas.country import CountrySummary -class TestCountriesEndpoints(CommonTestRoomdooApi): +class TestCountriesEndpoints(CommonTestPmsApi): def test_countries_get(self): with self._create_test_client() as test_client: response = self._login(test_client) diff --git a/pms_fastapi/tests/test_customers.py b/pms_fastapi/tests/test_customers.py index b76bd6a2..705d1114 100644 --- a/pms_fastapi/tests/test_customers.py +++ b/pms_fastapi/tests/test_customers.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class TestCustomersEndpoints(CommonTestRoomdooApi): +class TestCustomersEndpoints(CommonTestPmsApi): def test_customers_get(self): with self._create_test_client() as test_client: response = self._login(test_client) diff --git a/pms_fastapi/tests/test_guests.py b/pms_fastapi/tests/test_guests.py index 31201471..4177361a 100644 --- a/pms_fastapi/tests/test_guests.py +++ b/pms_fastapi/tests/test_guests.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class TestGuestsEndpoints(CommonTestRoomdooApi): +class TestGuestsEndpoints(CommonTestPmsApi): def test_guests_get(self): with self._create_test_client() as test_client: response = self._login(test_client) diff --git a/pms_fastapi/tests/test_languages.py b/pms_fastapi/tests/test_languages.py index 1bc6a1ec..13cea9e6 100644 --- a/pms_fastapi/tests/test_languages.py +++ b/pms_fastapi/tests/test_languages.py @@ -1,11 +1,11 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi from ..schemas.language import Language -class TestLanguagesEndpoints(CommonTestRoomdooApi): +class TestLanguagesEndpoints(CommonTestPmsApi): def test_languages_get(self): with self._create_test_client() as test_client: response = self._login(test_client) diff --git a/pms_fastapi/tests/test_properties.py b/pms_fastapi/tests/test_properties.py index 61cbd96a..119bb9c3 100644 --- a/pms_fastapi/tests/test_properties.py +++ b/pms_fastapi/tests/test_properties.py @@ -1,11 +1,11 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi from ..schemas.pms_property import PropertySummary -class TestPropertiesEndpoints(CommonTestRoomdooApi): +class TestPropertiesEndpoints(CommonTestPmsApi): def test_properties_get(self): with self._create_test_client() as test_client: response = self._login(test_client) diff --git a/pms_fastapi/tests/test_suppliers.py b/pms_fastapi/tests/test_suppliers.py index c8e22a07..e920d996 100644 --- a/pms_fastapi/tests/test_suppliers.py +++ b/pms_fastapi/tests/test_suppliers.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class TestsuppliersEndpoints(CommonTestRoomdooApi): +class TestsuppliersEndpoints(CommonTestPmsApi): def test_suppliers_get(self): with self._create_test_client() as test_client: response = self._login(test_client) diff --git a/pms_fastapi/tests/test_user.py b/pms_fastapi/tests/test_user.py index 4605bc39..19857b86 100644 --- a/pms_fastapi/tests/test_user.py +++ b/pms_fastapi/tests/test_user.py @@ -2,14 +2,14 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi from ..schemas.user import User dir_path = os.path.dirname(os.path.realpath(__file__)) -class TestUserEndpoints(CommonTestRoomdooApi): +class TestUserEndpoints(CommonTestPmsApi): def test_user_get(self): with self._create_test_client() as test_client: response = self._login(test_client) diff --git a/pms_fastapi_contact_lastname2/tests/test_contacts.py b/pms_fastapi_contact_lastname2/tests/test_contacts.py index 95c77a48..1825762a 100644 --- a/pms_fastapi_contact_lastname2/tests/test_contacts.py +++ b/pms_fastapi_contact_lastname2/tests/test_contacts.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class TestContactsEndpoints(CommonTestRoomdooApi): +class TestContactsEndpoints(CommonTestPmsApi): @classmethod def setUpClass(cls) -> None: super().setUpClass() diff --git a/pms_fastapi_contact_lastname2/tests/test_user.py b/pms_fastapi_contact_lastname2/tests/test_user.py index 7d7b69f7..5f7517a9 100644 --- a/pms_fastapi_contact_lastname2/tests/test_user.py +++ b/pms_fastapi_contact_lastname2/tests/test_user.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class TestUserEndpoints(CommonTestRoomdooApi): +class TestUserEndpoints(CommonTestPmsApi): def test_user_get(self): with self._create_test_client() as test_client: response = self._login(test_client) diff --git a/pms_fastapi_l10n_es/__init__.py b/pms_fastapi_l10n_es/__init__.py index 629a7fe1..d9c52042 100644 --- a/pms_fastapi_l10n_es/__init__.py +++ b/pms_fastapi_l10n_es/__init__.py @@ -1,2 +1,3 @@ from . import schemas from . import routers +from . import models diff --git a/pms_fastapi_l10n_es/models/__init__.py b/pms_fastapi_l10n_es/models/__init__.py new file mode 100644 index 00000000..91fed54d --- /dev/null +++ b/pms_fastapi_l10n_es/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/pms_fastapi_l10n_es/models/res_partner.py b/pms_fastapi_l10n_es/models/res_partner.py new file mode 100644 index 00000000..1dde24f3 --- /dev/null +++ b/pms_fastapi_l10n_es/models/res_partner.py @@ -0,0 +1,48 @@ +from odoo import models + +from odoo.addons.l10n_es_aeat_partner_identification.models.res_partner import ( + AEAT_TYPES_ID_CATEGORY_MAP, +) + + +class ResPartner(models.Model): + _inherit = "res.partner" + + def set_fiscal_document_data( + self, fiscal_id_number=False, fiscal_id_number_type=False + ): + if not fiscal_id_number and not fiscal_id_number_type: + return + if not fiscal_id_number: + if self.vat: + fiscal_id_number = self.vat + else: + fiscal_id_number = self.aeat_identification + if not fiscal_id_number_type and self.vat: + fiscal_id_number_type = "vat" + elif not fiscal_id_number_type and self.aeat_identification: + fiscal_id_number_type = AEAT_TYPES_ID_CATEGORY_MAP[ + self.aeat_identification_type + ] + if fiscal_id_number_type not in AEAT_TYPES_ID_CATEGORY_MAP.values(): + self.write( + { + "aeat_identification_type": False, + "aeat_identification": False, + } + ) + return super().set_fiscal_document_data( + fiscal_id_number, fiscal_id_number_type + ) + odoo_fiscal_type = [ + key + for key, value in AEAT_TYPES_ID_CATEGORY_MAP.items() + if value == fiscal_id_number_type + ] + self.write( + { + "vat": False, + "aeat_identification_type": odoo_fiscal_type[0], + "aeat_identification": fiscal_id_number, + } + ) diff --git a/pms_fastapi_l10n_es/routers/contact.py b/pms_fastapi_l10n_es/routers/contact.py index dc5326fb..f531577d 100644 --- a/pms_fastapi_l10n_es/routers/contact.py +++ b/pms_fastapi_l10n_es/routers/contact.py @@ -1,64 +1,9 @@ -from fastapi import HTTPException - from odoo import api, models -from odoo.addons.l10n_es_aeat_partner_identification.models.res_partner import ( - AEAT_TYPES_ID_CATEGORY_MAP, -) -from odoo.addons.pms_fastapi.schemas.contact import ( - ContactInsert, - ContactUpdate, -) - class PmsApiContactRouterHelper(models.AbstractModel): _inherit = "pms_api_contact.contact_router.helper" - def create_contact(self, data: ContactInsert): - res = super().create_contact(data) - if data.fiscalIdNumberType: - if data.fiscalIdNumberType != "vat": - res["aeat_identification_type"] = data.fiscalIdNumberType - res["aeat_identification"] = data.fiscalIdNumber - else: - res["vat"] = data.fiscalIdNumber - return res - - def update_contact(self, data: ContactUpdate, contact_id: int): - res = super().update_contact(data, contact_id) - partner = self.env["res.partner"].browse(contact_id) - if data.fiscalIdNumber: - if ( - data.fiscalIdNumberType - and data.fiscalIdNumberType != "vat" - or not data.fiscalIdNumberType - and partner.aeat_identification_type - ): - partner.aeat_identification = data.fiscalIdNumber - partner.vat = False - else: - partner.vat = data.fiscalIdNumber - partner.aeat_identification = False - if data.fiscalIdNumberType: - if data.fiscalIdNumberType != "vat": - odoo_fiscal_type = [ - key - for key, value in AEAT_TYPES_ID_CATEGORY_MAP.items() - if value == data.fiscalIdNumberType - ] - if not odoo_fiscal_type: - raise HTTPException( - status_code=404, - detail=f"fiscalIdNumberType not \ - found {data.fiscalIdNumberType}", - ) - partner.aeat_identification_type = ( - odoo_fiscal_type and odoo_fiscal_type[0] - ) - else: - partner.aeat_identification_type = False - return res - @api.model def extra_features(self): res = super().extra_features() diff --git a/pms_fastapi_l10n_es/tests/test_contacts.py b/pms_fastapi_l10n_es/tests/test_contacts.py index b343342f..7279f18a 100644 --- a/pms_fastapi_l10n_es/tests/test_contacts.py +++ b/pms_fastapi_l10n_es/tests/test_contacts.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class TestContactsEndpoints(CommonTestRoomdooApi): +class TestContactsEndpoints(CommonTestPmsApi): @classmethod def setUpClass(cls) -> None: super().setUpClass() @@ -42,10 +42,12 @@ def test_update_aeat_identification(self): response = self._login(test_client) response = test_client.patch( f"/contacts/{self.test_partner_aeat.id}", - json={"fiscalIdNumberType": "other"}, + json={"fiscalIdNumberType": "another_document"}, ) self.env.invalidate_all() - self.assertEqual(response.json().get("fiscalIdNumberType"), "other") + self.assertEqual( + response.json().get("fiscalIdNumberType"), "another_document" + ) self.assertEqual(response.json().get("fiscalIdNumber"), "ABC123456") self.assertEqual(self.test_partner_aeat.aeat_identification_type, "06") self.assertEqual(self.test_partner_aeat.aeat_identification, "ABC123456") @@ -55,7 +57,9 @@ def test_update_aeat_identification(self): json={"fiscalIdNumber": "XYZ987654"}, ) self.env.invalidate_all() - self.assertEqual(response.json().get("fiscalIdNumberType"), "other") + self.assertEqual( + response.json().get("fiscalIdNumberType"), "another_document" + ) self.assertEqual(response.json().get("fiscalIdNumber"), "XYZ987654") self.assertEqual(self.test_partner_aeat.aeat_identification_type, "06") self.assertEqual(self.test_partner_aeat.aeat_identification, "XYZ987654") @@ -87,14 +91,14 @@ def test_change_vat_to_aeat_identification(self): response = self._login(test_client) response = test_client.patch( f"/contacts/{self.test_partner_vat.id}", - json={"fiscalIdNumber": "ABC123456", "fiscalIdNumberType": "passport"}, + json={"fiscalIdNumber": "ABC1234567", "fiscalIdNumberType": "passport"}, ) self.env.invalidate_all() self.assertEqual(response.json().get("fiscalIdNumberType"), "passport") - self.assertEqual(response.json().get("fiscalIdNumber"), "ABC123456") + self.assertEqual(response.json().get("fiscalIdNumber"), "ABC1234567") self.assertEqual(self.test_partner_vat.vat, False) self.assertEqual(self.test_partner_vat.aeat_identification_type, "03") - self.assertEqual(self.test_partner_vat.aeat_identification, "ABC123456") + self.assertEqual(self.test_partner_vat.aeat_identification, "ABC1234567") def test_change_aeat_identification_to_vat(self): with self._create_test_client() as test_client: diff --git a/roomdoo_fastapi/routers/reports.py b/roomdoo_fastapi/routers/reports.py index 00b95277..3735e248 100644 --- a/roomdoo_fastapi/routers/reports.py +++ b/roomdoo_fastapi/routers/reports.py @@ -143,15 +143,6 @@ async def services_report( if not query: raise MissingError(_("SQL query not found")) report_wizard = env["sql.file.wizard"].sudo().create({"sql_export_id": query.id}) - properties_names = [x["name"] for x in report_wizard.query_properties] - if ( - "x_date_from" not in properties_names - or "x_date_to" not in properties_names - or "x_pms_property_id" not in properties_names - ): - raise MissingError( - _("The Query params was modifieds, please contact the administrator") - ) charge_params = { "x_date_from": fields.Date.to_string(dateFrom), "x_date_to": fields.Date.to_string(dateTo), @@ -159,8 +150,8 @@ async def services_report( } vals = [] for item in report_wizard.query_properties: - if item["name"] in charge_params: - vals.append({"name": item["name"], "value": charge_params[item["name"]]}) + if item["string"] in charge_params: + vals.append({"name": item["name"], "value": charge_params[item["string"]]}) report_wizard.write({"query_properties": vals}) report_wizard.export_sql() @@ -192,22 +183,14 @@ async def departures_report( if not query: raise MissingError(_("SQL query not found")) report_wizard = env["sql.file.wizard"].sudo().create({"sql_export_id": query.id}) - properties_names = [x["name"] for x in report_wizard.query_properties] - if ( - "x_date_from" not in properties_names - or "x_pms_property_id" not in properties_names - ): - raise MissingError( - _("The Query params was modifieds, please contact the administrator") - ) charge_params = { "x_date_from": fields.Date.to_string(dateFrom), "x_pms_property_id": pmsPropertyId, } vals = [] for item in report_wizard.query_properties: - if item["name"] in charge_params: - vals.append({"name": item["name"], "value": charge_params[item["name"]]}) + if item["string"] in charge_params: + vals.append({"name": item["name"], "value": charge_params[item["string"]]}) report_wizard.write({"query_properties": vals}) report_wizard.export_sql() @@ -239,22 +222,14 @@ async def arrivals_report( if not query: raise MissingError(_("SQL query not found")) report_wizard = env["sql.file.wizard"].sudo().create({"sql_export_id": query.id}) - properties_names = [x["name"] for x in report_wizard.query_properties] - if ( - "x_date_from" not in properties_names - or "x_pms_property_id" not in properties_names - ): - raise MissingError( - _("The Query params was modifieds, please contact the administrator") - ) charge_params = { "x_date_from": fields.Date.to_string(dateFrom), "x_pms_property_id": pmsPropertyId, } vals = [] for item in report_wizard.query_properties: - if item["name"] in charge_params: - vals.append({"name": item["name"], "value": charge_params[item["name"]]}) + if item["string"] in charge_params: + vals.append({"name": item["name"], "value": charge_params[item["string"]]}) report_wizard.write({"query_properties": vals}) report_wizard.export_sql() diff --git a/roomdoo_fastapi/tests/__init__.py b/roomdoo_fastapi/tests/__init__.py index 376fc794..73c8b1ff 100644 --- a/roomdoo_fastapi/tests/__init__.py +++ b/roomdoo_fastapi/tests/__init__.py @@ -2,3 +2,4 @@ from . import test_pms_property_urls from . import test_user from . import test_contacts +from . import test_reports diff --git a/roomdoo_fastapi/tests/test_contacts.py b/roomdoo_fastapi/tests/test_contacts.py index 70f9ae17..637456af 100644 --- a/roomdoo_fastapi/tests/test_contacts.py +++ b/roomdoo_fastapi/tests/test_contacts.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class TestContactsEndpoints(CommonTestRoomdooApi): +class TestContactsEndpoints(CommonTestPmsApi): @classmethod def setUpClass(cls) -> None: super().setUpClass() diff --git a/roomdoo_fastapi/tests/test_instance.py b/roomdoo_fastapi/tests/test_instance.py index c1c917ee..289f24eb 100644 --- a/roomdoo_fastapi/tests/test_instance.py +++ b/roomdoo_fastapi/tests/test_instance.py @@ -3,14 +3,14 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi from ..schemas.instance import Instance dir_path = os.path.dirname(os.path.realpath(__file__)) -class TestInstanceEndpoints(CommonTestRoomdooApi): +class TestInstanceEndpoints(CommonTestPmsApi): @classmethod def setUpClass(cls) -> None: super().setUpClass() diff --git a/roomdoo_fastapi/tests/test_pms_property_urls.py b/roomdoo_fastapi/tests/test_pms_property_urls.py index dee7bad0..ca4f3d66 100644 --- a/roomdoo_fastapi/tests/test_pms_property_urls.py +++ b/roomdoo_fastapi/tests/test_pms_property_urls.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class TestLinksEndpoints(CommonTestRoomdooApi): +class TestLinksEndpoints(CommonTestPmsApi): @classmethod def setUpClass(cls) -> None: super().setUpClass() diff --git a/roomdoo_fastapi/tests/test_reports.py b/roomdoo_fastapi/tests/test_reports.py new file mode 100644 index 00000000..4a559072 --- /dev/null +++ b/roomdoo_fastapi/tests/test_reports.py @@ -0,0 +1,117 @@ +from fastapi import status + +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi + + +class TestLinksEndpoints(CommonTestPmsApi): + @classmethod + def setUpClass(cls) -> None: + super().setUpClass() + cls.test_property.write( + { + "ine_tourism_number": "111", + "ine_category_id": cls.env.ref("pms_l10n_es.turism_category_2"), + "street": "Main Street 1", + "zip": "28001", + "city": "Madrid", + "state_id": cls.env.ref("base.state_es_m").id, + "country_id": cls.env.ref("base.es").id, + "phone": "+34123456789", + } + ) + + def test_kelly_report(self): + with self._create_test_client() as test_client: + response = self._login(test_client) + response = test_client.get( + f"/reports/kelly-report?pmsPropertyId={self.test_property.id}&dateFrom=2024-01-01" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK, response.text) + self.assertTrue( + response.headers["content-disposition"].startswith("attachment;"), + response.headers["content-disposition"], + ) + self.assertEqual( + response.headers["content-type"], + "application/vnd.ms-excel", + ) + + def test_ine_report(self): + with self._create_test_client() as test_client: + response = self._login(test_client) + response = test_client.get( + f"/reports/ine-report?pmsPropertyId={self.test_property.id}&dateFrom=2024-01-01&dateTo=2024-01-31" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK, response.text) + self.assertTrue( + response.headers["content-disposition"].startswith("attachment;"), + response.headers["content-disposition"], + ) + self.assertEqual( + response.headers["content-type"], + "application/xml", + ) + + def test_transaction_report(self): + with self._create_test_client() as test_client: + response = self._login(test_client) + response = test_client.get( + f"/reports/transactions-report?pmsPropertyId={self.test_property.id}&dateFrom=2024-01-01&dateTo=2024-01-31" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK, response.text) + self.assertTrue( + response.headers["content-disposition"].startswith("attachment;"), + response.headers["content-disposition"], + ) + self.assertEqual( + response.headers["content-type"], + "application/vnd.ms-excel", + ) + + def test_services_report(self): + with self._create_test_client() as test_client: + response = self._login(test_client) + response = test_client.get( + f"/reports/services-report?pmsPropertyId={self.test_property.id}&dateFrom=2024-01-01&dateTo=2024-01-31" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK, response.text) + self.assertTrue( + response.headers["content-disposition"].startswith("attachment;"), + response.headers["content-disposition"], + ) + self.assertEqual( + response.headers["content-type"], + "application/vnd.ms-excel", + ) + + def test_departures_report(self): + with self._create_test_client() as test_client: + response = self._login(test_client) + response = test_client.get( + f"/reports/departures-report?pmsPropertyId={self.test_property.id}&dateFrom=2024-01-01" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK, response.text) + self.assertTrue( + response.headers["content-disposition"].startswith("attachment;"), + response.headers["content-disposition"], + ) + self.assertEqual( + response.headers["content-type"], + "application/vnd.ms-excel", + ) + + def test_arrivals_report(self): + with self._create_test_client() as test_client: + response = self._login(test_client) + response = test_client.get( + f"/reports/arrivals-report?pmsPropertyId={self.test_property.id}&dateFrom=2024-01-01" + ) + self.assertEqual(response.status_code, status.HTTP_200_OK, response.text) + self.assertTrue( + response.headers["content-disposition"].startswith("attachment;"), + response.headers["content-disposition"], + ) + self.assertEqual( + response.headers["content-type"], + "application/vnd.ms-excel", + ) diff --git a/roomdoo_fastapi/tests/test_user.py b/roomdoo_fastapi/tests/test_user.py index ef42910b..cc73d763 100644 --- a/roomdoo_fastapi/tests/test_user.py +++ b/roomdoo_fastapi/tests/test_user.py @@ -1,9 +1,9 @@ from fastapi import status -from odoo.addons.pms_fastapi.tests.common import CommonTestRoomdooApi +from odoo.addons.pms_fastapi.tests.common import CommonTestPmsApi -class CommonTestAuth(CommonTestRoomdooApi): +class CommonTestAuth(CommonTestPmsApi): def test_password_change(self): with self._create_test_client() as test_client: response = self._login(test_client)