[ADD] Compute service_ids based in board_service selection

This commit is contained in:
Dario Lodeiros
2018-12-04 13:42:51 +01:00
parent 7ef85927bf
commit 028d1fcf0d
4 changed files with 97 additions and 53 deletions

View File

@@ -265,6 +265,7 @@
'checkout': (DateTime.today() + timedelta(days=2)).strftime('%Y-%m-%d'), 'checkout': (DateTime.today() + timedelta(days=2)).strftime('%Y-%m-%d'),
'adults': 2, 'adults': 2,
'state': 'confirm', 'state': 'confirm',
'board_service_id': ref('hotel_board_service_1'),
})]"/> })]"/>
</record> </record>
<!-- reservation of 1 triple room for 3 people on behalf on the company --> <!-- reservation of 1 triple room for 3 people on behalf on the company -->
@@ -276,6 +277,7 @@
'checkin': (DateTime.today() + timedelta(days=2)).strftime('%Y-%m-%d'), 'checkin': (DateTime.today() + timedelta(days=2)).strftime('%Y-%m-%d'),
'checkout': (DateTime.today() + timedelta(days=4)).strftime('%Y-%m-%d'), 'checkout': (DateTime.today() + timedelta(days=4)).strftime('%Y-%m-%d'),
'adults': 3, 'adults': 3,
'board_service_id': ref('hotel_board_service_2'),
})]"/> })]"/>
</record> </record>
<!-- reservation of 3 single rooms for 3 people with 1 cancelled --> <!-- reservation of 3 single rooms for 3 people with 1 cancelled -->
@@ -312,6 +314,7 @@
'checkout': (DateTime.today() + timedelta(days=4)).strftime('%Y-%m-%d'), 'checkout': (DateTime.today() + timedelta(days=4)).strftime('%Y-%m-%d'),
'adults': 1, 'adults': 1,
'state': 'confirm', 'state': 'confirm',
'board_service_id': ref('hotel_board_service_1'),
})]"/> })]"/>
</record> </record>

View File

