This commit is contained in:
oscar alvarez 2023-11-05 15:19:13 -05:00
parent 69b81ff64c
commit e5849a3ef4
4 changed files with 63 additions and 27 deletions

View File

@ -1589,7 +1589,7 @@ class FolioCharge(Workflow, ModelSQL, ModelView):
unit_price = fields.Numeric('Unit Price', digits=(16, 2),
required=True)
unit_price_w_tax = fields.Function(fields.Numeric('Unit Price w Tax',
digits=(16, 2)), 'get_unit_price_w_tax')
digits=(16, 2)), 'get_unit_price_w_tax', setter='set_unit_price_w_tax')
order = fields.Char('Order')
description = fields.Char('Description', depends=['product'])
state = fields.Selection(INVOICE_STATES, 'Invoice State', readonly=True)
@ -1746,6 +1746,20 @@ class FolioCharge(Workflow, ModelSQL, ModelView):
res = self.quantity * self.unit_price
return res
@classmethod
def set_unit_price_w_tax(cls, charges, name, value):
Tax = Pool().get('account.tax')
to_write = []
rvalue = Decimal(value).quantize('0.01')
for charge in charges:
taxes = charge.product.customer_taxes_used
unit_price = Tax.reverse_compute(rvalue, taxes)
unit_price = Decimal(unit_price).quantize('0.01')
to_write.extend([[charge], {
'unit_price': unit_price,
}])
cls.write(*to_write)
def get_amount_w_tax(self, name=None):
res = 0
if self.quantity and self.unit_price_w_tax:

View File

@ -96,21 +96,20 @@ class RatePlan(Workflow, ModelSQL, ModelView):
@classmethod
def best_price_list(cls, args):
"""Get the best available rate for the context
"""Get the best available price list for the context
arrival_date: Date
departure_date: Date
departure_date: Date (Optional)
rate_plan: Required
occupancy_rate for the arrival_date: Computed
occupancy_rate for the arrival_date: Computed (Optional)
"""
pool = Pool()
Calendar = pool.get('hotel.rate_plan.calendar')
PriceList = pool.get('product.price_list')
Config = pool.get('hotel.configuration')
rate_plan_id = args['rate_plan_id']
rate_plan_id = args.get('rate_plan_id', None)
arrival_date = args['arrival_date']
calendars = Calendar.search([
('start_date', '>=', args['arrival_date']),
('start_date', '>=', arrival_date),
('end_date', '<=', arrival_date),
])
if calendars:
@ -118,7 +117,11 @@ class RatePlan(Workflow, ModelSQL, ModelView):
else:
season = 'middle'
rate_plan = cls(rate_plan_id)
if rate_plan_id:
rate_plan = cls(rate_plan_id)
else:
return {}
price_list = None
for pl in rate_plan.price_lists:
if pl.season == season:
@ -133,13 +136,27 @@ class RatePlan(Workflow, ModelSQL, ModelView):
# This is in deprecation
price_list = rate_plan.price_list
if not price_list:
raise UserError(gettext('hotel.msg_missing_default_price_list'))
# Here add compute of price_list with variations of Context
# including occupancy_rate and IA
return price_list.id
# Here add compute of price_list with variations of Context,
# minima estancia, dia de la semana, desayuno incluido, etc
# including occupancy_rate and IA analysis of market
return {'id': price_list.id, 'rec_name': price_list.name}
@classmethod
def best_price(cls, accommodation, price_list):
"""
Get the best available rate for the context:::
price_list: Required
accommodation: Required (product)
Return sale price taxed for accomodation
"""
PriceList = Pool().get('product.price_list')
res = accommodation.sale_price_taxed
if price_list:
pass
return res
class RatePlanPriceList(ModelSQL):

33
room.py
View File

@ -164,31 +164,32 @@ class Room(Workflow, ModelSQL, ModelView):
pass
@classmethod
def available_by_classification(cls, start_date, end_date):
def available_by_classification(cls, start_date, end_date, rate_plan=None):
pool = Pool()
Classification = pool.get('hotel.room.classification')
# Classification = pool.get('hotel.room.classification')
Folio = pool.get('hotel.folio')
RatePlan = pool.get('hotel.rate_plan')
fmt = "%Y-%m-%d"
plan = {}
# FIXME: Add estimation of plan based on arrival date
plans = RatePlan.search([])
if plans:
_plan = plans[0]
plan = {"id": _plan.id, "rec_name": _plan.price_list.name }
# FIXME: Add estimation of price_list based on plan and arrival date
args = {
'rate_plan_id': rate_plan,
'arrival_date': start_date,
}
price_list = RatePlan.best_price_list(args)
if isinstance(start_date, str):
start_date = datetime.strptime(start_date, fmt).date()
end_date = datetime.strptime(end_date, fmt).date()
all_rooms = [ro['id'] for ro in Room.search_read([], fields_names=[])]
rooms_available = Folio.get_available_rooms(start_date, end_date, all_rooms)
classifications = Classification.search_read([],
fields_names=['id', 'name'])
rooms_available = Folio.get_available_rooms(
start_date, end_date, all_rooms)
clssf = {}
rooms = cls.browse(rooms_available)
best_price = RatePlan.best_price
for room in rooms:
product = room.main_accommodation.products[0]
price_taxed = best_price(product, price_list)
_room = {
"id": room.id,
"name": room.name,
@ -202,11 +203,15 @@ class Room(Workflow, ModelSQL, ModelView):
clssf[product.id]['rooms'].append(_room)
except:
clssf[product.id] = {
"product": {"id": product.id, "name": product.name, "images": [img.image_url for img in product.images]},
"sale_price_taxed": product.sale_price_taxed,
"product": {
"id": product.id,
"name": product.name,
"images": [img.image_url for img in product.images]
},
"sale_price_taxed": price_taxed,
"available": [1],
"rooms": [_room],
"rate_plan": plan,
"rate_plan": price_list, # ????
}
for k, v in clssf.items():

View File

@ -1,5 +1,5 @@
[tryton]
version=6.0.124
version=6.0.125
depends:
party
company