mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms: Add independent address to room
This commit is contained in:
@@ -110,6 +110,89 @@ class PmsRoom(models.Model):
|
||||
help="Four character name, if not set, autocompletes with the first two letters of "
|
||||
"the room name and two incremental numbers",
|
||||
)
|
||||
address_is_independent = fields.Boolean(
|
||||
string="Address is Independent",
|
||||
help="Indicates that the address of the room is independent of the property",
|
||||
)
|
||||
address_id = fields.Many2one(
|
||||
string="Address",
|
||||
help="Address of the room",
|
||||
comodel_name="res.partner",
|
||||
index=True,
|
||||
compute="_compute_address_id",
|
||||
store=True,
|
||||
ondelete="restrict",
|
||||
)
|
||||
street = fields.Char(
|
||||
related="address_id.street",
|
||||
readonly=False,
|
||||
)
|
||||
street2 = fields.Char(
|
||||
related="address_id.street2",
|
||||
readonly=False,
|
||||
)
|
||||
zip = fields.Char(
|
||||
related="address_id.zip",
|
||||
readonly=False,
|
||||
)
|
||||
city = fields.Char(
|
||||
related="address_id.city",
|
||||
readonly=False,
|
||||
)
|
||||
state_id = fields.Many2one(
|
||||
"res.country.state",
|
||||
related="address_id.state_id",
|
||||
string="State",
|
||||
ondelete="restrict",
|
||||
domain="[('country_id', '=?', country_id)]",
|
||||
readonly=False,
|
||||
)
|
||||
country_id = fields.Many2one(
|
||||
"res.country",
|
||||
related="address_id.country_id",
|
||||
string="Country",
|
||||
ondelete="restrict",
|
||||
readonly=False,
|
||||
)
|
||||
partner_latitude = fields.Float(
|
||||
string="Geo Latitude",
|
||||
related="address_id.partner_latitude",
|
||||
readonly=False,
|
||||
digits=(16, 5),
|
||||
)
|
||||
partner_longitude = fields.Float(
|
||||
string="Geo Longitude",
|
||||
related="address_id.partner_longitude",
|
||||
readonly=False,
|
||||
digits=(16, 5),
|
||||
)
|
||||
email = fields.Char(
|
||||
related="address_id.email",
|
||||
readonly=False,
|
||||
)
|
||||
email_formatted = fields.Char(
|
||||
"Formatted Email",
|
||||
compute="_compute_email_formatted",
|
||||
help='Format email address "Name <email@domain>"',
|
||||
)
|
||||
phone = fields.Char(
|
||||
related="address_id.phone",
|
||||
readonly=False,
|
||||
)
|
||||
mobile = fields.Char(
|
||||
related="address_id.mobile",
|
||||
readonly=False,
|
||||
)
|
||||
website = fields.Char(
|
||||
related="address_id.website",
|
||||
readonly=False,
|
||||
)
|
||||
image_1920 = fields.Image(
|
||||
related="address_id.image_1920",
|
||||
readonly=False,
|
||||
max_width=1920,
|
||||
max_height=1920,
|
||||
)
|
||||
|
||||
_sql_constraints = [
|
||||
(
|
||||
@@ -129,10 +212,38 @@ class PmsRoom(models.Model):
|
||||
@api.depends("child_ids")
|
||||
def _compute_is_shared_room(self):
|
||||
for record in self:
|
||||
if record.child_ids:
|
||||
record.is_shared_room = True
|
||||
elif not record.is_shared_room:
|
||||
record.is_shared_room = False
|
||||
record.is_shared_room = bool(record.child_ids)
|
||||
|
||||
@api.depends("address_is_independent")
|
||||
def _compute_address_id(self):
|
||||
for record in self:
|
||||
if not record.address_is_independent:
|
||||
if record.address_id and record.address_id.active:
|
||||
record.address_id.active = False
|
||||
if record.address_is_independent:
|
||||
if record.address_id and not record.address_id.active:
|
||||
record.address_id.active = True
|
||||
elif not record.address_id:
|
||||
record.address_id = (
|
||||
self.env["res.partner"]
|
||||
.with_context(avoid_document_restriction=True)
|
||||
.create(
|
||||
{
|
||||
"name": record.name,
|
||||
"type": "other",
|
||||
"is_company": False,
|
||||
"active": True,
|
||||
"parent_id": record.pms_property_id.id,
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
@api.depends("name", "email")
|
||||
def _compute_email_formatted(self):
|
||||
for room in self.filtered("address_id"):
|
||||
room.email_formatted = (
|
||||
room.address_id.email_formatted() if room.address_id else False
|
||||
)
|
||||
|
||||
def name_get(self):
|
||||
result = []
|
||||
|
||||
@@ -341,3 +341,92 @@ class TestPmsRoom(TestPms):
|
||||
msg="The short_name of the room should not be able to be write.",
|
||||
):
|
||||
self.room1.write({"short_name": "SIN-201"})
|
||||
|
||||
def test_create_independent_address(self):
|
||||
"""
|
||||
Check that an independent address is created and associated correctly
|
||||
when address_is_independent is set to True.
|
||||
"""
|
||||
self.room1 = self.env["pms.room"].create(
|
||||
{
|
||||
"name": "Room 101",
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"room_type_id": self.room_type1.id,
|
||||
"address_is_independent": True,
|
||||
}
|
||||
)
|
||||
self.assertTrue(
|
||||
self.room1.address_id,
|
||||
"The address should be created and associated with the room.",
|
||||
)
|
||||
self.assertTrue(self.room1.address_id.active, "The address should be active.")
|
||||
|
||||
def test_deactivate_independent_address(self):
|
||||
"""
|
||||
Check that the independent address is archived when a
|
||||
ddress_is_independent is set to False.
|
||||
"""
|
||||
self.room1 = self.env["pms.room"].create(
|
||||
{
|
||||
"name": "Room 101",
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"room_type_id": self.room_type1.id,
|
||||
"address_is_independent": True,
|
||||
}
|
||||
)
|
||||
self.room1.address_is_independent = False
|
||||
self.assertFalse(
|
||||
self.room1.address_id.active, "The address should be archived."
|
||||
)
|
||||
|
||||
def test_reactivate_independent_address(self):
|
||||
"""
|
||||
Check that the archived independent address is reactivated when
|
||||
address_is_independent is set to True again.
|
||||
"""
|
||||
self.room1 = self.env["pms.room"].create(
|
||||
{
|
||||
"name": "Room 101",
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"room_type_id": self.room_type1.id,
|
||||
"address_is_independent": True,
|
||||
}
|
||||
)
|
||||
initial_address_id = self.room1.address_id.id
|
||||
self.room1.address_is_independent = False
|
||||
self.assertFalse(
|
||||
self.room1.address_id.active, "The address should be archived."
|
||||
)
|
||||
self.room1.address_is_independent = True
|
||||
self.assertTrue(
|
||||
self.room1.address_id.active,
|
||||
"The address should be reactivated, not created again.",
|
||||
)
|
||||
self.assertEqual(
|
||||
self.room1.address_id.id,
|
||||
initial_address_id,
|
||||
"The reactivated address should be the same as the initial address.",
|
||||
)
|
||||
self.assertEqual(
|
||||
self.room1.address_id.name,
|
||||
"Room 101",
|
||||
"The reactivated address should have the same name.",
|
||||
)
|
||||
|
||||
def test_prevent_deletion_of_associated_address(self):
|
||||
"""
|
||||
Check that an associated address cannot be deleted.
|
||||
"""
|
||||
self.room1 = self.env["pms.room"].create(
|
||||
{
|
||||
"name": "Room 101",
|
||||
"pms_property_id": self.pms_property1.id,
|
||||
"room_type_id": self.room_type1.id,
|
||||
"address_is_independent": True,
|
||||
}
|
||||
)
|
||||
with self.assertRaises(
|
||||
IntegrityError,
|
||||
msg="The address associated with a room should not be deletable.",
|
||||
):
|
||||
self.room1.address_id.unlink()
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
<field name="name" />
|
||||
</h1>
|
||||
</div>
|
||||
<group>
|
||||
<field name="sequence" />
|
||||
</group>
|
||||
<notebook>
|
||||
<page name="information_pms_room" string="Information">
|
||||
<group colspan="4" col="4">
|
||||
@@ -36,6 +39,8 @@
|
||||
force_save="1"
|
||||
/>
|
||||
<field name="ubication_id" string="Ubication" />
|
||||
<field name="address_is_independent" />
|
||||
<field name="address_id" invisible="1" force_save="1" />
|
||||
<!-- <field name="categ_id" select="1" domain="[('isroomtype','=',True)]" string="Room Type" /> -->
|
||||
<field name="room_type_id" string="Room Type" />
|
||||
<field name="is_shared_room" />
|
||||
@@ -72,6 +77,64 @@
|
||||
<page string="Amenities">
|
||||
<field name="room_amenity_ids" />
|
||||
</page>
|
||||
<page
|
||||
string="Address"
|
||||
attrs="{'invisible':[('address_is_independent', '=', False)]}"
|
||||
>
|
||||
<field
|
||||
name="image_1920"
|
||||
widget='image'
|
||||
class="oe_avatar"
|
||||
options='{"preview_image": "image_128"}'
|
||||
/>
|
||||
<group>
|
||||
<group>
|
||||
<label for="street" string="Address" />
|
||||
<div class="o_address_format">
|
||||
<field
|
||||
name="street"
|
||||
placeholder="Street..."
|
||||
class="o_address_street"
|
||||
/>
|
||||
<field
|
||||
name="street2"
|
||||
placeholder="Street 2..."
|
||||
class="o_address_street"
|
||||
/>
|
||||
<field
|
||||
name="city"
|
||||
placeholder="City"
|
||||
class="o_address_city"
|
||||
/>
|
||||
<field
|
||||
name="state_id"
|
||||
class="o_address_state"
|
||||
placeholder="State"
|
||||
options="{'no_open': True, 'no_quick_create': True}"
|
||||
context="{'default_country_id': country_id}"
|
||||
/>
|
||||
<field
|
||||
name="zip"
|
||||
placeholder="ZIP"
|
||||
class="o_address_zip"
|
||||
/>
|
||||
<field
|
||||
name="country_id"
|
||||
placeholder="Country"
|
||||
class="o_address_country"
|
||||
options='{"no_open": True, "no_create": True}'
|
||||
/>
|
||||
</div>
|
||||
<field
|
||||
name="website"
|
||||
widget="url"
|
||||
placeholder="e.g. https://www.odoo.com"
|
||||
/>
|
||||
</group>
|
||||
<group>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
<page
|
||||
string="Shared Room"
|
||||
attrs="{'invisible':[('is_shared_room', '=', False)]}"
|
||||
@@ -94,9 +157,6 @@
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
<group>
|
||||
<field name="sequence" />
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user