trytonpsk-hotel/invoice.py
oscar alvarez ef6b5d79cf Fix
2022-03-25 10:03:19 -05:00

40 lines
1.3 KiB
Python

# 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
class Invoice(metaclass=PoolMeta):
__name__ = 'account.invoice'
@classmethod
def post(cls, invoices):
super(Invoice, cls).post(invoices)
for invoice in invoices:
if invoice.type == 'out':
cls.set_advances_from_origin(invoice)
@classmethod
def set_advances_from_origin(cls, invoice):
advances_to_add = []
vouchers = []
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)
if vouchers:
invoice.create_move_advance(set(vouchers))
class InvoiceLine(metaclass=PoolMeta):
__name__ = 'account.invoice.line'
@classmethod
def _get_origin(cls):
return super(InvoiceLine, cls)._get_origin() + [
'hotel.booking'
]