mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX] Missing service_line_ids computed
This commit is contained in:
@@ -188,69 +188,72 @@ class PmsService(models.Model):
|
|||||||
|
|
||||||
@api.depends("reservation_id.checkin", "reservation_id.checkout", "product_id")
|
@api.depends("reservation_id.checkin", "reservation_id.checkout", "product_id")
|
||||||
def _compute_service_line_ids(self):
|
def _compute_service_line_ids(self):
|
||||||
for service in self.filtered("product_id"):
|
for service in self:
|
||||||
day_qty = 1
|
if service.product_id:
|
||||||
if service.reservation_id and service.product_id:
|
day_qty = 1
|
||||||
reservation = service.reservation_id
|
if service.reservation_id and service.product_id:
|
||||||
product = service.product_id
|
reservation = service.reservation_id
|
||||||
consumed_on = product.consumed_on
|
product = service.product_id
|
||||||
if product.per_day:
|
consumed_on = product.consumed_on
|
||||||
lines = []
|
if product.per_day:
|
||||||
day_qty = service._service_day_qty()
|
lines = []
|
||||||
days_diff = (reservation.checkout - reservation.checkin).days
|
day_qty = service._service_day_qty()
|
||||||
for i in range(0, days_diff):
|
days_diff = (reservation.checkout - reservation.checkin).days
|
||||||
|
for i in range(0, days_diff):
|
||||||
|
if consumed_on == "after":
|
||||||
|
i += 1
|
||||||
|
idate = reservation.checkin + timedelta(days=i)
|
||||||
|
old_line = service._search_old_lines(idate)
|
||||||
|
if idate in [line.date for line in service.service_line_ids]:
|
||||||
|
#REVIEW: If the date is already cached (otherwise double the date)
|
||||||
|
pass
|
||||||
|
elif not old_line:
|
||||||
|
lines.append(
|
||||||
|
(0, False, {
|
||||||
|
"date": idate,
|
||||||
|
"day_qty": day_qty,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
lines.append((4, old_line.id))
|
||||||
|
move_day = 0
|
||||||
if consumed_on == "after":
|
if consumed_on == "after":
|
||||||
i += 1
|
move_day = 1
|
||||||
idate = reservation.checkin + timedelta(days=i)
|
service.service_line_ids -= service.service_line_ids.filtered_domain(
|
||||||
old_line = service._search_old_lines(idate)
|
[
|
||||||
if idate in [line.date for line in service.service_line_ids]:
|
"|",
|
||||||
#REVIEW: If the date is already cached (otherwise double the date)
|
("date", "<", reservation.checkin + timedelta(move_day)),
|
||||||
pass
|
("date", ">=", reservation.checkout + timedelta(move_day)),
|
||||||
elif not old_line:
|
]
|
||||||
lines.append(
|
)
|
||||||
(0, False, {
|
_logger.info(service)
|
||||||
"date": idate,
|
_logger.info(lines)
|
||||||
|
service.service_line_ids = lines
|
||||||
|
else:
|
||||||
|
# TODO: Review (business logic refact) no per_day logic service
|
||||||
|
if not service.service_line_ids:
|
||||||
|
service.service_line_ids = [(
|
||||||
|
0,
|
||||||
|
False,
|
||||||
|
{
|
||||||
|
"date": fields.Date.today(),
|
||||||
"day_qty": day_qty,
|
"day_qty": day_qty,
|
||||||
})
|
},
|
||||||
)
|
)]
|
||||||
else:
|
|
||||||
lines.append((4, old_line.id))
|
|
||||||
move_day = 0
|
|
||||||
if consumed_on == "after":
|
|
||||||
move_day = 1
|
|
||||||
service.service_line_ids -= service.service_line_ids.filtered_domain(
|
|
||||||
[
|
|
||||||
"|",
|
|
||||||
("date", "<", reservation.checkin + timedelta(move_day)),
|
|
||||||
("date", ">=", reservation.checkout + timedelta(move_day)),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
_logger.info(service)
|
|
||||||
_logger.info(lines)
|
|
||||||
service.service_line_ids = lines
|
|
||||||
else:
|
else:
|
||||||
# TODO: Review (business logic refact) no per_day logic service
|
# TODO: Service without reservation(room) but with folio¿?
|
||||||
|
# example: tourist tour in group
|
||||||
if not service.service_line_ids:
|
if not service.service_line_ids:
|
||||||
service.service_line_ids = [(
|
service.service_line_ids = [(
|
||||||
0,
|
0,
|
||||||
False,
|
False,
|
||||||
{
|
{
|
||||||
"date": fields.Date.today(),
|
"date": fields.Date.today(),
|
||||||
"day_qty": day_qty,
|
"day_qty": day_qty,
|
||||||
},
|
},
|
||||||
)]
|
)]
|
||||||
else:
|
else:
|
||||||
# TODO: Service without reservation(room) but with folio¿?
|
service.service_line_ids = False
|
||||||
# example: tourist tour in group
|
|
||||||
if not service.service_line_ids:
|
|
||||||
service.service_line_ids = [(
|
|
||||||
0,
|
|
||||||
False,
|
|
||||||
{
|
|
||||||
"date": fields.Date.today(),
|
|
||||||
"day_qty": day_qty,
|
|
||||||
},
|
|
||||||
)]
|
|
||||||
|
|
||||||
def _search_old_lines(self, date):
|
def _search_old_lines(self, date):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
@@ -273,6 +276,7 @@ class PmsService(models.Model):
|
|||||||
@api.depends("service_line_ids", "service_line_ids.day_qty")
|
@api.depends("service_line_ids", "service_line_ids.day_qty")
|
||||||
def _compute_product_qty(self):
|
def _compute_product_qty(self):
|
||||||
self.product_qty = 0
|
self.product_qty = 0
|
||||||
|
_logger.info("B")
|
||||||
for service in self.filtered("service_line_ids"):
|
for service in self.filtered("service_line_ids"):
|
||||||
qty = sum(service.service_line_ids.mapped("day_qty"))
|
qty = sum(service.service_line_ids.mapped("day_qty"))
|
||||||
service.product_qty = qty
|
service.product_qty = qty
|
||||||
|
|||||||
Reference in New Issue
Block a user