-
Notifications
You must be signed in to change notification settings - Fork 1
/
report_html_stock.py
111 lines (84 loc) · 2.9 KB
/
report_html_stock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
"""
report_html_stock.py
:copyright: (c) 2015 by Openlabs Technologies & Consulting (P) Limited
:license: BSD, see LICENSE for more details.
"""
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
from openlabs_report_webkit import ReportWebkit
__all__ = [
'PickingList', 'SupplierRestockingList', 'CustomerReturnRestockingList'
]
__metaclass__ = PoolMeta
class ReportMixin(ReportWebkit):
"""
Mixin Class to inherit from, for all HTML reports.
"""
@classmethod
def wkhtml_to_pdf(cls, data, options=None):
"""
Call wkhtmltopdf to convert the html to pdf
"""
Company = Pool().get('company.company')
company = ''
if Transaction().context.get('company'):
company = Company(Transaction().context.get('company')).party.name
options = {
'margin-bottom': '0.50in',
'margin-left': '0.50in',
'margin-right': '0.50in',
'margin-top': '0.50in',
'footer-font-size': '8',
'footer-left': company,
'footer-line': '',
'footer-right': '[page]/[toPage]',
'footer-spacing': '5',
}
return super(ReportMixin, cls).wkhtml_to_pdf(
data, options=options
)
@classmethod
def get_sorted_moves(cls, records):
"""
Sorting the moves for each shipment
"""
sorted_moves = {}
for shipment in records:
sorted_moves[shipment.id] = sorted(
shipment.inventory_moves,
key=lambda m: (m.from_location, m.to_location)
)
return sorted_moves
class PickingList(ReportMixin):
"""
Picking List Report
"""
__name__ = 'report.picking_list'
@classmethod
def parse(cls, report, records, data, localcontext):
sorted_moves = cls.get_sorted_moves(records)
localcontext['moves'] = sorted_moves
return super(PickingList, cls).parse(
report, records, data, localcontext
)
class SupplierRestockingList(ReportMixin):
'Supplier Restocking List'
__name__ = 'report.supplier_restocking_list'
@classmethod
def parse(cls, report, records, data, localcontext):
sorted_moves = cls.get_sorted_moves(records)
localcontext['moves'] = sorted_moves
return super(SupplierRestockingList, cls).parse(
report, records, data, localcontext
)
class CustomerReturnRestockingList(ReportMixin):
'Customer Return Restocking List'
__name__ = 'report.customer_return_restocking_list'
@classmethod
def parse(cls, report, records, data, localcontext):
sorted_moves = cls.get_sorted_moves(records)
localcontext['moves'] = sorted_moves
return super(CustomerReturnRestockingList, cls).parse(
report, records, data, localcontext
)