[WIP] Security Rules

This commit is contained in:
Dario Lodeiros
2019-03-17 17:25:18 +01:00
parent a044c92fe5
commit 0cb4ed1f32
5 changed files with 45 additions and 23 deletions

View File

@@ -12,18 +12,20 @@ class HotelBoardServiceLine(models.Model):
def _get_default_price(self):
if self.product_id:
return self.product_id.list_price
hotel_board_service_id = fields.Many2one(
'hotel.board.service', 'Board Service', ondelete='cascade', required=True)
'hotel.board.service',
'Board Service',
ondelete='cascade',
required=True)
product_id = fields.Many2one(
'product.product', 'Product', required=True)
amount = fields.Float('Amount',
digits=dp.get_precision('Product Price'), default=_get_default_price)
amount = fields.Float(
'Amount',
digits=dp.get_precision('Product Price'),
default=_get_default_price)
@api.onchange('product_id')
def onchange_product_id(self):
if self.product_id:
self.update({'amount': self.product_id.list_price})

View File

@@ -169,11 +169,17 @@ class HotelService(models.Model):
if self.compute_lines_out_vals(vals):
reservation = self.env['hotel.reservation'].browse(vals['ser_room_line'])
product = self.env['product.product'].browse(vals['product_id'])
checkin_dt = fields.Date.from_string(reservation.real_checkin)
checkout_dt = fields.Date.from_string(reservation.real_checkout)
if reservation.splitted:
checkin = reservation.real_checkin
checkout = reservation.real_checkout
else:
checkin = reservation.checkin
checkout = reservation.checkout
checkin_dt = fields.Date.from_string(checkin)
checkout_dt = fields.Date.from_string(checkout)
nights = abs((checkout_dt - checkin_dt).days)
vals.update(self.prepare_service_lines(
dfrom=reservation.real_checkin,
dfrom=checkin,
days=nights,
per_person=product.per_person,
persons=reservation.adults,
@@ -190,18 +196,24 @@ class HotelService(models.Model):
product = self.env['product.product'].browse(vals.get('product_id'))
if not product.per_day:
vals.update({
'service_line_ids' : [(5, 0, 0)]
'service_line_ids': [(5, 0, 0)]
})
else:
for record in self:
reservations = self.env['hotel.reservation']
reservation = reservations.browse(vals['ser_room_line']) \
if 'ser_room_line' in vals else record.ser_room_line
checkin_dt = fields.Date.from_string(reservation.real_checkin)
checkout_dt = fields.Date.from_string(reservation.real_checkout)
if reservation.splitted:
checkin = reservation.real_checkin
checkout = reservation.real_checkout
else:
checkin = reservation.checkin
checkout = reservation.checkout
checkin_dt = fields.Date.from_string(checkin)
checkout_dt = fields.Date.from_string(checkout)
nights = abs((checkout_dt - checkin_dt).days)
record.update(record.prepare_service_lines(
dfrom=reservation.real_checkin,
dfrom=checkin,
days=nights,
per_person=product.per_person,
persons=reservation.adults,
@@ -277,11 +289,17 @@ class HotelService(models.Model):
if record.per_day and record.ser_room_line:
product = record.product_id
reservation = record.ser_room_line
checkin_dt = fields.Date.from_string(reservation.real_checkin)
checkout_dt = fields.Date.from_string(reservation.real_checkout)
if reservation.splitted:
checkin = reservation.real_checkin
checkout = reservation.real_checkout
else:
checkin = reservation.checkin
checkout = reservation.checkout
checkin_dt = fields.Date.from_string(checkin)
checkout_dt = fields.Date.from_string(checkout)
nights = abs((checkout_dt - checkin_dt).days)
vals.update(record.prepare_service_lines(
dfrom=reservation.real_checkin,
dfrom=checkin,
days=nights,
per_person=product.per_person,
persons=reservation.adults,