Fix
This commit is contained in:
parent
e73def6507
commit
dda7139f06
27
booking.py
27
booking.py
|
@ -348,25 +348,20 @@ class Booking(Workflow, ModelSQL, ModelView):
|
||||||
@classmethod
|
@classmethod
|
||||||
def compute_taxes(cls, _taxes, unit_price, quantity, currency=None):
|
def compute_taxes(cls, _taxes, unit_price, quantity, currency=None):
|
||||||
Tax = Pool().get('account.tax')
|
Tax = Pool().get('account.tax')
|
||||||
print("_taxes...", _taxes)
|
|
||||||
l_taxes = Tax.compute(list(_taxes), unit_price, quantity)
|
l_taxes = Tax.compute(list(_taxes), unit_price, quantity)
|
||||||
taxes = {}
|
taxes = []
|
||||||
for tax in l_taxes:
|
for tax in l_taxes:
|
||||||
taxline = TaxableMixin._compute_tax_line(**tax)
|
taxline = TaxableMixin._compute_tax_line(**tax)
|
||||||
# Base must always be rounded per folio as there will
|
# Base must always be rounded per folio as there will
|
||||||
# be one tax folio per taxable_lines
|
# be one tax folio per taxable_lines
|
||||||
if currency:
|
if currency:
|
||||||
taxline['base'] = currency.round(taxline['base'])
|
taxline['base'] = currency.round(taxline['base'])
|
||||||
if taxline not in taxes:
|
taxes.append(taxline)
|
||||||
taxes[taxline] = taxline
|
|
||||||
else:
|
|
||||||
taxes[taxline]['base'] += taxline['base']
|
|
||||||
taxes[taxline]['amount'] += taxline['amount']
|
|
||||||
return taxes
|
return taxes
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _get_taxes(cls, lines):
|
def _get_taxes(cls, lines):
|
||||||
taxes = {}
|
taxes = []
|
||||||
with Transaction().set_context({}):
|
with Transaction().set_context({}):
|
||||||
for folio in lines:
|
for folio in lines:
|
||||||
currency = folio.booking.currency
|
currency = folio.booking.currency
|
||||||
|
@ -374,7 +369,7 @@ class Booking(Workflow, ModelSQL, ModelView):
|
||||||
continue
|
continue
|
||||||
_taxes = folio.product.customer_taxes_used
|
_taxes = folio.product.customer_taxes_used
|
||||||
if not folio.occupancy and not folio.charges:
|
if not folio.occupancy and not folio.charges:
|
||||||
taxes.update(cls.compute_taxes(
|
taxes.extend(cls.compute_taxes(
|
||||||
_taxes,
|
_taxes,
|
||||||
folio.unit_price,
|
folio.unit_price,
|
||||||
folio.nights_quantity,
|
folio.nights_quantity,
|
||||||
|
@ -383,16 +378,23 @@ class Booking(Workflow, ModelSQL, ModelView):
|
||||||
else:
|
else:
|
||||||
for occ in folio.occupancy:
|
for occ in folio.occupancy:
|
||||||
if not occ.charge:
|
if not occ.charge:
|
||||||
taxes.update(cls.compute_taxes(
|
taxes.extend(cls.compute_taxes(
|
||||||
_taxes, occ.unit_price, 1, currency))
|
_taxes, occ.unit_price, 1, currency))
|
||||||
|
|
||||||
for charge in folio.charges:
|
for charge in folio.charges:
|
||||||
taxes.update(cls.compute_taxes(
|
taxes.extend(cls.compute_taxes(
|
||||||
charge.taxes,
|
charge.taxes,
|
||||||
charge.unit_price,
|
charge.unit_price,
|
||||||
charge.quantity,
|
charge.quantity,
|
||||||
currency))
|
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):
|
def get_invoices(self, name=None):
|
||||||
res = []
|
res = []
|
||||||
|
@ -1232,6 +1234,7 @@ class Booking(Workflow, ModelSQL, ModelView):
|
||||||
|
|
||||||
def get_tax_amount(self, name):
|
def get_tax_amount(self, name):
|
||||||
taxes_computed = Booking._get_taxes(self.lines)
|
taxes_computed = Booking._get_taxes(self.lines)
|
||||||
|
print('taxes_computed.....', taxes_computed)
|
||||||
res = sum([t['amount'] for t in taxes_computed], _ZERO)
|
res = sum([t['amount'] for t in taxes_computed], _ZERO)
|
||||||
return self.currency.round(res)
|
return self.currency.round(res)
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,8 @@ class Configuration(ModelSQL, ModelView):
|
||||||
storage_by_default = fields.Many2One('stock.location', 'Storage By Default',
|
storage_by_default = fields.Many2One('stock.location', 'Storage By Default',
|
||||||
domain=[('type', '=', 'storage')], required=False)
|
domain=[('type', '=', 'storage')], required=False)
|
||||||
payment_term = fields.Many2One('account.invoice.payment_term',
|
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',
|
children_policies = fields.One2Many('hotel.children_policy',
|
||||||
'configuration', 'Children Policies')
|
'configuration', 'Children Policies')
|
||||||
nationality = fields.Many2One('country.country', 'Default Nationality')
|
nationality = fields.Many2One('country.country', 'Default Nationality')
|
||||||
|
|
|
@ -117,5 +117,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<record model="ir.message" id="msg_the_accommodation_not_charged">
|
<record model="ir.message" id="msg_the_accommodation_not_charged">
|
||||||
<field name="text">The accommodation is not charged!</field>
|
<field name="text">The accommodation is not charged!</field>
|
||||||
</record>
|
</record>
|
||||||
|
<record model="ir.message" id="msg_missing_default_price_list">
|
||||||
|
<field name="text">Missing default price list!</field>
|
||||||
|
</record>
|
||||||
</data>
|
</data>
|
||||||
</tryton>
|
</tryton>
|
||||||
|
|
60
rate_plan.py
60
rate_plan.py
|
@ -2,8 +2,9 @@
|
||||||
# this repository contains the full copyright notices and license terms.
|
# this repository contains the full copyright notices and license terms.
|
||||||
|
|
||||||
from trytond.model import ModelView, ModelSQL, fields, Workflow
|
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):
|
class RatePlanCalendar(ModelSQL, ModelView):
|
||||||
|
@ -64,8 +65,9 @@ class RatePlan(Workflow, ModelSQL, ModelView):
|
||||||
saturday = fields.Char('Saturday', help="Example, -15%")
|
saturday = fields.Char('Saturday', help="Example, -15%")
|
||||||
sunday = fields.Char('Sunday', help="Example, -15%")
|
sunday = fields.Char('Sunday', help="Example, -15%")
|
||||||
holiday = fields.Char('Holiday', help="Example, -15%")
|
holiday = fields.Char('Holiday', help="Example, -15%")
|
||||||
price_list = fields.Many2One('product.price_list', 'Price List',
|
price_list = fields.Many2One('product.price_list', 'Default Price List',
|
||||||
required=False)
|
required=True)
|
||||||
|
# Add children policy
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
|
@ -92,16 +94,52 @@ class RatePlan(Workflow, ModelSQL, ModelView):
|
||||||
def default_active():
|
def default_active():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def best_available_rate(cls, context):
|
def best_price_list(cls, args):
|
||||||
"""Get the best available rate for the context
|
"""Get the best available rate for the context
|
||||||
arrival_date: Computed
|
arrival_date: Date
|
||||||
departure_date: Computed
|
departure_date: Date
|
||||||
kind (rate_plan): Required
|
rate_plan: Required
|
||||||
occupancy_rate for the arrival_date: Computed
|
occupancy_rate for the arrival_date: Computed
|
||||||
"""
|
"""
|
||||||
# rate_plan: Required
|
pool = Pool()
|
||||||
pass
|
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):
|
class RatePlanPriceList(ModelSQL):
|
||||||
|
|
|
@ -42,6 +42,10 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="charge_sequence"/>
|
<field name="charge_sequence"/>
|
||||||
<label name="offset_journal"/>
|
<label name="offset_journal"/>
|
||||||
<field 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">
|
<group col="6" string="Accounting" id="account" colspan="4">
|
||||||
<label name="accounting_revenue"/>
|
<label name="accounting_revenue"/>
|
||||||
<field name="accounting_revenue"/>
|
<field name="accounting_revenue"/>
|
||||||
|
@ -52,6 +56,4 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
</group>
|
</group>
|
||||||
<field name="default_charges" colspan="2"/>
|
<field name="default_charges" colspan="2"/>
|
||||||
<field name="children_policies" colspan="2"/>
|
<field name="children_policies" colspan="2"/>
|
||||||
<label name="token_siat"/>
|
|
||||||
<field name="token_siat"/>
|
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -18,6 +18,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||||
<field name="minimum_advance"/>
|
<field name="minimum_advance"/>
|
||||||
<label name="cancellation_policies"/>
|
<label name="cancellation_policies"/>
|
||||||
<field name="cancellation_policies"/>
|
<field name="cancellation_policies"/>
|
||||||
|
<label name="price_list"/>
|
||||||
|
<field name="price_list"/>
|
||||||
<group string="Food" col="8" id="food" colspan="4">
|
<group string="Food" col="8" id="food" colspan="4">
|
||||||
<label name="all_inclusive"/>
|
<label name="all_inclusive"/>
|
||||||
<field name="all_inclusive"/>
|
<field name="all_inclusive"/>
|
||||||
|
|
Loading…
Reference in New Issue