1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# |
3
|
|
|
# This file is part of SENAITE.CORE |
4
|
|
|
# |
5
|
|
|
# Copyright 2018 by it's authors. |
6
|
|
|
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst. |
7
|
|
|
|
8
|
|
|
import sys |
9
|
|
|
|
10
|
|
|
from AccessControl import ClassSecurityInfo |
11
|
|
|
from bika.lims import bikaMessageFactory as _ |
12
|
|
|
from bika.lims.config import PROJECTNAME |
13
|
|
|
from bika.lims.content.bikaschema import BikaSchema |
14
|
|
|
from bika.lims.interfaces import IInvoice |
15
|
|
|
from plone.app.blob.field import FileField as BlobFileField |
16
|
|
|
from Products.Archetypes.public import BaseFolder |
17
|
|
|
from Products.Archetypes.public import FileWidget |
18
|
|
|
from Products.Archetypes.public import ReferenceField |
19
|
|
|
from Products.Archetypes.public import Schema |
20
|
|
|
from Products.Archetypes.public import registerType |
21
|
|
|
from Products.ATExtensions.ateapi import DateTimeField |
22
|
|
|
from Products.ATExtensions.ateapi import DateTimeWidget |
23
|
|
|
from Products.CMFPlone.utils import safe_unicode |
24
|
|
|
from zope.interface import implements |
25
|
|
|
|
26
|
|
|
schema = BikaSchema.copy() + Schema(( |
27
|
|
|
BlobFileField( |
28
|
|
|
"InvoicePDF", |
29
|
|
|
widget=FileWidget( |
30
|
|
|
label=_("Invoice PDF"), |
31
|
|
|
) |
32
|
|
|
), |
33
|
|
|
ReferenceField( |
34
|
|
|
"Client", |
35
|
|
|
required=1, |
36
|
|
|
vocabulary_display_path_bound=sys.maxsize, |
37
|
|
|
allowed_types=("Client",), |
38
|
|
|
relationship="ClientInvoice", |
39
|
|
|
), |
40
|
|
|
ReferenceField( |
41
|
|
|
"AnalysisRequest", |
42
|
|
|
required=1, |
43
|
|
|
vocabulary_display_path_bound=sys.maxsize, |
44
|
|
|
allowed_types=("AnalysisRequest",), |
45
|
|
|
relationship="AnalysisRequestInvoice", |
46
|
|
|
), |
47
|
|
|
ReferenceField( |
48
|
|
|
"SupplyOrder", |
49
|
|
|
required=1, |
50
|
|
|
vocabulary_display_path_bound=sys.maxsize, |
51
|
|
|
allowed_types=("SupplyOrder",), |
52
|
|
|
relationship="SupplyOrderInvoice", |
53
|
|
|
), |
54
|
|
|
DateTimeField( |
55
|
|
|
"InvoiceDate", |
56
|
|
|
required=1, |
57
|
|
|
default_method="get_current_date", |
58
|
|
|
widget=DateTimeWidget( |
59
|
|
|
label=_("Date"), |
60
|
|
|
), |
61
|
|
|
), |
62
|
|
|
)) |
63
|
|
|
|
64
|
|
|
TitleField = schema["title"] |
65
|
|
|
TitleField.required = 0 |
66
|
|
|
TitleField.widget.visible = False |
67
|
|
|
|
68
|
|
|
|
69
|
|
|
class Invoice(BaseFolder): |
70
|
|
|
implements(IInvoice) |
71
|
|
|
security = ClassSecurityInfo() |
72
|
|
|
displayContentsTab = False |
73
|
|
|
schema = schema |
|
|
|
|
74
|
|
|
|
75
|
|
|
_at_rename_after_creation = True |
76
|
|
|
|
77
|
|
|
def _renameAfterCreation(self, check_auto_id=False): |
78
|
|
|
from bika.lims.idserver import renameAfterCreation |
79
|
|
|
renameAfterCreation(self) |
80
|
|
|
|
81
|
|
|
def Title(self): |
82
|
|
|
"""Return the Invoice ID as title |
83
|
|
|
""" |
84
|
|
|
return safe_unicode(self.getId()).encode("utf-8") |
85
|
|
|
|
86
|
|
|
def get_current_date(self): |
87
|
|
|
"""Return the current Date |
88
|
|
|
""" |
89
|
|
|
|
90
|
|
|
|
91
|
|
|
registerType(Invoice, PROJECTNAME) |
92
|
|
|
|