This commit is contained in:
oscar alvarez 2023-11-04 13:54:12 -05:00
parent e73def6507
commit dda7139f06
6 changed files with 75 additions and 26 deletions

View File

@ -348,25 +348,20 @@ class Booking(Workflow, ModelSQL, ModelView):
@classmethod
def compute_taxes(cls, _taxes, unit_price, quantity, currency=None):
Tax = Pool().get('account.tax')
print("_taxes...", _taxes)
l_taxes = Tax.compute(list(_taxes), unit_price, quantity)
taxes = {}
taxes = []
for tax in l_taxes:
taxline = TaxableMixin._compute_tax_line(**tax)
# Base must always be rounded per folio as there will
# be one tax folio per taxable_lines
if currency:
taxline['base'] = currency.round(taxline['base'])
if taxline not in taxes:
taxes[taxline] = taxline
else:
taxes[taxline]['base'] += taxline['base']
taxes[taxline]['amount'] += taxline['amount']
taxes.append(taxline)
return taxes
@classmethod
def _get_taxes(cls, lines):
taxes = {}
taxes = []
with Transaction().set_context({}):
for folio in lines:
currency = folio.booking.currency
@ -374,7 +369,7 @@ class Booking(Workflow, ModelSQL, ModelView):
continue
_taxes = folio.product.customer_taxes_used
if not folio.occupancy and not folio.charges:
taxes.update(cls.compute_taxes(
taxes.extend(cls.compute_taxes(
_taxes,
folio.unit_price,
folio.nights_quantity,
@ -383,16 +378,23 @@ class Booking(Workflow, ModelSQL, ModelView):
else:
for occ in folio.occupancy:
if not occ.charge:
taxes.update(cls.compute_taxes(
taxes.extend(cls.compute_taxes(
_taxes, occ.unit_price, 1, currency))
for charge in folio.charges:
taxes.update(cls.compute_taxes(
taxes.extend(cls.compute_taxes(
charge.taxes,
charge.unit_price,
charge.quantity,
currency))
return taxes
_taxes = {}
for ctax in taxes:
if ctax['tax'] not in _taxes.keys():
_taxes[ctax['tax']] = ctax
else:
_taxes[ctax['tax']]['base'] += ctax['base']
_taxes[ctax['tax']]['amount'] += ctax['amount']
return _taxes.values()
def get_invoices(self, name=None):
res = []
@ -1232,6 +1234,7 @@ class Booking(Workflow, ModelSQL, ModelView):
def get_tax_amount(self, name):
taxes_computed = Booking._get_taxes(self.lines)
print('taxes_computed.....', taxes_computed)
res = sum([t['amount'] for t in taxes_computed], _ZERO)
return self.currency.round(res)

View File

@ -77,7 +77,8 @@ class Configuration(ModelSQL, ModelView):
storage_by_default = fields.Many2One('stock.location', 'Storage By Default',
domain=[('type', '=', 'storage')], required=False)
payment_term = fields.Many2One('account.invoice.payment_term',
'Payment Term')
'Default Payment Term')
price_list = fields.Many2One('product.price_list', 'Default Price List')
children_policies = fields.One2Many('hotel.children_policy',
'configuration', 'Children Policies')
nationality = fields.Many2One('country.country', 'Default Nationality')

View File

@ -117,5 +117,8 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_the_accommodation_not_charged">
<field name="text">The accommodation is not charged!</field>
</record>
<record model="ir.message" id="msg_missing_default_price_list">
<field name="text">Missing default price list!</field>
</record>
</data>
</tryton>

View File

@ -2,8 +2,9 @@
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields, Workflow
# from trytond.pyson import Eval, Bool
# from trytond.pool import Pool
from trytond.pool import Pool
from trytond.exceptions import UserError
from trytond.i18n import gettext
class RatePlanCalendar(ModelSQL, ModelView):
@ -64,8 +65,9 @@ class RatePlan(Workflow, ModelSQL, ModelView):
saturday = fields.Char('Saturday', help="Example, -15%")
sunday = fields.Char('Sunday', help="Example, -15%")
holiday = fields.Char('Holiday', help="Example, -15%")
price_list = fields.Many2One('product.price_list', 'Price List',
required=False)
price_list = fields.Many2One('product.price_list', 'Default Price List',
required=True)
# Add children policy
@classmethod
def __setup__(cls):
@ -92,16 +94,52 @@ class RatePlan(Workflow, ModelSQL, ModelView):
def default_active():
return True
@staticmethod
def best_available_rate(cls, context):
@classmethod
def best_price_list(cls, args):
"""Get the best available rate for the context
arrival_date: Computed
departure_date: Computed
kind (rate_plan): Required
arrival_date: Date
departure_date: Date
rate_plan: Required
occupancy_rate for the arrival_date: Computed
"""
# rate_plan: Required
pass
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']
arrival_date = args['arrival_date']
calendars = Calendar.search([
('start_date', '>=', args['arrival_date']),
('end_date', '<=', arrival_date),
])
if calendars:
season = calendars[0].season
else:
season = 'middle'
rate_plan = cls(rate_plan_id)
price_list = None
for pl in rate_plan.price_lists:
if pl.season == season:
price_list = pl
break
if not price_list:
config = Config.get_configuration()
if config.price_list:
price_list = config.price_list
else:
# 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
class RatePlanPriceList(ModelSQL):

View File

@ -42,6 +42,10 @@ this repository contains the full copyright notices and license terms. -->
<field name="charge_sequence"/>
<label name="offset_journal"/>
<field name="offset_journal"/>
<label name="price_list"/>
<field name="price_list"/>
<label name="token_siat"/>
<field name="token_siat"/>
<group col="6" string="Accounting" id="account" colspan="4">
<label name="accounting_revenue"/>
<field name="accounting_revenue"/>
@ -52,6 +56,4 @@ this repository contains the full copyright notices and license terms. -->
</group>
<field name="default_charges" colspan="2"/>
<field name="children_policies" colspan="2"/>
<label name="token_siat"/>
<field name="token_siat"/>
</form>

View File

@ -18,6 +18,8 @@ this repository contains the full copyright notices and license terms. -->
<field name="minimum_advance"/>
<label name="cancellation_policies"/>
<field name="cancellation_policies"/>
<label name="price_list"/>
<field name="price_list"/>
<group string="Food" col="8" id="food" colspan="4">
<label name="all_inclusive"/>
<field name="all_inclusive"/>