Merge lp:~camptocamp/carriers-deliveries/7.0-delivery_carrier_label_dispatch-output-file-yvr into lp:~stock-logistic-core-editors/carriers-deliveries/7.0
- 7.0-delivery_carrier_label_dispatch-output-file-yvr
- Merge into 7.0
Status: | Needs review |
---|---|
Proposed branch: | lp:~camptocamp/carriers-deliveries/7.0-delivery_carrier_label_dispatch-output-file-yvr |
Merge into: | lp:~stock-logistic-core-editors/carriers-deliveries/7.0 |
Prerequisite: | lp:~camptocamp/carriers-deliveries/7.0-add-delivery_carrier_label_dispatch-yvr |
Diff against target: |
503 lines (+180/-199) 7 files modified
delivery_carrier_label_dispatch/__init__.py (+0/-1) delivery_carrier_label_dispatch/__openerp__.py (+7/-2) delivery_carrier_label_dispatch/i18n/delivery_carrier_label_dispatch.pot (+76/-95) delivery_carrier_label_dispatch/pdf_utils.py (+2/-0) delivery_carrier_label_dispatch/stock.py (+0/-62) delivery_carrier_label_dispatch/wizard/generate_labels.py (+91/-34) delivery_carrier_label_dispatch/wizard/generate_labels_view.xml (+4/-5) |
To merge this branch: | bzr merge lp:~camptocamp/carriers-deliveries/7.0-delivery_carrier_label_dispatch-output-file-yvr |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Leonardo Pistone | code review | Approve | |
Stock and Logistic Core Editors | Pending | ||
Review via email: mp+202444@code.launchpad.net |
Commit message
Description of the change
Leonardo Pistone (lepistone) wrote : | # |
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
I have some work on my side on the same part of the code. I will merge your changes in my own branch because they will conflict a lot otherwise. I put your branch as WIP just to avoid people reviewing it meanwhile.
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : | # |
Merged Guewen's work
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : | # |
Resolved conflicts Needs reviews
- 21. By Yannick Vaucher @ Camptocamp
-
Add better exception message from dispatch to identify the pack with an error
- 22. By Yannick Vaucher @ Camptocamp
-
update pot file
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : | # |
This project is now hosted on https:/
Unmerged revisions
- 22. By Yannick Vaucher @ Camptocamp
-
update pot file
- 21. By Yannick Vaucher @ Camptocamp
-
Add better exception message from dispatch to identify the pack with an error
- 20. By Yannick Vaucher @ Camptocamp
-
merge main branch to resolve conflicts
- 19. By Yannick Vaucher @ Camptocamp
-
add file extension in file name for poor OS
- 18. By Yannick Vaucher @ Camptocamp
-
fix generation of picking shipping labels from picking dispatch when there are no pack defined in the pickings
- 17. By Guewen Baconnier @ Camptocamp
-
use the general method and not the one for the button
avoid utils.PdfReadEr
ror('Cannot read an empty file') error - 16. By Yannick Vaucher @ Camptocamp
-
[FIX] delivery_
carrier_ label_dispatch - save picking dispatch label pdf file as attachement of the picking
Preview Diff
1 | === modified file 'delivery_carrier_label_dispatch/__init__.py' | |||
2 | --- delivery_carrier_label_dispatch/__init__.py 2014-01-09 13:54:55 +0000 | |||
3 | +++ delivery_carrier_label_dispatch/__init__.py 2014-04-10 14:10:35 +0000 | |||
4 | @@ -18,6 +18,5 @@ | |||
5 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
6 | 19 | # | 19 | # |
7 | 20 | ############################################################################## | 20 | ############################################################################## |
8 | 21 | from . import stock | ||
9 | 22 | from . import picking_dispatch | 21 | from . import picking_dispatch |
10 | 23 | from . import wizard | 22 | from . import wizard |
11 | 24 | 23 | ||
12 | === modified file 'delivery_carrier_label_dispatch/__openerp__.py' | |||
13 | --- delivery_carrier_label_dispatch/__openerp__.py 2014-01-09 13:54:55 +0000 | |||
14 | +++ delivery_carrier_label_dispatch/__openerp__.py 2014-04-10 14:10:35 +0000 | |||
15 | @@ -29,8 +29,13 @@ | |||
16 | 29 | [Link module] Carrier labels - Picking dispatch | 29 | [Link module] Carrier labels - Picking dispatch |
17 | 30 | ============================== | 30 | ============================== |
18 | 31 | 31 | ||
21 | 32 | This module adds a wizard on picking dispatch to generate related picking | 32 | This module adds a wizard on picking dispatch to generate the labels |
22 | 33 | labels | 33 | of the packs. The labels are merged in one PDF file. |
23 | 34 | |||
24 | 35 | If you want multiple labels for one picking, all the moves should have been | ||
25 | 36 | put in a pack before the labels can be printed. | ||
26 | 37 | |||
27 | 38 | If you don't define your pack it will be considered a picking is a single pack. | ||
28 | 34 | 39 | ||
29 | 35 | Contributors | 40 | Contributors |
30 | 36 | ------------ | 41 | ------------ |
31 | 37 | 42 | ||
32 | === modified file 'delivery_carrier_label_dispatch/i18n/delivery_carrier_label_dispatch.pot' | |||
33 | --- delivery_carrier_label_dispatch/i18n/delivery_carrier_label_dispatch.pot 2014-01-09 13:54:55 +0000 | |||
34 | +++ delivery_carrier_label_dispatch/i18n/delivery_carrier_label_dispatch.pot 2014-04-10 14:10:35 +0000 | |||
35 | @@ -6,58 +6,75 @@ | |||
36 | 6 | msgstr "" | 6 | msgstr "" |
37 | 7 | "Project-Id-Version: OpenERP Server 7.0\n" | 7 | "Project-Id-Version: OpenERP Server 7.0\n" |
38 | 8 | "Report-Msgid-Bugs-To: \n" | 8 | "Report-Msgid-Bugs-To: \n" |
42 | 9 | "POT-Creation-Date: 2014-01-09 13:29+0000\n" | 9 | "POT-Creation-Date: 2014-04-10 14:03+0000\n" |
43 | 10 | "PO-Revision-Date: 2014-01-09 14:30+0100\n" | 10 | "PO-Revision-Date: 2014-04-10 14:03+0000\n" |
44 | 11 | "Last-Translator: Yannick Vaucher <yannick.vaucher@camptocamp.com>\n" | 11 | "Last-Translator: <>\n" |
45 | 12 | "Language-Team: \n" | 12 | "Language-Team: \n" |
46 | 13 | "MIME-Version: 1.0\n" | 13 | "MIME-Version: 1.0\n" |
47 | 14 | "Content-Type: text/plain; charset=UTF-8\n" | 14 | "Content-Type: text/plain; charset=UTF-8\n" |
49 | 15 | "Content-Transfer-Encoding: 8bit\n" | 15 | "Content-Transfer-Encoding: \n" |
50 | 16 | "Plural-Forms: \n" | 16 | "Plural-Forms: \n" |
51 | 17 | 17 | ||
52 | 18 | #. module: delivery_carrier_label_dispatch | 18 | #. module: delivery_carrier_label_dispatch |
53 | 19 | #: model:ir.model.fields,field_description:delivery_carrier_label_dispatch.field_picking_dispatch_carrier_id | ||
54 | 20 | #: field:picking.dispatch,carrier_id:0 | ||
55 | 21 | msgid "Carrier" | ||
56 | 22 | msgstr "" | ||
57 | 23 | |||
58 | 24 | #. module: delivery_carrier_label_dispatch | ||
59 | 19 | #: view:picking.dispatch:0 | 25 | #: view:picking.dispatch:0 |
60 | 20 | msgid "Carrier Info" | 26 | msgid "Carrier Info" |
61 | 21 | msgstr "" | 27 | msgstr "" |
62 | 22 | 28 | ||
63 | 23 | #. module: delivery_carrier_label_dispatch | 29 | #. module: delivery_carrier_label_dispatch |
64 | 30 | #: view:delivery.carrier.label.generate:0 | ||
65 | 31 | msgid "Close" | ||
66 | 32 | msgstr "" | ||
67 | 33 | |||
68 | 34 | #. module: delivery_carrier_label_dispatch | ||
69 | 35 | #: view:picking.dispatch:0 | ||
70 | 36 | msgid "Delivery" | ||
71 | 37 | msgstr "" | ||
72 | 38 | |||
73 | 39 | #. module: delivery_carrier_label_dispatch | ||
74 | 40 | #: code:_description:0 | ||
75 | 41 | #: model:ir.model,name:delivery_carrier_label_dispatch.model_picking_dispatch | ||
76 | 42 | #, python-format | ||
77 | 43 | msgid "Dispatch Picking Order" | ||
78 | 44 | msgstr "" | ||
79 | 45 | |||
80 | 46 | #. module: delivery_carrier_label_dispatch | ||
81 | 24 | #: model:ir.actions.act_window,name:delivery_carrier_label_dispatch.action_delivery_carrier_label_generate | 47 | #: model:ir.actions.act_window,name:delivery_carrier_label_dispatch.action_delivery_carrier_label_generate |
82 | 25 | msgid "Generate Carrier Labels" | 48 | msgid "Generate Carrier Labels" |
83 | 26 | msgstr "" | 49 | msgstr "" |
84 | 27 | 50 | ||
85 | 28 | #. module: delivery_carrier_label_dispatch | 51 | #. module: delivery_carrier_label_dispatch |
104 | 29 | #: model:ir.model,name:delivery_carrier_label_dispatch.model_stock_picking | 52 | #: view:delivery.carrier.label.generate:0 |
105 | 30 | msgid "Picking List" | 53 | msgid "Generate Carriers Labels" |
106 | 31 | msgstr "" | 54 | msgstr "" |
107 | 32 | 55 | ||
108 | 33 | #. module: delivery_carrier_label_dispatch | 56 | #. module: delivery_carrier_label_dispatch |
109 | 34 | #: code:addons/delivery_carrier_label_dispatch/picking_dispatch.py:100 | 57 | #: view:delivery.carrier.label.generate:0 |
110 | 35 | #, python-format | 58 | msgid "Generate Labels" |
111 | 36 | msgid "" | 59 | msgstr "" |
112 | 37 | "You can not remove a mandatory option.\n" | 60 | |
113 | 38 | "Options are reset to default." | 61 | #. module: delivery_carrier_label_dispatch |
114 | 39 | msgstr "" | 62 | #: field:delivery.carrier.label.generate,generate_new_labels:0 |
115 | 40 | 63 | #: model:ir.model.fields,field_description:delivery_carrier_label_dispatch.field_delivery_carrier_label_generate_generate_new_labels | |
116 | 41 | #. module: delivery_carrier_label_dispatch | 64 | msgid "Generate new labels" |
117 | 42 | #: model:ir.model,name:delivery_carrier_label_dispatch.model_picking_dispatch | 65 | msgstr "" |
118 | 43 | msgid "Dispatch Picking Order" | 66 | |
119 | 44 | msgstr "" | 67 | #. module: delivery_carrier_label_dispatch |
120 | 45 | 68 | #: help:delivery.carrier.label.generate,generate_new_labels:0 | |
121 | 46 | #. module: delivery_carrier_label_dispatch | 69 | msgid "If this option is used, new labels will be generated for the packs even if they already have one.\n" |
122 | 70 | "The default is to use the existing label." | ||
123 | 71 | msgstr "" | ||
124 | 72 | |||
125 | 73 | #. module: delivery_carrier_label_dispatch | ||
126 | 74 | #: model:ir.model.fields,field_description:delivery_carrier_label_dispatch.field_picking_dispatch_option_ids | ||
127 | 47 | #: view:picking.dispatch:0 | 75 | #: view:picking.dispatch:0 |
141 | 48 | msgid "Delivery" | 76 | #: field:picking.dispatch,option_ids:0 |
142 | 49 | msgstr "" | 77 | msgid "Options" |
130 | 50 | |||
131 | 51 | #. module: delivery_carrier_label_dispatch | ||
132 | 52 | #: code:addons/delivery_carrier_label_dispatch/wizard/generate_labels.py:58 | ||
133 | 53 | #, python-format | ||
134 | 54 | msgid "No picking dispatch selected" | ||
135 | 55 | msgstr "" | ||
136 | 56 | |||
137 | 57 | #. module: delivery_carrier_label_dispatch | ||
138 | 58 | #: field:delivery.carrier.label.generate,label_pdf_file:0 | ||
139 | 59 | #: model:ir.model.fields,field_description:delivery_carrier_label_dispatch.field_delivery_carrier_label_generate_label_pdf_file | ||
140 | 60 | msgid "Labels file" | ||
143 | 61 | msgstr "" | 78 | msgstr "" |
144 | 62 | 79 | ||
145 | 63 | #. module: delivery_carrier_label_dispatch | 80 | #. module: delivery_carrier_label_dispatch |
146 | @@ -67,71 +84,35 @@ | |||
147 | 67 | msgstr "" | 84 | msgstr "" |
148 | 68 | 85 | ||
149 | 69 | #. module: delivery_carrier_label_dispatch | 86 | #. module: delivery_carrier_label_dispatch |
150 | 87 | #: code:_description:0 | ||
151 | 88 | #: model:ir.model,name:delivery_carrier_label_dispatch.model_stock_picking | ||
152 | 89 | #, python-format | ||
153 | 90 | msgid "Picking List" | ||
154 | 91 | msgstr "" | ||
155 | 92 | |||
156 | 93 | #. module: delivery_carrier_label_dispatch | ||
157 | 94 | #: view:picking.dispatch:0 | ||
158 | 95 | msgid "Set Options" | ||
159 | 96 | msgstr "" | ||
160 | 97 | |||
161 | 98 | #. module: delivery_carrier_label_dispatch | ||
162 | 99 | #: view:delivery.carrier.label.generate:0 | ||
163 | 100 | msgid "This wizard creates an attachement on each selected dispatch containing picking labels" | ||
164 | 101 | msgstr "" | ||
165 | 102 | |||
166 | 103 | #. module: delivery_carrier_label_dispatch | ||
167 | 104 | #: view:picking.dispatch:0 | ||
168 | 105 | msgid "Warning, setting options will erase existing ones in pickings" | ||
169 | 106 | msgstr "" | ||
170 | 107 | |||
171 | 108 | #. module: delivery_carrier_label_dispatch | ||
172 | 109 | #: code:_description:0 | ||
173 | 70 | #: model:ir.model,name:delivery_carrier_label_dispatch.model_delivery_carrier_label_generate | 110 | #: model:ir.model,name:delivery_carrier_label_dispatch.model_delivery_carrier_label_generate |
174 | 111 | #, python-format | ||
175 | 71 | msgid "delivery.carrier.label.generate" | 112 | msgid "delivery.carrier.label.generate" |
176 | 72 | msgstr "" | 113 | msgstr "" |
177 | 73 | 114 | ||
178 | 74 | #. module: delivery_carrier_label_dispatch | 115 | #. module: delivery_carrier_label_dispatch |
179 | 75 | #: view:picking.dispatch:0 | ||
180 | 76 | msgid "Set Options" | ||
181 | 77 | msgstr "" | ||
182 | 78 | |||
183 | 79 | #. module: delivery_carrier_label_dispatch | ||
184 | 80 | #: model:ir.model.fields,field_description:delivery_carrier_label_dispatch.field_picking_dispatch_carrier_id | ||
185 | 81 | #: field:picking.dispatch,carrier_id:0 | ||
186 | 82 | msgid "Carrier" | ||
187 | 83 | msgstr "" | ||
188 | 84 | |||
189 | 85 | #. module: delivery_carrier_label_dispatch | ||
190 | 86 | #: code:addons/delivery_carrier_label_dispatch/wizard/generate_labels.py:58 | ||
191 | 87 | #, python-format | ||
192 | 88 | msgid "Error" | ||
193 | 89 | msgstr "" | ||
194 | 90 | |||
195 | 91 | #. module: delivery_carrier_label_dispatch | ||
196 | 92 | #: view:picking.dispatch:0 | ||
197 | 93 | msgid "Warning, setting options will erase existing ones in pickings" | ||
198 | 94 | msgstr "" | ||
199 | 95 | |||
200 | 96 | #. module: delivery_carrier_label_dispatch | ||
201 | 97 | #: model:ir.model.fields,field_description:delivery_carrier_label_dispatch.field_picking_dispatch_option_ids | ||
202 | 98 | #: view:picking.dispatch:0 | ||
203 | 99 | #: field:picking.dispatch,option_ids:0 | ||
204 | 100 | msgid "Options" | ||
205 | 101 | msgstr "" | ||
206 | 102 | |||
207 | 103 | #. module: delivery_carrier_label_dispatch | ||
208 | 104 | #: view:delivery.carrier.label.generate:0 | ||
209 | 105 | msgid "Generate Labels" | ||
210 | 106 | msgstr "" | ||
211 | 107 | |||
212 | 108 | #. module: delivery_carrier_label_dispatch | ||
213 | 109 | #: view:delivery.carrier.label.generate:0 | ||
214 | 110 | msgid "Labels" | ||
215 | 111 | msgstr "" | ||
216 | 112 | |||
217 | 113 | #. module: delivery_carrier_label_dispatch | ||
218 | 114 | #: view:delivery.carrier.label.generate:0 | ||
219 | 115 | msgid "Generate Carriers Labels" | ||
220 | 116 | msgstr "" | ||
221 | 117 | |||
222 | 118 | #. module: delivery_carrier_label_dispatch | ||
223 | 119 | #: view:delivery.carrier.label.generate:0 | ||
224 | 120 | msgid "Close" | ||
225 | 121 | msgstr "" | ||
226 | 122 | |||
227 | 123 | #. module: delivery_carrier_label_dispatch | ||
228 | 124 | #: code:addons/delivery_carrier_label_dispatch/picking_dispatch.py:99 | ||
229 | 125 | #, python-format | ||
230 | 126 | msgid "User Error !" | ||
231 | 127 | msgstr "" | ||
232 | 128 | |||
233 | 129 | #. module: delivery_carrier_label_dispatch | ||
234 | 130 | #: model:ir.model,name:delivery_carrier_label_dispatch.model_stock_picking_out | ||
235 | 131 | msgid "Delivery Orders" | ||
236 | 132 | msgstr "" | ||
237 | 133 | |||
238 | 134 | #. module: delivery_carrier_label_dispatch | ||
239 | 135 | #: view:delivery.carrier.label.generate:0 | 116 | #: view:delivery.carrier.label.generate:0 |
240 | 136 | msgid "or" | 117 | msgid "or" |
241 | 137 | msgstr "" | 118 | msgstr "" |
242 | 138 | 119 | ||
243 | === modified file 'delivery_carrier_label_dispatch/pdf_utils.py' | |||
244 | --- delivery_carrier_label_dispatch/pdf_utils.py 2013-12-17 07:55:56 +0000 | |||
245 | +++ delivery_carrier_label_dispatch/pdf_utils.py 2014-04-10 14:10:35 +0000 | |||
246 | @@ -39,6 +39,8 @@ | |||
247 | 39 | 39 | ||
248 | 40 | output = PdfFileWriter() | 40 | output = PdfFileWriter() |
249 | 41 | for pdf in pdf_list: | 41 | for pdf in pdf_list: |
250 | 42 | if not pdf: | ||
251 | 43 | continue | ||
252 | 42 | reader = PdfFileReader(StringIO(pdf)) | 44 | reader = PdfFileReader(StringIO(pdf)) |
253 | 43 | 45 | ||
254 | 44 | for page in range(reader.getNumPages()): | 46 | for page in range(reader.getNumPages()): |
255 | 45 | 47 | ||
256 | === removed file 'delivery_carrier_label_dispatch/stock.py' | |||
257 | --- delivery_carrier_label_dispatch/stock.py 2013-12-17 07:42:04 +0000 | |||
258 | +++ delivery_carrier_label_dispatch/stock.py 1970-01-01 00:00:00 +0000 | |||
259 | @@ -1,62 +0,0 @@ | |||
260 | 1 | # -*- coding: utf-8 -*- | ||
261 | 2 | ############################################################################## | ||
262 | 3 | # | ||
263 | 4 | # Author: Yannick Vaucher | ||
264 | 5 | # Copyright 2013 Camptocamp SA | ||
265 | 6 | # | ||
266 | 7 | # This program is free software: you can redistribute it and/or modify | ||
267 | 8 | # it under the terms of the GNU Affero General Public License as | ||
268 | 9 | # published by the Free Software Foundation, either version 3 of the | ||
269 | 10 | # License, or (at your option) any later version. | ||
270 | 11 | # | ||
271 | 12 | # This program is distributed in the hope that it will be useful, | ||
272 | 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
273 | 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
274 | 15 | # GNU Affero General Public License for more details. | ||
275 | 16 | # | ||
276 | 17 | # You should have received a copy of the GNU Affero General Public License | ||
277 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
278 | 19 | # | ||
279 | 20 | ############################################################################## | ||
280 | 21 | from pdf_utils import assemble_pdf | ||
281 | 22 | from openerp.osv import orm | ||
282 | 23 | |||
283 | 24 | |||
284 | 25 | class stock_picking(orm.Model): | ||
285 | 26 | _inherit = 'stock.picking' | ||
286 | 27 | |||
287 | 28 | def get_pdf_label(self, cr, uid, ids, context=None): | ||
288 | 29 | """ Return a single pdf of labels for a stock picking | ||
289 | 30 | |||
290 | 31 | If more than one label is found for a picking we merge one label per | ||
291 | 32 | tracking in a single pdf | ||
292 | 33 | |||
293 | 34 | :return: a list of pdf file data | ||
294 | 35 | """ | ||
295 | 36 | res = dict.fromkeys(ids, False) | ||
296 | 37 | label_obj = self.pool.get('shipping.label') | ||
297 | 38 | for picking_id in ids: | ||
298 | 39 | label_ids = label_obj.search(cr, uid, | ||
299 | 40 | [('file_type', '=', 'pdf'), | ||
300 | 41 | ('res_id', '=', picking_id)], | ||
301 | 42 | order='create_date', | ||
302 | 43 | context=context) | ||
303 | 44 | if label_ids: | ||
304 | 45 | all_picking_labels = label_obj.browse(cr, uid, | ||
305 | 46 | label_ids, | ||
306 | 47 | context=context) | ||
307 | 48 | |||
308 | 49 | tracking_ids = [l.tracking_id for l in all_picking_labels] | ||
309 | 50 | |||
310 | 51 | # filter for newest created label for each trackings | ||
311 | 52 | label_datas = [] | ||
312 | 53 | tracking_ids = set(tracking_ids) | ||
313 | 54 | while tracking_ids: | ||
314 | 55 | tracking_id = tracking_ids.pop() | ||
315 | 56 | for label in all_picking_labels: | ||
316 | 57 | if label.tracking_id.id == tracking_id.id: | ||
317 | 58 | label_datas.append(label.datas.decode('base64')) | ||
318 | 59 | |||
319 | 60 | label_pdf = assemble_pdf(label_datas) | ||
320 | 61 | res[picking_id] = label_pdf.encode('base64') | ||
321 | 62 | return res | ||
322 | 63 | 0 | ||
323 | === modified file 'delivery_carrier_label_dispatch/wizard/generate_labels.py' | |||
324 | --- delivery_carrier_label_dispatch/wizard/generate_labels.py 2013-12-17 07:42:04 +0000 | |||
325 | +++ delivery_carrier_label_dispatch/wizard/generate_labels.py 2014-04-10 14:10:35 +0000 | |||
326 | @@ -18,11 +18,14 @@ | |||
327 | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
328 | 19 | # | 19 | # |
329 | 20 | ############################################################################## | 20 | ############################################################################## |
330 | 21 | from operator import attrgetter | ||
331 | 22 | from itertools import groupby | ||
332 | 23 | |||
333 | 24 | from openerp.osv import orm, fields | ||
334 | 25 | from openerp.tools.translate import _ | ||
335 | 26 | |||
336 | 21 | from ..pdf_utils import assemble_pdf | 27 | from ..pdf_utils import assemble_pdf |
337 | 22 | 28 | ||
338 | 23 | from openerp.osv import orm, fields | ||
339 | 24 | from tools.translate import _ | ||
340 | 25 | |||
341 | 26 | 29 | ||
342 | 27 | class DeliveryCarrierLabelGenerate(orm.TransientModel): | 30 | class DeliveryCarrierLabelGenerate(orm.TransientModel): |
343 | 28 | 31 | ||
344 | @@ -40,52 +43,106 @@ | |||
345 | 40 | _columns = { | 43 | _columns = { |
346 | 41 | 'dispatch_ids': fields.many2many('picking.dispatch', | 44 | 'dispatch_ids': fields.many2many('picking.dispatch', |
347 | 42 | string='Picking Dispatch'), | 45 | string='Picking Dispatch'), |
349 | 43 | 'label_pdf_file': fields.binary('Labels file'), | 46 | 'generate_new_labels': fields.boolean( |
350 | 47 | 'Generate new labels', | ||
351 | 48 | help="If this option is used, new labels will be " | ||
352 | 49 | "generated for the packs even if they already have one.\n" | ||
353 | 50 | "The default is to use the existing label."), | ||
354 | 44 | } | 51 | } |
355 | 45 | 52 | ||
356 | 46 | _defaults = { | 53 | _defaults = { |
357 | 47 | 'dispatch_ids': _get_dispatch_ids, | 54 | 'dispatch_ids': _get_dispatch_ids, |
358 | 55 | 'generate_new_labels': False, | ||
359 | 48 | } | 56 | } |
360 | 49 | 57 | ||
361 | 58 | def _get_packs(self, cr, uid, wizard, dispatch, context=None): | ||
362 | 59 | moves = sorted(dispatch.move_ids, key=attrgetter('tracking_id.name')) | ||
363 | 60 | for pack, moves in groupby(moves, key=attrgetter('tracking_id')): | ||
364 | 61 | pack_label = self._find_pack_label(cr, uid, wizard, pack, | ||
365 | 62 | context=context) | ||
366 | 63 | yield pack, list(moves), pack_label | ||
367 | 64 | |||
368 | 65 | def _find_picking_label(self, cr, uid, wizard, picking, context=None): | ||
369 | 66 | label_obj = self.pool['shipping.label'] | ||
370 | 67 | domain = [('file_type', '=', 'pdf'), | ||
371 | 68 | ('res_id', '=', picking.id), | ||
372 | 69 | ('tracking_id', '=', False), | ||
373 | 70 | ] | ||
374 | 71 | label_id = label_obj.search(cr, uid, domain, order='create_date DESC', | ||
375 | 72 | limit=1, context=context) | ||
376 | 73 | if not label_id: | ||
377 | 74 | return None | ||
378 | 75 | return label_obj.browse(cr, uid, label_id[0], context=context) | ||
379 | 76 | |||
380 | 77 | def _find_pack_label(self, cr, uid, wizard, pack, context=None): | ||
381 | 78 | label_obj = self.pool['shipping.label'] | ||
382 | 79 | domain = [('file_type', '=', 'pdf'), | ||
383 | 80 | ('tracking_id', '=', pack.id), | ||
384 | 81 | ] | ||
385 | 82 | label_id = label_obj.search(cr, uid, domain, order='create_date DESC', | ||
386 | 83 | limit=1, context=context) | ||
387 | 84 | if not label_id: | ||
388 | 85 | return None | ||
389 | 86 | return label_obj.browse(cr, uid, label_id[0], context=context) | ||
390 | 87 | |||
391 | 88 | def _get_all_pdf(self, cr, uid, wizard, dispatch, context=None): | ||
392 | 89 | for pack, moves, label in self._get_packs(cr, uid, wizard, dispatch, | ||
393 | 90 | context=context): | ||
394 | 91 | if not label or wizard.generate_new_labels: | ||
395 | 92 | picking_out_obj = self.pool['stock.picking.out'] | ||
396 | 93 | picking = moves[0].picking_id | ||
397 | 94 | # generate the label of the pack | ||
398 | 95 | if pack: | ||
399 | 96 | tracking_ids = [pack.id] | ||
400 | 97 | else: | ||
401 | 98 | tracking_ids = None | ||
402 | 99 | try: | ||
403 | 100 | picking_out_obj.generate_labels( | ||
404 | 101 | cr, uid, [picking.id], | ||
405 | 102 | tracking_ids=tracking_ids, | ||
406 | 103 | context=context) | ||
407 | 104 | except orm.except_orm as e: | ||
408 | 105 | picking_name = _('Picking: %s') % picking.name | ||
409 | 106 | pack_num = _('Pack: %s') % pack.name if pack else '' | ||
410 | 107 | raise orm.except_orm( | ||
411 | 108 | e.name, | ||
412 | 109 | _('%s %s - %s') % (picking_name, pack_num, e.value)) | ||
413 | 110 | if pack: | ||
414 | 111 | label = self._find_pack_label(cr, uid, wizard, pack, | ||
415 | 112 | context=context) | ||
416 | 113 | else: | ||
417 | 114 | label = self._find_picking_label(cr, uid, wizard, picking, | ||
418 | 115 | context=context) | ||
419 | 116 | if not label: | ||
420 | 117 | continue # no label could be generated | ||
421 | 118 | yield label | ||
422 | 119 | |||
423 | 50 | def action_generate_labels(self, cr, uid, ids, context=None): | 120 | def action_generate_labels(self, cr, uid, ids, context=None): |
424 | 51 | """ | 121 | """ |
425 | 52 | Call the creation of the delivery carrier label | 122 | Call the creation of the delivery carrier label |
426 | 53 | of the missing labels and get the existing ones | 123 | of the missing labels and get the existing ones |
427 | 54 | Then merge all of them in a single PDF | 124 | Then merge all of them in a single PDF |
428 | 125 | |||
429 | 55 | """ | 126 | """ |
430 | 56 | this = self.browse(cr, uid, ids, context=context)[0] | 127 | this = self.browse(cr, uid, ids, context=context)[0] |
431 | 57 | if not this.dispatch_ids: | 128 | if not this.dispatch_ids: |
432 | 58 | raise orm.except_orm(_('Error'), _('No picking dispatch selected')) | 129 | raise orm.except_orm(_('Error'), _('No picking dispatch selected')) |
433 | 59 | 130 | ||
457 | 60 | picking_out_obj = self.pool.get('stock.picking.out') | 131 | attachment_obj = self.pool.get('ir.attachment') |
458 | 61 | 132 | ||
459 | 62 | # flatten all picking in one list to keep the order in case | 133 | for dispatch in this.dispatch_ids: |
460 | 63 | # there are multiple dispatch or if pickings | 134 | labels = self._get_all_pdf(cr, uid, this, dispatch, |
461 | 64 | # have been ordered to ease packaging | 135 | context=context) |
462 | 65 | pickings = [(pick, pick.get_pdf_label()[pick.id]) | 136 | labels = (label.datas for label in labels) |
463 | 66 | for dispatch in this.dispatch_ids | 137 | labels = (label.decode('base64') for label in labels if labels) |
464 | 67 | for pick in dispatch.related_picking_ids] | 138 | data = { |
465 | 68 | # get picking ids for which we want to generate pdf label | 139 | 'name': dispatch.name + '.pdf', |
466 | 69 | picking_ids = [pick.id for pick, pdf in pickings | 140 | 'res_id': dispatch.id, |
467 | 70 | if not pdf] | 141 | 'res_model': 'picking.dispatch', |
468 | 71 | # generate missing picking labels | 142 | 'datas': assemble_pdf(labels).encode('base64'), |
469 | 72 | picking_out_obj.action_generate_carrier_label(cr, uid, | 143 | } |
470 | 73 | picking_ids, | 144 | attachment_obj.create(cr, uid, data, context=context) |
471 | 74 | #file_type='pdf', | 145 | |
449 | 75 | context=context) | ||
450 | 76 | |||
451 | 77 | # Get all pdf files adding the newly generated ones | ||
452 | 78 | data_list = [pdf or pick.get_pdf_label()[pick.id] | ||
453 | 79 | for pick, pdf in pickings] | ||
454 | 80 | pdf_list = [data.decode('base64') for data in data_list if data] | ||
455 | 81 | pdf_file = assemble_pdf(pdf_list) | ||
456 | 82 | this.write({'label_pdf_file': pdf_file.encode('base64')}) | ||
472 | 83 | return { | 146 | return { |
480 | 84 | 'type': 'ir.actions.act_window', | 147 | 'type': 'ir.actions.act_window_close', |
474 | 85 | 'res_model': 'delivery.carrier.label.generate', | ||
475 | 86 | 'view_mode': 'form', | ||
476 | 87 | 'view_type': 'form', | ||
477 | 88 | 'res_id': this.id, | ||
478 | 89 | 'views': [(False, 'form')], | ||
479 | 90 | 'target': 'new', | ||
481 | 91 | } | 148 | } |
482 | 92 | 149 | ||
483 | === modified file 'delivery_carrier_label_dispatch/wizard/generate_labels_view.xml' | |||
484 | --- delivery_carrier_label_dispatch/wizard/generate_labels_view.xml 2013-12-06 12:51:58 +0000 | |||
485 | +++ delivery_carrier_label_dispatch/wizard/generate_labels_view.xml 2014-04-10 14:10:35 +0000 | |||
486 | @@ -7,13 +7,12 @@ | |||
487 | 7 | <field name="model">delivery.carrier.label.generate</field> | 7 | <field name="model">delivery.carrier.label.generate</field> |
488 | 8 | <field name="arch" type="xml"> | 8 | <field name="arch" type="xml"> |
489 | 9 | <form string="Generate Carriers Labels" version="7.0"> | 9 | <form string="Generate Carriers Labels" version="7.0"> |
491 | 10 | 10 | <group> | |
492 | 11 | <label string="This wizard creates an attachement on each selected dispatch containing picking labels"/> | ||
493 | 12 | </group> | ||
494 | 11 | <group> | 13 | <group> |
495 | 12 | <field name="dispatch_ids"/> | 14 | <field name="dispatch_ids"/> |
500 | 13 | </group> | 15 | <field name="generate_new_labels"/> |
497 | 14 | <separator string="Labels"/> | ||
498 | 15 | <group> | ||
499 | 16 | <field name="label_pdf_file" filename="picking_labels.pdf"/> | ||
501 | 17 | </group> | 16 | </group> |
502 | 18 | <footer> | 17 | <footer> |
503 | 19 | <button name="action_generate_labels" string="Generate Labels" type="object" icon="gtk-execute" class="oe_highlight"/> | 18 | <button name="action_generate_labels" string="Generate Labels" type="object" icon="gtk-execute" class="oe_highlight"/> |
Hi Yannick,
#file_type='pdf'
is meant to be commented out?
I approve in any case because you are not really changing that line, justing indenting it a little :)