mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
14.0 pms service price day (#57)
WIP: compute folio_sale_line without (5,0,0) WIP: boardservices pricelist item sql search * [IMP]pms: Service day with prices * [ADD]pms: New Product price base type: Board Service * [WIP]pms: pricelist item rule board service * [WIP]pms: pricelist boardservice sql * [WIP]pms: pricelist boardservice sql * [IMP] service price per day * [FIX] compute board_service reservation change * [FIX] Views * [IMP]pms: add default user_id on reservation and folio * [IMP]pms: aler change prices reservation * [FIX]pms: recompute reservation services board * [DEL]pms: pricelist field on board_service_room_type * [RFC] sale_line_ids model
This commit is contained in:
@@ -29,35 +29,144 @@ class PmsServiceLine(models.Model):
|
||||
)
|
||||
date = fields.Date("Date")
|
||||
day_qty = fields.Integer("Units")
|
||||
price_total = fields.Float(
|
||||
"Price Total", compute="_compute_price_total", store=True
|
||||
)
|
||||
price_unit = fields.Float(
|
||||
"Unit Price", related="service_id.price_unit", readonly=True, store=True
|
||||
"Unit Price",
|
||||
digits=("Product Price"),
|
||||
)
|
||||
price_day_subtotal = fields.Monetary(
|
||||
string="Subtotal",
|
||||
readonly=True,
|
||||
store=True,
|
||||
compute="_compute_day_amount_service",
|
||||
)
|
||||
price_day_total = fields.Monetary(
|
||||
string="Total", readonly=True, store=True, compute="_compute_day_amount_service"
|
||||
)
|
||||
price_day_tax = fields.Float(
|
||||
string="Taxes Amount",
|
||||
readonly=True,
|
||||
store=True,
|
||||
compute="_compute_day_amount_service",
|
||||
)
|
||||
currency_id = fields.Many2one(
|
||||
related="service_id.currency_id", store=True, string="Currency", readonly=True
|
||||
)
|
||||
room_id = fields.Many2one(
|
||||
string="Room", related="service_id.reservation_id", readonly=True, store=True
|
||||
)
|
||||
discount = fields.Float(
|
||||
"Discount", related="service_id.discount", readonly=True, store=True
|
||||
string="Discount (%)",
|
||||
digits=("Discount"),
|
||||
default=0.0,
|
||||
compute="_compute_discount",
|
||||
readonly=False,
|
||||
store=True,
|
||||
)
|
||||
cancel_discount = fields.Float(
|
||||
"Cancelation Discount", compute="_compute_cancel_discount"
|
||||
)
|
||||
|
||||
# Compute and Search methods
|
||||
@api.depends("day_qty", "service_id.price_total")
|
||||
def _compute_price_total(self):
|
||||
@api.depends("day_qty", "discount", "price_unit", "tax_ids")
|
||||
def _compute_day_amount_service(self):
|
||||
for line in self:
|
||||
amount_service = line.price_unit
|
||||
if amount_service > 0:
|
||||
currency = line.service_id.currency_id
|
||||
product = line.product_id
|
||||
price = amount_service * (1 - (line.discount or 0.0) * 0.01)
|
||||
# REVIEW: line.day_qty is not the total qty (the total is on service_id)
|
||||
taxes = line.tax_ids.compute_all(
|
||||
price, currency, line.day_qty, product=product
|
||||
)
|
||||
line.update(
|
||||
{
|
||||
"price_day_tax": sum(
|
||||
t.get("amount", 0.0) for t in taxes.get("taxes", [])
|
||||
),
|
||||
"price_day_total": taxes["total_included"],
|
||||
"price_day_subtotal": taxes["total_excluded"],
|
||||
}
|
||||
)
|
||||
else:
|
||||
line.update(
|
||||
{
|
||||
"price_day_tax": 0,
|
||||
"price_day_total": 0,
|
||||
"price_day_subtotal": 0,
|
||||
}
|
||||
)
|
||||
|
||||
@api.depends("service_id.reservation_id", "service_id.reservation_id.discount")
|
||||
def _compute_discount(self):
|
||||
"""
|
||||
Used to reports
|
||||
On board service the line discount is always
|
||||
equal to reservation line discount
|
||||
"""
|
||||
for record in self:
|
||||
if record.service_id.product_qty != 0:
|
||||
record.price_total = (
|
||||
record.service_id.price_total * record.day_qty
|
||||
) / record.service_id.product_qty
|
||||
else:
|
||||
record.price_total = 0
|
||||
if record.is_board_service:
|
||||
record.discount = (
|
||||
record.service_id.reservation_id.reservation_line_ids.filtered(
|
||||
lambda l: l.date == record.date
|
||||
).discount
|
||||
)
|
||||
elif not record.discount:
|
||||
record.discount = 0
|
||||
|
||||
# TODO: Refact method and allowed cancelled single days
|
||||
@api.depends("service_id.reservation_id.cancelled_reason")
|
||||
def _compute_cancel_discount(self):
|
||||
for line in self:
|
||||
line.cancel_discount = 0
|
||||
# TODO: Review cancel logic
|
||||
# reservation = line.reservation_id.reservation_id
|
||||
# pricelist = reservation.pricelist_id
|
||||
# if reservation.state == "cancelled":
|
||||
# if (
|
||||
# reservation.cancelled_reason
|
||||
# and pricelist
|
||||
# and pricelist.cancelation_rule_id
|
||||
# ):
|
||||
# date_start_dt = fields.Date.from_string(
|
||||
# reservation.checkin
|
||||
# )
|
||||
# date_end_dt = fields.Date.from_string(
|
||||
# reservation.checkout
|
||||
# )
|
||||
# days = abs((date_end_dt - date_start_dt).days)
|
||||
# rule = pricelist.cancelation_rule_id
|
||||
# if reservation.cancelled_reason == "late":
|
||||
# discount = 100 - rule.penalty_late
|
||||
# if rule.apply_on_late == "first":
|
||||
# days = 1
|
||||
# elif rule.apply_on_late == "days":
|
||||
# days = rule.days_late
|
||||
# elif reservation.cancelled_reason == "noshow":
|
||||
# discount = 100 - rule.penalty_noshow
|
||||
# if rule.apply_on_noshow == "first":
|
||||
# days = 1
|
||||
# elif rule.apply_on_noshow == "days":
|
||||
# days = rule.days_late - 1
|
||||
# elif reservation.cancelled_reason == "intime":
|
||||
# discount = 100
|
||||
|
||||
# checkin = reservation.checkin
|
||||
# dates = []
|
||||
# for i in range(0, days):
|
||||
# dates.append(
|
||||
# (
|
||||
# fields.Date.from_string(checkin) + timedelta(days=i)
|
||||
# ).strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
# )
|
||||
# reservation.reservation_line_ids.filtered(
|
||||
# lambda r: r.date in dates
|
||||
# ).update({"cancel_discount": discount})
|
||||
# reservation.reservation_line_ids.filtered(
|
||||
# lambda r: r.date not in dates
|
||||
# ).update({"cancel_discount": 100})
|
||||
# else:
|
||||
# reservation.reservation_line_ids.update({"cancel_discount": 0})
|
||||
# else:
|
||||
# reservation.reservation_line_ids.update({"cancel_discount": 0})
|
||||
|
||||
# Constraints and onchanges
|
||||
@api.constrains("day_qty")
|
||||
|
||||
Reference in New Issue
Block a user