Added payment to invoice

This commit is contained in:
Oscar 2021-10-18 21:17:22 -05:00
parent 8b9886984f
commit 810b1bdf31
1 changed files with 49 additions and 1 deletions

View File

@ -321,6 +321,54 @@ class Booking(Workflow, ModelSQL, ModelView):
number = config.booking_sequence.get()
cls.write([booking], {'number': number})
@classmethod
def reconcile(cls, booking, voucher):
pool = Pool()
VoucherConfig = pool.get('account.voucher_configuration')
MoveLine = pool.get('account.move.line')
invoice = None
config = VoucherConfig.get_configuration()
account = config.account_prepayment
for folio in booking.lines:
invoice = folio.invoice
if invoice and invoice.state == 'paid':
continue
advances = []
payments = []
for voucher in booking.vouchers:
print(folio.invoice.number, folio.invoice.state)
for line in voucher.move.lines:
if line.account.id == account.id and not line.reconciliation:
advances.append(voucher)
break
elif line.account.id == invoice.account.id:
payments.append(line)
if invoice:
to_reconcile_lines = []
if advances:
invoice.create_move_advance(advances)
invoice.save()
if payments:
invoice.add_payment_lines({invoice: payments})
invoice.save()
# to_reconcile_lines.extend(payments)
if invoice.amount_to_pay == Decimal(0):
# invoice.paid([invoice])
for ml in invoice.payment_lines:
if not ml.reconciliation:
to_reconcile_lines.append(ml)
for ml in invoice.move.lines:
if not ml.reconciliation and ml.account.id == invoice.account.id:
to_reconcile_lines.append(ml)
if to_reconcile_lines:
print('to_reconcile_lines...', to_reconcile_lines)
balance = 0
for lin in to_reconcile_lines:
print(lin.debit, line.credit)
balance += lin.debit - line.credit
MoveLine.reconcile(to_reconcile_lines)
@classmethod
def get_grouped_invoices(cls, folios, charges):
res = {}
@ -361,7 +409,7 @@ class Booking(Workflow, ModelSQL, ModelView):
'folios': [fo],
'description': fo.get_room_info(),
'quantity': fo.nights_quantity,
'product': fo.accommodation,
'product': fo.product,
'unit_price': fo.unit_price,
'taxes_exception': booking.taxes_exception,
})