trytonpsk-hotel/invoice.py

41 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'
]