Fix
This commit is contained in:
parent
a7000eb130
commit
e8e0f5237f
12
booking.py
12
booking.py
|
@ -2498,6 +2498,7 @@ class BillBookingStart(ModelView):
|
|||
charges = fields.Many2Many('hotel.folio.charge', None, None, 'Charges',
|
||||
domain=[
|
||||
('id', 'in', Eval('targets')),
|
||||
('invoice_line', '=', None),
|
||||
],
|
||||
states={
|
||||
'invisible': Eval('kind') != 'only_products',
|
||||
|
@ -2519,7 +2520,6 @@ class BillBookingStart(ModelView):
|
|||
if not charges:
|
||||
continue
|
||||
res.extend(list(charges))
|
||||
print("folios ....", res)
|
||||
return res
|
||||
|
||||
|
||||
|
@ -2610,11 +2610,11 @@ class OperationForecast(Wizard):
|
|||
'Operation Forecast'
|
||||
__name__ = 'hotel.print_operation_forecast'
|
||||
start = StateView(
|
||||
'hotel.print_operation_forecast.start',
|
||||
'hotel.print_operation_forecast_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Print', 'print_', 'tryton-print', default=True),
|
||||
])
|
||||
'hotel.print_operation_forecast.start',
|
||||
'hotel.print_operation_forecast_start_view_form', [
|
||||
Button('Cancel', 'end', 'tryton-cancel'),
|
||||
Button('Print', 'print_', 'tryton-print', default=True),
|
||||
])
|
||||
print_ = StateReport('hotel.operation_forecast.report')
|
||||
|
||||
def do_print_(self, action):
|
||||
|
|
2
folio.py
2
folio.py
|
@ -280,12 +280,10 @@ class Folio(ModelSQL, ModelView):
|
|||
if name == 'pending_accommodation':
|
||||
res = self.get_total_accommodation()
|
||||
charge_paid = self._get_paid('accommodation')
|
||||
print(self.registration_card, "ACO ====", res, charge_paid)
|
||||
res = res - charge_paid
|
||||
elif name == 'pending_charges':
|
||||
res = self.get_total_products()
|
||||
charge_paid = self._get_paid('product')
|
||||
print(self.registration_card, "Product ====", res, charge_paid)
|
||||
res = res - charge_paid
|
||||
elif name == 'pending_total':
|
||||
res = self.total_amount - self.total_advances
|
||||
|
|
94
invoice.py
94
invoice.py
|
@ -119,10 +119,11 @@ class Invoice(metaclass=PoolMeta):
|
|||
if invoice.type == 'in':
|
||||
invoice._add_commission_payment()
|
||||
|
||||
cls.set_booking_payments(invoice)
|
||||
if not invoice.move.origin:
|
||||
return
|
||||
invoice.auto_reconcile()
|
||||
# Better add this for night audit
|
||||
# cls.set_booking_payments(invoice)
|
||||
# if not invoice.move.origin:
|
||||
# return
|
||||
# invoice.auto_reconcile()
|
||||
|
||||
@classmethod
|
||||
def set_booking_payments(cls, invoice):
|
||||
|
@ -133,47 +134,65 @@ class Invoice(metaclass=PoolMeta):
|
|||
booking = None
|
||||
payments = []
|
||||
lines_paid = []
|
||||
bk_invoices = {}
|
||||
party = invoice.party
|
||||
for line in invoice.lines:
|
||||
if line.origin and line.origin.__name__ == 'hotel.folio':
|
||||
folio = line.origin
|
||||
booking = folio.booking
|
||||
payments.append(folio.payments)
|
||||
|
||||
if booking:
|
||||
for inv in booking.invoices:
|
||||
if inv.state != 'posted':
|
||||
continue
|
||||
if inv.party == invoice.party:
|
||||
bk_invoices[inv.id] = inv
|
||||
payments.append(booking.payments)
|
||||
|
||||
lines_paid = []
|
||||
lines_advance = []
|
||||
for rec in payments:
|
||||
lines_paid.extend(cls.set_payments_lines(invoice, rec))
|
||||
_bk_invoices = list(bk_invoices.values())
|
||||
for rec in set(payments):
|
||||
lines_paid.extend(cls.set_payments_lines(_bk_invoices, party, rec))
|
||||
lines_advance.extend(
|
||||
cls.set_payments_lines(invoice, rec, acc_advance))
|
||||
cls.set_payments_lines(_bk_invoices, party, rec, acc_advance))
|
||||
|
||||
lines_invs_advance = {}
|
||||
if lines_paid or lines_advance:
|
||||
if acc_advance and lines_advance:
|
||||
lines_paid.extend(
|
||||
cls.do_move_writeoff_advance(
|
||||
lines_advance, acc_advance, invoice))
|
||||
if lines_paid:
|
||||
lines_invs_advance = cls.do_move_writeoff_advance(
|
||||
lines_advance, acc_advance, _bk_invoices)
|
||||
if lines_paid and len(_bk_invoices) == 1:
|
||||
lines_paid = [li.id for li in lines_paid]
|
||||
cls.write([invoice], {'payment_lines': [('add', lines_paid)]})
|
||||
|
||||
if lines_invs_advance:
|
||||
for invoice in _bk_invoices:
|
||||
lines_paid = lines_invs_advance[invoice.id]
|
||||
cls.write([invoice], {
|
||||
'payment_lines': [('add', lines_paid)],
|
||||
})
|
||||
return _bk_invoices
|
||||
|
||||
@classmethod
|
||||
def set_payments_lines(cls, inv, payments, account=None):
|
||||
def set_payments_lines(cls, invoices, party, payments, account=None):
|
||||
lines_paid = []
|
||||
balance = 0
|
||||
account_id = account.id if account else inv.account.id
|
||||
account_id = account.id if account else invoices[0].account.id
|
||||
total_amount = sum(inv.total_amount for inv in invoices)
|
||||
for as_line in payments:
|
||||
if as_line.move and as_line.party == inv.party:
|
||||
if as_line.move and as_line.party == party:
|
||||
balance += as_line.amount
|
||||
if as_line.amount > inv.total_amount or balance > inv.total_amount:
|
||||
if as_line.amount > total_amount or balance > total_amount:
|
||||
break
|
||||
for mline in as_line.move.lines:
|
||||
if mline.account.id == account_id and not mline.reconciliation:
|
||||
lines_paid.append(mline)
|
||||
for ml in as_line.move.lines:
|
||||
if ml.account.id == account_id and not ml.reconciliation:
|
||||
lines_paid.append(ml)
|
||||
return lines_paid
|
||||
|
||||
@classmethod
|
||||
def do_move_writeoff_advance(cls, lines, account, inv):
|
||||
def do_move_writeoff_advance(cls, lines, account, invoices):
|
||||
# Asiento de cancelacion de los anticipos en la reserva
|
||||
# conciliacion de los anticipos y abono de los pagos en factura
|
||||
pool = Pool()
|
||||
|
@ -186,21 +205,23 @@ class Invoice(metaclass=PoolMeta):
|
|||
('type', '=', 'write-off')
|
||||
], limit=1)
|
||||
|
||||
inv = invoices[0]
|
||||
amount_paid = sum(li.credit for li in lines)
|
||||
sum_invoices = sum(invoice.total_amount for invoice in invoices)
|
||||
if sum_invoices != amount_paid:
|
||||
return {}
|
||||
period_id = Period.find(inv.company.id, date=inv.invoice_date)
|
||||
move, = Move.create([{
|
||||
'journal': journal['id'],
|
||||
'period': period_id,
|
||||
'date': inv.invoice_date,
|
||||
# 'origin': str(self),
|
||||
'state': 'draft',
|
||||
'description': inv.description,
|
||||
}])
|
||||
amount = 0
|
||||
to_debit = []
|
||||
advance_lines = []
|
||||
for line in lines:
|
||||
advance_lines.append(line.id)
|
||||
amount += line.credit
|
||||
to_debit.append({
|
||||
'description': inv.reference,
|
||||
'party': inv.party.id,
|
||||
|
@ -209,22 +230,26 @@ class Invoice(metaclass=PoolMeta):
|
|||
'credit': 0,
|
||||
'move': move.id,
|
||||
})
|
||||
to_credit = [{
|
||||
'description': inv.description,
|
||||
'party': inv.party.id,
|
||||
'account': inv.account.id,
|
||||
'debit': 0,
|
||||
'credit': amount,
|
||||
'move': move.id,
|
||||
}]
|
||||
|
||||
lines_invoices_paid = {}
|
||||
for invoice in invoices:
|
||||
line_id_pay, = MoveLine.create([{
|
||||
'description': inv.description,
|
||||
'party': inv.party.id,
|
||||
'account': inv.account.id,
|
||||
'debit': 0,
|
||||
'credit': invoice.total_amount,
|
||||
'move': move.id,
|
||||
}])
|
||||
lines_invoices_paid[invoice.id] = [line_id_pay]
|
||||
|
||||
debit_lines = MoveLine.create(to_debit)
|
||||
lines_ids = MoveLine.create(to_credit)
|
||||
Reconciliation.create([{
|
||||
'lines': [('add', debit_lines + advance_lines)],
|
||||
'date': date.today(),
|
||||
}])
|
||||
Move.post([move])
|
||||
return lines_ids
|
||||
return lines_invoices_paid
|
||||
|
||||
@classmethod
|
||||
def set_advances_from_origin(cls, invoice):
|
||||
|
@ -244,8 +269,9 @@ class Invoice(metaclass=PoolMeta):
|
|||
def concile_booking_invoice(cls, record):
|
||||
if record.state != 'posted':
|
||||
return
|
||||
cls.set_booking_payments(record)
|
||||
record.auto_reconcile()
|
||||
invoices = cls.set_booking_payments(record)
|
||||
for invoice in invoices:
|
||||
invoice.auto_reconcile()
|
||||
|
||||
|
||||
class InvoiceLine(metaclass=PoolMeta):
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[tryton]
|
||||
version=6.0.120
|
||||
version=6.0.121
|
||||
depends:
|
||||
party
|
||||
company
|
||||
|
|
Loading…
Reference in New Issue