This commit is contained in:
oscar alvarez 2022-07-08 15:09:07 -05:00
parent bae79e55af
commit 443c20a66f
6 changed files with 97 additions and 16 deletions

View File

@ -17,6 +17,7 @@ from . import service
from . import policy
from . import dash
from . import invoice
from . import statement
def register():
@ -39,6 +40,7 @@ def register():
booking.ManagerStart,
booking.BookingStatementLine,
booking.StatementPaymentForm,
statement.StatementLine,
housekeeping.Housekeeping,
housekeeping.HousekeepingCleaningType,
party.Party,

View File

@ -129,8 +129,6 @@ class Booking(Workflow, ModelSQL, ModelView):
ota_booking_code = fields.Char('OTA Code', select=True,
states={'invisible': Eval('media') != 'ota'}
)
# payments = fields.One2Many('account.statement.line', 'booking', 'Payments')
# readonly=True)
payments = fields.Many2Many('hotel.booking-statement.line', 'booking',
'statement_line', 'Payments', states=STATES_CHECKIN, readonly=True,
depends=['party'])
@ -385,8 +383,10 @@ class Booking(Workflow, ModelSQL, ModelView):
# cls.bill_to_channel(records)
for rec in records:
cls.create_invoice(rec.lines)
# rec.add_payments_invoice()
cls.check_finished(records)
@classmethod
def bill_to_channel(cls, records):
for rec in records:
@ -682,6 +682,11 @@ class Booking(Workflow, ModelSQL, ModelView):
except:
pass
# def add_payments_invoice(self):
# for payment in self.payments:
# for invoice in self.invoices:
# if invoice.
@classmethod
def create_invoice(cls, folios):
pool = Pool()
@ -692,6 +697,8 @@ class Booking(Workflow, ModelSQL, ModelView):
config = Configuration.get_configuration()
invoice = {}
_folios, _charges = cls.pending_to_invoice(folios)
booking = folios[0].booking
if not _folios and not _charges:
return
@ -829,9 +836,13 @@ class Booking(Workflow, ModelSQL, ModelView):
def get_total_advance(self, name):
Advance = Pool().get('hotel.booking-account.voucher')
Payments = Pool().get('hotel.booking-statement.line')
vouchers = Advance.search([('booking', '=', self.id)])
# payments = Payments.search([('booking', '=', self.id)])
res = sum([voucher.voucher.amount_to_pay for voucher in vouchers])
return res
payments = sum([pay.amount for pay in self.payments])
return res + payments
def get_pending_to_pay(self, name):
if self.total_amount:
@ -1733,14 +1744,12 @@ class ManagerReport(Report):
if k in ('direct', 'ota'):
rooms_saled.append(room_qty)
print(guests_by_country)
available_nights = total_rooms * delta_days
beds_capacity = []
for room in rooms:
beds_capacity.append(room.main_accommodation.accommodation_capacity or 0)
available_beds = sum(beds_capacity) * delta_days
print(total_rooms, delta_days)
average_price = sum(total_income) / sum(rooms_saled)
report_context['records'] = channels.values()
report_context['rooms_occupied'] = sum(rooms_occupied)
@ -1869,6 +1878,4 @@ class WizardStatementPayment(Wizard):
'statement_line': line.id,
}])
booking.save()
return 'end'

Binary file not shown.

View File

@ -1,20 +1,69 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.pool import PoolMeta
# from trytond.model import fields
# from trytond.pyson import Eval
from datetime import date
from trytond.pool import PoolMeta, Pool
class Invoice(metaclass=PoolMeta):
__name__ = 'account.invoice'
def auto_reconcile(self):
reconcile_lines = []
Reconciliation = Pool().get('account.move.reconciliation')
account_reconcile_id = self.account.id
balance = []
for ml in self.payment_lines:
if not ml.reconciliation and ml.account.id == account_reconcile_id:
reconcile_lines.append(ml)
balance.append(ml.debit - ml.credit)
for ml in self.move.lines:
if ml.account.id == account_reconcile_id:
reconcile_lines.append(ml)
balance.append(ml.debit - ml.credit)
if sum(balance) != 0:
return
if reconcile_lines:
Reconciliation.create([{
'lines': [('add', reconcile_lines)],
'date': date.today(),
}])
@classmethod
def post(cls, invoices):
super(Invoice, cls).post(invoices)
for invoice in invoices:
invoice.set_booking_payments()
# FIXME: esta creando notas en ceros
# for invoice in invoices:
# if invoice.type == 'out':
# cls.set_advances_from_origin(invoice)
def set_booking_payments(self):
for line in self.lines:
if line.origin and line.origin.__name__ == 'hotel.booking':
booking = line.origin
for payline in booking.payments:
if not payline.invoice and payline.party == self.party:
payline.invoice = self.id
payline.save()
# advances_lines = []
# if self.state == 'paid':
# return
#
# for line in invoice.lines:
# if line.origin and line.origin.__name__ == 'hotel.booking':
# booking = line.origin
# for payline in booking.payments:
# if payline.move and payline.party == self.party:
# for mline in payline.move.lines:
# if mline.account == self.account:
# advances_lines.append(mline)
# if advances_lines:
# invoice.add_payments(set(advances_lines))
@classmethod
def set_advances_from_origin(cls, invoice):
advances_to_add = []
@ -22,12 +71,11 @@ class Invoice(metaclass=PoolMeta):
for line in invoice.lines:
if line.origin and line.origin.__name__ == 'hotel.booking':
booking = line.origin
if not booking.vouchers:
continue
for voucher in booking.vouchers:
if invoice.party.id == voucher.party.id:
vouchers.append(voucher)
# FIXME must pass lines of move
if booking.vouchers:
for voucher in booking.vouchers:
if invoice.party.id == voucher.party.id:
vouchers.append(voucher)
# FIXME must pass lines of move
if vouchers:
invoice.create_move_advance(set(vouchers))

Binary file not shown.

24
statement.py Normal file
View File

@ -0,0 +1,24 @@
# This file is part of the sale_pos module for Tryton.
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from datetime import date
from decimal import Decimal
from trytond.model import fields, ModelView, ModelSQL, Workflow
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
from trytond.wizard import Button, StateTransition, StateView, Wizard
from trytond.pyson import Eval
from trytond.i18n import gettext
from trytond.exceptions import UserError
class StatementLine(metaclass=PoolMeta):
__name__ = 'account.statement.line'
@classmethod
def post_move(cls, lines):
super(StatementLine, cls).post_move(lines)
for s in lines:
if s.invoice and s.move and s.invoice.state != 'paid':
s.invoice.auto_reconcile()