Skip to content

Commit

Permalink
[IMP] [17.0] hotel: Implement code changes as per review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pavan-serpentcs committed Jul 15, 2024
1 parent 2f4b970 commit abed0a6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
5 changes: 3 additions & 2 deletions hotel/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
{
"name": "Hotel Management",
"version": "17.0.1.0.0",
"author": "Odoo Community Association (OCA), Serpent Consulting \
Services Pvt. Ltd., OpenERP SA",
"author": """Odoo Community Association (OCA),
Serpent Consulting Services Pvt. Ltd.,
""",
"category": "Hotel Management",
"website": "https://github.com/OCA/vertical-hotel",
"depends": ["sale_stock", "account"],
Expand Down
1 change: 1 addition & 0 deletions hotel/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class AccountMove(models.Model):
_inherit = "account.move"

# "Override the create method to link the account move with a hotel folio"
@api.model
def create(self, vals):
res = super().create(vals)
Expand Down
42 changes: 20 additions & 22 deletions hotel/models/hotel_folio.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ class HotelFolio(models.Model):
_description = "hotel folio"
_rec_name = "order_id"

def name_get(self):
def _compute_display_name(self):
res = []
fname = ""
for rec in self:
if rec.order_id:
fname = str(rec.name)
rec.display_name = ( str(rec.order_id.name))
res.append((rec.id, fname))
return res

@api.model
def name_search(self, name="", args=None, operator="ilike", limit=100):
Expand All @@ -58,7 +57,7 @@ def _get_checkout_date(self):
)
return fields.Datetime.to_string(checkout_date)

name = fields.Char("Folio Number", readonly=True, index=True, default="New")
name = fields.Char("Folio Number", index=True, default="New")
order_id = fields.Many2one(
"sale.order", "Order", delegate=True, required=True, ondelete="cascade"
)
Expand All @@ -69,7 +68,6 @@ def _get_checkout_date(self):
)
checkout_date = fields.Datetime(
"Check Out",
required=True,
readonly=True,
default=_get_checkout_date,
)
Expand Down Expand Up @@ -140,18 +138,16 @@ def _update_folio_line(self, folio_id):
folio_room_line_obj = self.env["folio.room.line"]
hotel_room_obj = self.env["hotel.room"]
for rec in folio_id:
for room_rec in rec.room_line_ids:
room = hotel_room_obj.search(
[("product_id", "=", room_rec.product_id.id)]
)
room.write({"isroom": False})
vals = {
"room_id": room.id,
"check_in": rec.checkin_date,
"check_out": rec.checkout_date,
"folio_id": rec.id,
}
folio_room_line_obj.create(vals)
product_ids = rec.room_line_ids.mapped("product_id").ids
rooms = hotel_room_obj.search([("product_id", "in", product_ids)])
rooms.write({"isroom": False})
vals = {
"room_id": rooms.id,
"check_in": rec.checkin_date,
"check_out": rec.checkout_date,
"folio_id": rec.id,
}
folio_room_line_obj.create(vals)

@api.model
def create(self, vals):
Expand All @@ -161,7 +157,7 @@ def create(self, vals):
@param vals: dictionary of fields value.
@return: new record set for hotel folio.
"""
if not "service_line_ids" and "folio_id" in vals:
if "service_line_ids" not in vals and "folio_id" in vals:
tmp_room_lines = vals.get("room_line_ids", [])
vals["order_policy"] = vals.get("hotel_policy", "manual")
vals.update({"room_line_ids": []})
Expand All @@ -175,7 +171,7 @@ def create(self, vals):
vals = {}
vals["name"] = self.env["ir.sequence"].next_by_code("hotel.folio")
vals["duration"] = vals.get("duration", 0.0) or vals.get("duration", 0.0)
folio_id = super().create(vals)
folio_id = super(HotelFolio, self).create(vals)
self._update_folio_line(folio_id)
return folio_id

Expand All @@ -198,8 +194,8 @@ def write(self, vals):
new_rooms = set(room_lst).difference(set(rooms_list))
if len(list(new_rooms)) != 0:
room_list = product_obj.browse(list(new_rooms))
for rm in room_list:
room_obj = hotel_room_obj.search([("product_id", "=", rm.id)])
for room in room_list:
room_obj = hotel_room_obj.search([("product_id", "=", room.id)],limit=1)
room_obj.write({"isroom": False})
vals = {
"room_id": room_obj.id,
Expand All @@ -223,7 +219,7 @@ def write(self, vals):
[("folio_id", "=", rec.id)]
)
folio_romline_rec.write(room_vals)
return super().write(vals)
return super(HotelFolio, self).write(vals)

@api.onchange("partner_id")
def _onchange_partner_id(self):
Expand Down Expand Up @@ -347,6 +343,8 @@ def unlink(self):
@param self: The object pointer
@return: True/False.
"""
hotel_room_obj = self.env["hotel.room"]
hotel_room_line_obj = self.env["folio.room.line"]
for line in self:
if line.order_line_id:
rooms = self.env["hotel.room"].search(
Expand Down
4 changes: 2 additions & 2 deletions hotel/views/hotel_folio.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<sheet>
<label for="name" string="Folio Number" />
<h1>
<field name="name" colspan="4" />
<field name="name" colspan="4" readonly="1" />
</h1>
<group colspan="4" col="4">
<field name="date_order" readonly="1" />
Expand Down Expand Up @@ -100,7 +100,7 @@
/>
<field
name="checkout_date"
readonly="state != 'draft'"
readonly="state != 'draft' or 1"
/>
<field name="duration" readonly="1" />
<field name="duration_dummy" invisible="1" />
Expand Down

0 comments on commit abed0a6

Please sign in to comment.