@@ -290,6 +290,15 @@ class HotelReservation(models.Model):
#~ 'reserve_color': colors[0], #~ 'reserve_color': colors[0],
#~ 'reserve_color_text': colors[1], #~ 'reserve_color_text': colors[1],
}) })
if 'board_service_id' in vals:
board_services = []
board = self.env['hotel.board.service'].browse(vals['board_service_id'])
for product in board.service_ids:
board_services.append((0, False, {
'product_id': product.id,
'is_board_service': True,
}))
vals.update({'service_ids': board_services})
if self.compute_price_out_vals(vals): if self.compute_price_out_vals(vals):
days_diff = ( days_diff = (
fields.Date.from_string(vals['checkout']) - fields.Date.from_string(vals['checkin']) fields.Date.from_string(vals['checkout']) - fields.Date.from_string(vals['checkin'])
@@ -317,6 +326,22 @@ class HotelReservation(models.Model):
fields.Date.from_string(checkout) - \ fields.Date.from_string(checkout) - \
fields.Date.from_string(checkin) fields.Date.from_string(checkin)
).days ).days
if self.compute_board_services(vals):
record.service_ids.filtered(lambda r: r.is_board_service == True).unlink()
board_services = []
board = self.env['hotel.board.service'].browse(vals['board_service_id'])
for product in board.service_ids:
board_services.append((0, False, {
'product_id': product.id,
'is_board_service': True,
}))
# NEED REVIEW: Why I need add manually the old IDs if board service is (0,0,(-)) ¿?¿?¿
record.update({'service_ids': [(6, 0, record.service_ids.ids)] + board_services})
update_services = record.service_ids.filtered(
lambda r: r.is_board_service == True
)
for service in update_services:
service.onchange_product_calc_qty()
if record.compute_price_out_vals(vals): if record.compute_price_out_vals(vals):
record.update(record.prepare_reservation_lines( record.update(record.prepare_reservation_lines(
checkin, checkin,
@@ -325,14 +350,12 @@ class HotelReservation(models.Model):
if record.compute_qty_service_day(vals): if record.compute_qty_service_day(vals):
for service in record.service_ids: for service in record.service_ids:
if service.product_id.per_day: if service.product_id.per_day:
params = {
'per_person': service.product_id.per_person,
'persons': vals['adults'] if 'adults' in vals else record.adults
}
service.update(service.prepare_service_lines( service.update(service.prepare_service_lines(
checkin, dfrom=checkin,
days_diff, days=days_diff,
params per_person=product.per_person,
persons=reservation.adults,
old_line_days=service.service_line_ids
)) ))
if ('checkin' in vals and record.checkin != vals['checkin']) or \ if ('checkin' in vals and record.checkin != vals['checkin']) or \
('checkout' in vals and record.checkout != vals['checkout']) or \ ('checkout' in vals and record.checkout != vals['checkout']) or \
@@ -341,6 +364,21 @@ class HotelReservation(models.Model):
res = super(HotelReservation, self).write(vals) res = super(HotelReservation, self).write(vals)
return res return res
@api.multi
def compute_board_services(self, vals):
"""
We must compute service_ids when we hace a board_service_id without
service_ids associated to reservation
"""
if 'board_service_id' in vals:
if 'service_ids' in vals:
for service in vals['service_ids']:
if 'is_board_service' in service[2] and \
service[2]['is_board_service'] == True:
return False
return True
return False
@api.multi @api.multi
def compute_qty_service_day(self, vals): def compute_qty_service_day(self, vals):
""" """
@@ -361,12 +399,14 @@ class HotelReservation(models.Model):
def _prepare_add_missing_fields(self, values): def _prepare_add_missing_fields(self, values):
""" Deduce missing required fields from the onchange """ """ Deduce missing required fields from the onchange """
res = {} res = {}
onchange_fields = ['room_id', 'reservation_type', 'currency_id', 'name'] onchange_fields = ['room_id', 'reservation_type',
'currency_id', 'name', 'board_service_id']
if values.get('room_type_id'): if values.get('room_type_id'):
line = self.new(values) line = self.new(values)
if any(f not in values for f in onchange_fields): if any(f not in values for f in onchange_fields):
line.onchange_room_id() line.onchange_room_id()
line.onchange_compute_reservation_description() line.onchange_compute_reservation_description()
line.onchange_board_service()
if 'pricelist_id' not in values: if 'pricelist_id' not in values:
line.onchange_partner_id() line.onchange_partner_id()
for field in onchange_fields: for field in onchange_fields:
@@ -567,21 +607,23 @@ class HotelReservation(models.Model):
@api.onchange('board_service_id') @api.onchange('board_service_id')
def onchange_board_service(self): def onchange_board_service(self):
if self.board_service_id: if self.board_service_id:
self.service_ids.filtered(lambda r: r.is_board_service == True).unlink()
board_services = [] board_services = []
for product in self.board_service_id.service_ids: for product in self.board_service_id.service_ids:
board_services.append((0, False, { if product.per_day:
'product_id': product.id, vals = {
'is_board_service': True, 'product_id': product.id,
})) 'is_board_service': True,
# NEED REVIEW: Why I need add manually the old IDs if board service is (0,0,(-)) ¿?¿?¿ }
self.update({'service_ids': [(6, 0, self.service_ids.ids)] + board_services}) vals.update(self.env['hotel.service'].prepare_service_lines(
update_services = self.service_ids.filtered( dfrom=self.checkin,
lambda r: r.is_board_service == True days=self.nights,
) per_person=product.per_person,
for service in update_services: persons=self.adults,
service.onchange_product_calc_qty() old_line_days=False))
board_services.append((0, False, vals))
other_services = self.service_ids.filtered(lambda r: r.is_board_service == False)
self.update({'service_ids': [(6, 0, other_services.ids)] + board_services})
""" """
COMPUTE RESERVE COLOR ---------------------------------------------- COMPUTE RESERVE COLOR ----------------------------------------------

View File

@@ -78,14 +78,13 @@ class HotelService(models.Model):
if self.compute_lines_out_vals(vals): if self.compute_lines_out_vals(vals):
reservation = self.env['hotel.reservation'].browse(vals['ser_room_line']) reservation = self.env['hotel.reservation'].browse(vals['ser_room_line'])
product = self.env['product.product'].browse(vals['product_id']) product = self.env['product.product'].browse(vals['product_id'])
params = {
'per_person': product.per_person,
'persons': reservation.adults
}
vals.update(self.prepare_service_lines( vals.update(self.prepare_service_lines(
reservation.checkin, dfrom=reservation.checkin,
reservation.nights, days=reservation.nights,
params per_person=product.per_person,
persons=reservation.adults,
old_day_lines=False,
)) ))
record = super(HotelService, self).create(vals) record = super(HotelService, self).create(vals)
return record return record
@@ -105,14 +104,12 @@ class HotelService(models.Model):
reservations = self.env['hotel.reservation'] reservations = self.env['hotel.reservation']
reservation = reservations.browse(vals['ser_room_line']) \ reservation = reservations.browse(vals['ser_room_line']) \
if 'ser_room_line' in vals else record.ser_room_line if 'ser_room_line' in vals else record.ser_room_line
params = {
'per_person': product.per_person,
'persons': reservation.adults
}
record.update(record.prepare_service_lines( record.update(record.prepare_service_lines(
reservation.checkin, dfrom=reservation.checkin,
reservation.nights, days=reservation.nights,
params per_person=product.per_person,
persons=reservation.adults,
old_line_days=self.service_line_ids
)) ))
res = super(HotelService, self).write(vals) res = super(HotelService, self).write(vals)
return res return res
@@ -142,37 +139,36 @@ class HotelService(models.Model):
if record.per_day and record.ser_room_line: if record.per_day and record.ser_room_line:
product = record.product_id product = record.product_id
reservation = record.ser_room_line reservation = record.ser_room_line
params = {
'per_person': product.per_person,
'persons': reservation.adults
}
record.update(self.prepare_service_lines( record.update(self.prepare_service_lines(
reservation.checkin, dfrom=reservation.checkin,
reservation.nights, days=reservation.nights,
params)) per_person=product.per_person,
@api.multi persons=reservation.adults,
def prepare_service_lines(self, dfrom, days, params=False): old_line_days=self.service_line_ids))
@api.model
def prepare_service_lines(self, **kwargs):
""" """
Respect the old manual changes on lines Prepare line and respect the old manual changes on lines
""" """
self.ensure_one()
cmds = [(5, 0, 0)] cmds = [(5, 0, 0)]
old_lines_days = self.mapped('service_line_ids.date') old_lines_days = kwargs.get('old_lines_days')
total_qty = 0 total_qty = 0
day_qty = 1 day_qty = 1
if params.get('per_person'): #WARNING: Change adults in reservation NOT update qty service!! if kwargs.get('per_person'): #WARNING: Change adults in reservation NOT update qty service!!
day_qty = params.get('persons') day_qty = kwargs.get('persons')
for i in range(0, days): old_line_days = self.env['hotel.service.line'].browse(kwargs.get('old_line_days'))
idate = (fields.Date.from_string(dfrom) + timedelta(days=i)).strftime( for i in range(0, kwargs.get('days')):
idate = (fields.Date.from_string(kwargs.get('dfrom')) + timedelta(days=i)).strftime(
DEFAULT_SERVER_DATE_FORMAT) DEFAULT_SERVER_DATE_FORMAT)
old_line = self.service_line_ids.filtered(lambda r: r.date == idate) if not old_lines_days or idate not in old_lines_days.mapped('date'):
if idate not in old_lines_days:
cmds.append((0, False, { cmds.append((0, False, {
'date': idate, 'date': idate,
'day_qty': day_qty 'day_qty': day_qty
})) }))
total_qty = total_qty + day_qty total_qty = total_qty + day_qty
else: else:
old_line = old_line_days.filtered(lambda r: r.date == idate)
cmds.append((4, old_line.id)) cmds.append((4, old_line.id))
total_qty = total_qty + old_line.day_qty total_qty = total_qty + old_line.day_qty
return {'service_line_ids': cmds, 'product_qty': total_qty} return {'service_line_ids': cmds, 'product_qty': total_qty}

View File

@@ -58,6 +58,8 @@ class AccountInvoice(models.Model):
@api.multi @api.multi
def action_invoice_open(self): def action_invoice_open(self):
#TODO: VAT Control
"""
to_open_invoices_without_vat = self.filtered( to_open_invoices_without_vat = self.filtered(
lambda inv: inv.state != 'open' and inv.partner_id.vat == False) lambda inv: inv.state != 'open' and inv.partner_id.vat == False)
if to_open_invoices_without_vat: if to_open_invoices_without_vat:
@@ -65,5 +67,6 @@ class AccountInvoice(models.Model):
for invoice in to_open_invoices_without_vat: for invoice in to_open_invoices_without_vat:
vat_error += ", " + invoice.partner_id.name vat_error += ", " + invoice.partner_id.name
raise ValidationError(vat_error) raise ValidationError(vat_error)
"""
return super(AccountInvoice, self).action_invoice_open() return super(AccountInvoice, self).action_invoice_open()