diff --git a/__init__.py b/__init__.py index 1b1f19e..c65ab14 100644 --- a/__init__.py +++ b/__init__.py @@ -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, diff --git a/booking.py b/booking.py index 083a8a3..210ab13 100644 --- a/booking.py +++ b/booking.py @@ -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' diff --git a/folio.fodt b/folio.fodt index 5bdeed0..33e1fea 100644 Binary files a/folio.fodt and b/folio.fodt differ diff --git a/invoice.py b/invoice.py index 19e30cc..2e4bf79 100644 --- a/invoice.py +++ b/invoice.py @@ -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)) diff --git a/statement.fodt b/statement.fodt index 4e4aa7f..dba6c0d 100644 Binary files a/statement.fodt and b/statement.fodt differ diff --git a/statement.py b/statement.py new file mode 100644 index 0000000..53f497b --- /dev/null +++ b/statement.py @@ -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()