Add taxes

This commit is contained in:
oscar alvarez 2022-08-03 22:36:12 -05:00
parent 6cd24811ff
commit 394074c52d
7 changed files with 90 additions and 18 deletions

View File

@ -60,6 +60,7 @@ def register():
folio.StatisticsByMonthStart, folio.StatisticsByMonthStart,
folio.Folio, folio.Folio,
folio.FolioCharge, folio.FolioCharge,
folio.HotelFolioTax,
folio.FolioStockMove, folio.FolioStockMove,
folio.OpenMigrationStart, folio.OpenMigrationStart,
stock.Move, stock.Move,

View File

@ -15,6 +15,7 @@ from trytond.transaction import Transaction
from trytond.pool import Pool from trytond.pool import Pool
from trytond.exceptions import UserError from trytond.exceptions import UserError
from trytond.i18n import gettext from trytond.i18n import gettext
from trytond.modules.account.tax import TaxableMixin
from .constants import ( from .constants import (
STATE_BOOKING, REGISTRATION_STATE, REASON, GUARANTEE, SATISFACTION, STATE_BOOKING, REGISTRATION_STATE, REASON, GUARANTEE, SATISFACTION,
MEDIA, PLAN, INVOICE_METHOD, COMPLEMENTARY, PAYMENT_METHOD_CHANNEL, MEDIA, PLAN, INVOICE_METHOD, COMPLEMENTARY, PAYMENT_METHOD_CHANNEL,
@ -65,7 +66,6 @@ class Booking(Workflow, ModelSQL, ModelView):
'invisible': ~Bool(Eval('complementary')), 'invisible': ~Bool(Eval('complementary')),
'required': Bool(Eval('complementary')), 'required': Bool(Eval('complementary')),
}) })
# rename to channel
channel = fields.Many2One('hotel.channel', 'Channel', channel = fields.Many2One('hotel.channel', 'Channel',
states={ states={
'invisible': Eval('media') != 'ota', 'invisible': Eval('media') != 'ota',
@ -291,6 +291,48 @@ class Booking(Workflow, ModelSQL, ModelView):
now = datetime.now() now = datetime.now()
return now return now
def _round_taxes(self, taxes):
if not self.currency:
return
for taxline in taxes.values():
taxline['amount'] = self.currency.round(taxline['amount'])
def _get_taxes(self):
pool = Pool()
Tax = pool.get('account.tax')
Configuration = pool.get('account.configuration')
taxes = {}
with Transaction().set_context({}):
config = Configuration(1)
tax_rounding = config.get_multivalue('tax_rounding')
def compute(_taxes, unit_price, quantity):
l_taxes = Tax.compute(Tax.browse(_taxes), unit_price, quantity)
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 self.currency:
taxline['base'] = self.currency.round(taxline['base'])
if taxline not in taxes:
taxes[taxline] = taxline
else:
taxes[taxline]['base'] += taxline['base']
taxes[taxline]['amount'] += taxline['amount']
if tax_rounding == 'line':
self._round_taxes(taxes)
for folio in self.lines:
compute(folio.taxes, folio.unit_price, folio.nights_quantity)
for charge in folio.charges:
compute(folio.taxes, charge.unit_price, charge.quantity)
if tax_rounding == 'document':
self._round_taxes(taxes)
return taxes
def get_invoices(self, name=None): def get_invoices(self, name=None):
res = [] res = []
for folio in self.lines: for folio in self.lines:
@ -969,22 +1011,24 @@ class Booking(Workflow, ModelSQL, ModelView):
return res return res
def get_tax_amount(self, name): def get_tax_amount(self, name):
Tax = Pool().get('account.tax') # Tax = Pool().get('account.tax')
Booking = Pool().get('hotel.booking') # Booking = Pool().get('hotel.booking')
#
res = _ZERO # res = _ZERO
for line in self.lines: # for folio in self.lines:
taxes_ids = Booking.get_taxes(line.product) # taxes_ids = Booking.get_taxes(line.product)
if taxes_ids: # if taxes_ids:
taxes = Tax.browse(taxes_ids) # taxes = Tax.browse(taxes_ids)
tax_list = Tax.compute( # tax_list = Tax.compute(
taxes, line.unit_price or _ZERO, line.nights_quantity or 0 # taxes, line.unit_price or _ZERO, line.nights_quantity or 0
) # )
#
tax_amount = sum([t['amount'] for t in tax_list], _ZERO) # tax_amount = sum([t['amount'] for t in tax_list], _ZERO)
res += tax_amount # res += tax_amount
#
res = Decimal(round(res, 2)) # res = Decimal(round(res, 2))
taxes_computed = self._get_taxes()
res = sum([t['amount'] for t in taxes_computed], _ZERO)
return res return res
def get_untaxed_amount(self, name): def get_untaxed_amount(self, name):

View File

@ -140,6 +140,13 @@ class Folio(ModelSQL, ModelView):
stock_moves = fields.Function(fields.One2Many('stock.move', 'origin', 'Moves', stock_moves = fields.Function(fields.One2Many('stock.move', 'origin', 'Moves',
readonly=True), 'get_stock_moves') readonly=True), 'get_stock_moves')
vehicle_plate = fields.Char('Vehicle Plate') vehicle_plate = fields.Char('Vehicle Plate')
taxes = fields.Many2Many('hotel.folio-account.tax', 'folio', 'tax', 'Taxes',
order=[('tax.sequence', 'ASC'), ('tax.id', 'ASC')],
domain=[('parent', '=', None), ['OR',
('group', '=', None),
('group.kind', 'in', ['sale', 'both'])],
],
)
@classmethod @classmethod
def __setup__(cls): def __setup__(cls):
@ -228,6 +235,10 @@ class Folio(ModelSQL, ModelView):
gettext('hotel.msg_room_no_clean', s=self.room.name) gettext('hotel.msg_room_no_clean', s=self.room.name)
) )
# def get_tax_amount(self):
# return sum(
# (v['amount'] for v in self._get_taxes().values()), Decimal(0))
@classmethod @classmethod
@ModelView.button @ModelView.button
def check_out(cls, records): def check_out(cls, records):
@ -1737,3 +1748,13 @@ class RegistrationCardReport(Report):
_records.append(rec) _records.append(rec)
report_context['records'] = _records report_context['records'] = _records
return report_context return report_context
class HotelFolioTax(ModelSQL):
'Hotel Folio - Tax'
__name__ = 'hotel.folio-account.tax'
_table = 'hotel_folio_account_tax'
folio = fields.Many2One('hotel.folio', 'Folio', ondelete='CASCADE',
select=True, required=True)
tax = fields.Many2One('account.tax', 'Tax', ondelete='RESTRICT',
select=True, required=True)

Binary file not shown.

View File

@ -1,5 +1,5 @@
[tryton] [tryton]
version=6.0.25 version=6.0.26
depends: depends:
party party
company company

View File

@ -37,6 +37,9 @@ this repository contains the full copyright notices and license terms. -->
<field name="charges" colspan="4"/> <field name="charges" colspan="4"/>
<field name="guests" colspan="4"/> <field name="guests" colspan="4"/>
</page> </page>
<page string="Taxes" id="folio_taxes">
<field name="taxes" colspan="4"/>
</page>
<page string="Stock" id="stock"> <page string="Stock" id="stock">
<field name="stock_moves" colspan="4"/> <field name="stock_moves" colspan="4"/>
</page> </page>

View File

@ -35,6 +35,9 @@ this repository contains the full copyright notices and license terms. -->
<field name="charges" colspan="4"/> <field name="charges" colspan="4"/>
<field name="guests" colspan="4"/> <field name="guests" colspan="4"/>
</page> </page>
<page string="Taxes" id="folio_taxes">
<field name="taxes" colspan="4"/>
</page>
<page string="Stock" id="folio_stock"> <page string="Stock" id="folio_stock">
<label name="storage"/> <label name="storage"/>
<field name="storage"/> <field name="storage"/>