2009-03-05 19:53:31 +01:00
|
|
|
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
#this repository contains the full copyright notices and license terms.
|
|
|
|
|
import datetime
|
2012-09-24 22:19:48 +02:00
|
|
|
|
|
|
|
|
from trytond.model import fields
|
|
|
|
|
from trytond.pool import PoolMeta
|
|
|
|
|
|
|
|
|
|
__all__ = ['Invoice']
|
|
|
|
|
__metaclass__ = PoolMeta
|
2009-03-05 19:53:31 +01:00
|
|
|
|
|
|
|
|
|
2012-09-24 22:19:48 +02:00
|
|
|
class Invoice:
|
|
|
|
|
__name__ = 'account.invoice'
|
2009-03-05 19:53:31 +01:00
|
|
|
open_date = fields.DateTime('Open Date')
|
|
|
|
|
|
2012-09-24 22:19:48 +02:00
|
|
|
@classmethod
|
|
|
|
|
def __setup__(cls):
|
|
|
|
|
super(Invoice, cls).__setup__()
|
|
|
|
|
cls.party.datetime_field = 'open_date'
|
|
|
|
|
if 'open_date' not in cls.party.depends:
|
|
|
|
|
cls.party.depends.append('open_date')
|
|
|
|
|
cls.invoice_address.datetime_field = 'open_date'
|
|
|
|
|
if 'open_date' not in cls.invoice_address.depends:
|
|
|
|
|
cls.invoice_address.depends.append('open_date')
|
|
|
|
|
cls.payment_term.datetime_field = 'open_date'
|
|
|
|
|
if 'open_date' not in cls.payment_term.depends:
|
|
|
|
|
cls.payment_term.depends.append('open_date')
|
2009-03-05 19:53:31 +01:00
|
|
|
|
2012-09-24 22:19:48 +02:00
|
|
|
def set_number(self):
|
|
|
|
|
set_open_date = not self.number
|
|
|
|
|
super(Invoice, self).set_number()
|
2012-08-16 14:52:34 +02:00
|
|
|
if set_open_date:
|
2012-09-24 22:19:48 +02:00
|
|
|
self.write([self], {
|
|
|
|
|
'open_date': datetime.datetime.now(),
|
|
|
|
|
})
|
2009-03-05 19:53:31 +01:00
|
|
|
|
2012-09-24 22:19:48 +02:00
|
|
|
@classmethod
|
|
|
|
|
def copy(cls, invoices, default=None):
|
2009-03-28 19:49:20 +01:00
|
|
|
if default is None:
|
|
|
|
|
default = {}
|
|
|
|
|
default = default.copy()
|
2012-03-27 10:43:08 +02:00
|
|
|
default['open_date'] = None
|
2012-09-24 22:19:48 +02:00
|
|
|
return super(Invoice, cls).copy(invoices, default=default)
|