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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 Tiny SPRL (<http://tiny.be>).
# Copyright (C) 2011 Camptocamp Austria (<http://www.camptocamp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import fields, osv
from tools.translate import _
import one2many_sorted
#----------------------------------------------------------
# Company
#----------------------------------------------------------
class res_company(osv.osv):
_inherit = 'res.company'
_columns = {
'print_ean' : fields.boolean( string="Print EAN on documents"),
}
_defaults = {
'print_ean': lambda *a: True,
}
res_company()
class stock_picking(osv.osv):
_inherit = "stock.picking"
def _print_uom(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_uom = False
if picking.move_lines:
for line in picking.move_lines:
if not line.product_uos or line.product_uos and line.product_uom != line.product_uos:
print_uom = True
res[picking.id] = print_uom
return res
def _print_uos(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_uos = False
if picking.move_lines:
for line in picking.move_lines:
if line.product_uos:
print_uos = True
res[picking.id] = print_uos
return res
def _print_packing(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_packing = False
if picking.move_lines:
for line in picking.move_lines:
if line.product_packaging:
print_packing = True
res[picking.id] = print_packing
return res
def _print_ean(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_ean = False
if picking.company_id.print_ean and picking.move_lines:
for line in picking.move_lines:
if line.product_id.ean13 or line.product_packaging.ean:
print_ean = True
res[picking.id] = print_ean
return res
def _print_lot(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_lot = False
if picking.move_lines:
for line in picking.move_lines:
if line.prodlot_id:
print_lot = True
res[picking.id] = print_lot
return res
def _print_code(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_code = False
if picking.move_lines and 'print_code' in picking.company_id._columns and picking.company_id.print_code:
for line in picking.move_lines:
if line.product_id.default_code:
print_code = True
res[picking.id] = print_code
return res
def _get_cols(self, cr, uid, ids, name, args, context=None):
res = {}
for order in self.browse(cr, uid, ids, context=context):
cols = 2
if order.print_uom:
cols += 2
if order.print_uos:
cols += 2
if order.print_packing:
cols += 2
if order.print_ean:
cols += 1
if order.print_lot:
cols += 1
if order.print_code:
cols += 1
res[order.id] = cols
return res
def _get_packs(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
packs = 0
if picking.move_lines:
for line in picking.move_lines:
if 'price_unit_id' in self._columns and line.product_packaging and line.product_packaging.qty:
packs += line.product_qty/line.product_packaging.qty
res[picking.id] = packs
return res
_columns = {
'print_uom': fields.function(_print_uom, method=True, type='boolean', string='Print UoM if different from UoS',),
'print_uos': fields.function(_print_uos, method=True, type='boolean', string='Print UoS if exists',),
'print_packing': fields.function(_print_packing, method=True, type='boolean', string='Print Packing Info if available',),
'print_ean': fields.function(_print_ean, method=True, type='boolean', string='Print EAN if available',),
'print_lot': fields.function(_print_lot, method=True, type='boolean', string='Print lot if available',),
'print_code': fields.function(_print_code, method=True, type='boolean', string='Print code if available',),
'cols': fields.function(_get_cols, method=True, type='integer', string='No of columns before totals',),
'number_of_packages_computed': fields.function(_get_packs, method=True, type='float', string='Number of Packages'),
'move_lines_sorted' : one2many_sorted.one2many_sorted
( 'stock.move'
, 'picking_id'
, 'Internal Moves Sorted'
, states={'draft': [('readonly', False)]}
, order = 'product_id.name'
)
}
def copy(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
default = default.copy()
default.update({'move_lines_sorted': []})
return super(stock_picking, self).copy(cr, uid, id, default, context=context)
stock_picking()
class stock_picking_out(osv.osv):
_inherit = "stock.picking.out"
def _print_uom(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_uom = False
if picking.move_lines:
for line in picking.move_lines:
if not line.product_uos or line.product_uos and line.product_uom != line.product_uos:
print_uom = True
res[picking.id] = print_uom
return res
def _print_uos(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_uos = False
if picking.move_lines:
for line in picking.move_lines:
if line.product_uos:
print_uos = True
res[picking.id] = print_uos
return res
def _print_packing(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_packing = False
if picking.move_lines:
for line in picking.move_lines:
if line.product_packaging:
print_packing = True
res[picking.id] = print_packing
return res
def _print_ean(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_ean = False
if picking.company_id.print_ean and picking.move_lines:
for line in picking.move_lines:
if line.product_id.ean13 or line.product_packaging.ean:
print_ean = True
res[picking.id] = print_ean
return res
def _print_lot(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_lot = False
if picking.move_lines:
for line in picking.move_lines:
if line.prodlot_id:
print_lot = True
res[picking.id] = print_lot
return res
def _print_code(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
print_code = False
if picking.move_lines and 'print_code' in picking.company_id._columns and picking.company_id.print_code:
for line in picking.move_lines:
if line.product_id.default_code:
print_code = True
res[picking.id] = print_code
return res
def _get_cols(self, cr, uid, ids, name, args, context=None):
res = {}
for order in self.browse(cr, uid, ids, context=context):
cols = 2
if order.print_uom:
cols += 2
if order.print_uos:
cols += 2
if order.print_packing:
cols += 2
if order.print_ean:
cols += 1
if order.print_lot:
cols += 1
if order.print_code:
cols += 1
res[order.id] = cols
return res
def _get_packs(self, cr, uid, ids, name, args, context=None):
res = {}
for picking in self.browse(cr, uid, ids, context=context):
packs = 0
if picking.move_lines:
for line in picking.move_lines:
if 'price_unit_id' in self._columns and line.product_packaging and line.product_packaging.qty:
packs += line.product_qty/line.product_packaging.qty
res[picking.id] = packs
return res
_columns = {
'print_uom': fields.function(_print_uom, method=True, type='boolean', string='Print UoM if different from UoS',),
'print_uos': fields.function(_print_uos, method=True, type='boolean', string='Print UoS if exists',),
'print_packing': fields.function(_print_packing, method=True, type='boolean', string='Print Packing Info if available',),
'print_ean': fields.function(_print_ean, method=True, type='boolean', string='Print EAN if available',),
'print_lot': fields.function(_print_lot, method=True, type='boolean', string='Print lot if available',),
'print_code': fields.function(_print_code, method=True, type='boolean', string='Print code if available',),
'cols': fields.function(_get_cols, method=True, type='integer', string='No of columns before totals',),
'number_of_packages_computed': fields.function(_get_packs, method=True, type='float', string='Number of Packages'),
'move_lines_sorted' : one2many_sorted.one2many_sorted
( 'stock.move'
, 'picking_id'
, 'Internal Moves Sorted'
, states={'draft': [('readonly', False)]}
, order = 'product_id.name'
)
}
def copy(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
default = default.copy()
default.update({'move_lines_sorted': []})
return super(stock_picking, self).copy(cr, uid, id, default, context=context)
stock_picking_out()
|