Skip to content
Merged
52 changes: 52 additions & 0 deletions .github.dev/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions pms_api_rest/services/pms_partner_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
)
)
Expand Down
7 changes: 0 additions & 7 deletions pms_api_rest/services/pms_reservation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pms_fastapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from . import models
from . import schemas
from . import routers
from . import models
17 changes: 17 additions & 0 deletions pms_fastapi/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
13 changes: 11 additions & 2 deletions pms_fastapi/routers/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions pms_fastapi/schemas/guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
),
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 += [
Expand Down Expand Up @@ -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}
3 changes: 3 additions & 0 deletions pms_fastapi/schemas/pms_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
3 changes: 2 additions & 1 deletion pms_fastapi/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi/tests/test_agencies.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi/tests/test_contact_id_numbers.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi/tests/test_contacts.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi/tests/test_countries.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi/tests/test_customers.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi/tests/test_guests.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi/tests/test_languages.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi/tests/test_properties.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi/tests/test_suppliers.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi_contact_lastname2/tests/test_contacts.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
4 changes: 2 additions & 2 deletions pms_fastapi_contact_lastname2/tests/test_user.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
1 change: 1 addition & 0 deletions pms_fastapi_l10n_es/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import schemas
from . import routers
from . import models
1 change: 1 addition & 0 deletions pms_fastapi_l10n_es/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import res_partner
Loading