mirror of
https://bitbucket.org/presik/trytonpsk-hotel.git
synced 2023-12-14 07:52:52 +01:00
40 lines
1.3 KiB
Python
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'
|
|
]
|