diff --git a/hotel/models/hotel_folio.py b/hotel/models/hotel_folio.py
index 9ef68c97f..668106463 100644
--- a/hotel/models/hotel_folio.py
+++ b/hotel/models/hotel_folio.py
@@ -314,23 +314,24 @@ class HotelFolio(models.Model):
@api.model
def create(self, vals):
- if vals.get('name', _('New')) == _('New'):
+ if vals.get('name', _('New')) == _('New') or 'name' not in vals:
if 'company_id' in vals:
vals['name'] = self.env['ir.sequence'].with_context(
force_company=vals['company_id']
).next_by_code('sale.order') or _('New')
else:
vals['name'] = self.env['ir.sequence'].next_by_code('hotel.folio') or _('New')
+
# Makes sure partner_invoice_id' and 'pricelist_id' are defined
lfields = ('partner_invoice_id', 'partner_shipping_id', 'pricelist_id')
- #~ if any(f not in vals for f in lfields):
- #~ partner = self.env['res.partner'].browse(vals.get('partner_id'))
- #~ addr = partner.address_get(['delivery', 'invoice'])
+ if any(f not in vals for f in lfields):
+ partner = self.env['res.partner'].browse(vals.get('partner_id'))
+ addr = partner.address_get(['delivery', 'invoice'])
#~ vals['partner_invoice_id'] = vals.setdefault('partner_invoice_id', addr['invoice'])
- #~ vals['pricelist_id'] = vals.setdefault(
- #~ 'pricelist_id',
- #~ partner.property_product_pricelist and partner.property_product_pricelist.id)
+ vals['pricelist_id'] = vals.setdefault(
+ 'pricelist_id',
+ partner.property_product_pricelist and partner.property_product_pricelist.id)
result = super(HotelFolio, self).create(vals)
return result
@@ -353,7 +354,10 @@ class HotelFolio(models.Model):
addr = self.partner_id.address_get(['invoice'])
#TEMP:
- values = { 'user_id': self.partner_id.user_id.id or self.env.uid }
+ values = { 'user_id': self.partner_id.user_id.id or self.env.uid,
+ 'pricelist_id':self.partner_id.property_product_pricelist and \
+ self.partner_id.property_product_pricelist.id or \
+ self.env['ir.default'].sudo().get('res.config.settings', 'parity_pricelist_id')}
#~ values = {
#~ 'pricelist_id': self.partner_id.property_product_pricelist and \
#~ self.partner_id.property_product_pricelist.id or False,
@@ -488,18 +492,16 @@ class HotelFolio(models.Model):
def _compute_cardex_count(self):
_logger.info('_compute_cardex_amount')
for record in self:
- if record.reservation_type == 'normal':
+ if record.reservation_type == 'normal' and record.room_lines:
write_vals = {}
- filtered_reservs = record.filtered(
- lambda x: x.room_lines.state != 'cancelled' and \
- not x.room_lines.parent_reservation)
-
+ filtered_reservs = record.room_lines.filtered(
+ lambda x: x.state != 'cancelled' and \
+ not x.parent_reservation)
mapped_cardex = filtered_reservs.mapped('cardex_ids.id')
- write_vals.update({'cardex_count': len(mapped_cardex)})
+ record.cardex_count = len(mapped_cardex)
mapped_cardex_count = filtered_reservs.mapped(
lambda x: (x.adults + x.children) - len(x.cardex_ids))
- write_vals.update({'cardex_pending_count': sum(mapped_cardex_count)})
- record.write(write_vals)
+ record.cardex_pending_count = sum(mapped_cardex_count)
"""
MAILING PROCESS
diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py
index ecb4d3726..f2a9eab6b 100644
--- a/hotel/models/hotel_reservation.py
+++ b/hotel/models/hotel_reservation.py
@@ -334,11 +334,14 @@ class HotelReservation(models.Model):
def _prepare_add_missing_fields(self, values):
""" Deduce missing required fields from the onchange """
res = {}
- onchange_fields = ['room_id', 'pricelist_id', 'reservation_type', 'currency_id']
- if values.get('partner_id') and values.get('room_type_id') and \
- any(f not in values for f in onchange_fields):
+ onchange_fields = ['room_id', 'reservation_type', 'currency_id', 'name']
+ if values.get('partner_id') and values.get('room_type_id'):
line = self.new(values)
- line.onchange_room_id()
+ if any(f not in values for f in onchange_fields):
+ line.onchange_room_id()
+ line.onchange_compute_reservation_description()
+ if 'pricelist_id' not in values:
+ line.onchange_partner_id()
for field in onchange_fields:
if field not in values:
res[field] = line._fields[field].convert_to_write(line[field], line)
@@ -353,7 +356,7 @@ class HotelReservation(models.Model):
if checkin and checkout and room_type:
room_chosen = self.env['hotel.room.type'].check_availability_room(checkin, checkout, room_type)[0]
res.update({
- 'room_id': room_chosen
+ 'room_id': room_chosen.id
})
return res
@@ -888,11 +891,9 @@ class HotelReservation(models.Model):
def _compute_cardex_count(self):
_logger.info('_compute_cardex_count')
for record in self:
- record.write({
- 'cardex_count': len(record.cardex_ids),
- 'cardex_pending_count': (record.adults + record.children) \
+ record.cardex_count = len(record.cardex_ids)
+ record.cardex_pending_count = (record.adults + record.children) \
- len(record.cardex_ids)
- })
# https://www.odoo.com/es_ES/forum/ayuda-1/question/calculated-fields-in-search-filter-possible-118501
@api.multi
diff --git a/hotel/views/hotel_folio.xml b/hotel/views/hotel_folio.xml
index be1003cce..a3a3c73a7 100644
--- a/hotel/views/hotel_folio.xml
+++ b/hotel/views/hotel_folio.xml
@@ -64,7 +64,7 @@
Checks
-
+
-
-
+