Merge lp:~camptocamp/carriers-deliveries/7.0-needed_changes_to_fit_with_stock_picking_v7_changes-rde into lp:~stock-logistic-core-editors/carriers-deliveries/7.0

Proposed by Romain Deheele - Camptocamp
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 27
Merged at revision: 29
Proposed branch: lp:~camptocamp/carriers-deliveries/7.0-needed_changes_to_fit_with_stock_picking_v7_changes-rde
Merge into: lp:~stock-logistic-core-editors/carriers-deliveries/7.0
Diff against target: 432 lines (+108/-64)
11 files modified
base_delivery_carrier_files/__openerp__.py (+18/-10)
base_delivery_carrier_files/carrier_file.py (+38/-20)
base_delivery_carrier_files/carrier_file_demo.yml (+2/-2)
base_delivery_carrier_files/csv_writer/unicode_writer.py (+0/-1)
base_delivery_carrier_files/stock.py (+28/-9)
base_delivery_carrier_files/stock_view.xml (+6/-4)
base_delivery_carrier_files/test/carrier_file.yml (+2/-2)
base_delivery_carrier_files/test/carrier_file_manual.yml (+4/-4)
base_delivery_carrier_files/wizard/__init__.py (+1/-1)
base_delivery_carrier_files/wizard/generate_carrier_files.py (+8/-9)
base_delivery_carrier_files/wizard/generate_carrier_files_view.xml (+1/-2)
To merge this branch: bzr merge lp:~camptocamp/carriers-deliveries/7.0-needed_changes_to_fit_with_stock_picking_v7_changes-rde
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp code review, no test Approve
Yannick Vaucher @ Camptocamp code review Approve
Leonardo Pistone Approve
Review via email: mp+211056@code.launchpad.net

Description of the change

Hi,

Most of changes are about to fit with stock.picking/stock.picking.out v7 changes
(be careful about fixme in addons/delivery/stock.py in line 207)
Tests are green.

Regards,

Romain

To post a comment you must log in.
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Thanks for fixing the tests Romain. I only see a small alignment issue in l49. Can you please check that your changes pass flake8?

review: Needs Fixing (code review)
27. By Romain Deheele - Camptocamp

[UPD] clean according flake8

Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote :

Thanks Leonardo,
  PEP8 check done.

Romain

Revision history for this message
Leonardo Pistone (lepistone) :
review: Approve
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

LGTM

Thanks

review: Approve (code review)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

LGTM

review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'base_delivery_carrier_files/__openerp__.py'
2--- base_delivery_carrier_files/__openerp__.py 2014-03-13 16:11:58 +0000
3+++ base_delivery_carrier_files/__openerp__.py 2014-03-24 10:53:45 +0000
4@@ -24,19 +24,27 @@
5 'version': '1.1',
6 'category': 'Generic Modules/Warehouse',
7 'description': """
8-Base module for creation of carrier files (La Poste, TNT Express Shipper, ...). exported as text (csv, ...).
9-It contains the base structure to handle the export of files on Delivery Orders and an API to ease the generation of the files for the developers in sub-modules.
10-
11-The delivery orders can be grouped in one files or be exported each one in a separate file.
12-The files can be generated automatically on the shipment of a Delivery Order or from a manual action.
13-They are exported to a defined path or in a document directory of your choice if the "document" module is installed.
14-
15-A generic carrier file is included in the module. It can also be used as a basis to create your own sub-module.
16+Base module for creation of carrier files (La Poste, TNT Express Shipper, ...).
17+Files are exported as text (csv, ...).
18+It contains :
19+- the base structure to handle the export of files on Delivery Orders
20+- an API to ease the generation of the files for the developers in sub-modules.
21+
22+The delivery orders can be grouped in one files
23+or be exported each one in a separate file.
24+The files can be generated automatically
25+on the shipment of a Delivery Order or from a manual action.
26+They are exported to a defined path or
27+in a document directory of your choice if the "document" module is installed.
28+
29+A generic carrier file is included in the module.
30+It can also be used as a basis to create your own sub-module.
31
32 Sub-modules already exist to generate file according to specs of :
33 - La Poste (France) : delivery_carrier_file_laposte
34 - TNT Express Shipper (France) : delivery_carrier_file_tnt
35- - Make your own ! Look at the code of the modules above, it's trivial to create a sub-module for a carrier.
36+ - Make your own ! Look at the code of the modules above,
37+ it's trivial to create a sub-module for a carrier.
38
39 """,
40 'author': 'Camptocamp',
41@@ -50,7 +58,7 @@
42 'wizard/generate_carrier_files_view.xml',
43 'security/ir.model.access.csv'],
44 'demo': ['carrier_file_demo.xml',
45- 'carrier_file_demo.yml'],
46+ 'carrier_file_demo.yml'],
47 'test': ['test/carrier_file.yml',
48 'test/carrier_file_manual.yml'],
49 'images': [],
50
51=== modified file 'base_delivery_carrier_files/carrier_file.py'
52--- base_delivery_carrier_files/carrier_file.py 2014-03-13 09:19:28 +0000
53+++ base_delivery_carrier_files/carrier_file.py 2014-03-24 10:53:45 +0000
54@@ -46,42 +46,55 @@
55 'name': fields.char('Name', size=64, required=True),
56 'type': fields.selection(get_type_selection, 'Type', required=True),
57 'group_pickings': fields.boolean('Group all pickings in one file',
58- help=('All the pickings will be grouped in the same file. '
59- 'Has no effect when the files are automatically '
60- 'exported at the delivery order process.')),
61- 'write_mode': fields.selection(get_write_mode_selection, 'Write on', required=True),
62+ help='All the pickings will be '
63+ 'grouped in the same file. '
64+ 'Has no effect when the files '
65+ 'are automatically exported at '
66+ 'the delivery order process.'),
67+ 'write_mode': fields.selection(get_write_mode_selection,
68+ 'Write on',
69+ required=True),
70 'export_path': fields.char('Export Path', size=256),
71 'auto_export': fields.boolean('Export at delivery order process',
72- help=("The file will be automatically generated when a "
73- "delivery order is processed. If activated, each "
74- "delivery order will be exported in a separate file.")),
75+ help='The file will be automatically '
76+ 'generated when a delivery order '
77+ 'is processed. If activated, each '
78+ 'delivery order will be exported '
79+ 'in a separate file.'),
80 }
81
82- def _write_file(self, cr, uid, carrier_file, filename, file_content, context=None):
83+ def _write_file(self, cr, uid, carrier_file, filename, file_content,
84+ context=None):
85 """
86 Method responsible of writing the file, on the filesystem or
87 by inheriting the module, in the document module as instance
88
89- :param browse_record carrier_file: browsable carrier.file (configuration)
90+ :param browse_record carrier_file: browsable carrier.file
91+ (configuration)
92 :param tuple filename: name of the file to write
93 :param tuple file_content: content of the file to write
94 :return: True if write is successful
95 """
96 if not carrier_file.export_path:
97- raise osv.except_osv(_('Error'),
98- _('Export path is not defined for carrier file %s') %
99+ raise orm.except_orm(_('Error'),
100+ _('Export path is not defined '
101+ 'for carrier file %s') %
102 (carrier_file.name,))
103 full_path = os.path.join(carrier_file.export_path, filename)
104 with open(full_path, 'w') as file_handle:
105 file_handle.write(file_content)
106 return True
107
108- def _generate_files(self, cr, uid, carrier_file, picking_ids, context=None):
109+ def _generate_files(self, cr, uid, carrier_file, picking_ids,
110+ context=None):
111 """
112- Generate one or more files according to carrier_file configuration for all picking_ids
113+ Generate one or more files according to carrier_file configuration
114+ for all picking_ids
115
116- :param browse_record carrier_file: browsable carrier file configuration
117- :param list picking_ids: list of ids of pickings for which we have to generate a file
118+ :param browse_record carrier_file: browsable carrier file
119+ configuration
120+ :param list picking_ids: list of ids of pickings for which
121+ we have to generate a file
122 :return: True if successful
123 """
124 picking_obj = self.pool.get('stock.picking')
125@@ -106,11 +119,13 @@
126 {'carrier_file_generated': True},
127 context=context)
128 except Exception, e:
129- log.exception("Could not create the picking file for pickings %s: %s",
130+ log.exception("Could not create the picking file "
131+ "for pickings %s: %s",
132 picking_ids, e)
133 return True
134
135- def generate_files(self, cr, uid, carrier_file_id, picking_ids, context=None):
136+ def generate_files(self, cr, uid, carrier_file_id, picking_ids,
137+ context=None):
138 """
139 Generate one or more files according to carrier_file
140 configuration for all picking_ids
141@@ -124,16 +139,19 @@
142 """
143 if not isinstance(carrier_file_id, (int, long)):
144 if len(carrier_file_id) > 1:
145- raise Exception('Code Error: you have to export only one carrier at a time.')
146+ raise Exception('Code Error: you have to export '
147+ 'only one carrier at a time.')
148 else:
149 carrier_file_id = carrier_file_id[0]
150 carrier_file = self.browse(cr, uid, carrier_file_id, context=context)
151- return self._generate_files(cr, uid, carrier_file, picking_ids, context=context)
152+ return self._generate_files(cr, uid, carrier_file, picking_ids,
153+ context=context)
154
155
156 class delivery_carrier(orm.Model):
157 _inherit = 'delivery.carrier'
158
159 _columns = {
160- 'carrier_file_id': fields.many2one('delivery.carrier.file', 'Carrier File')
161+ 'carrier_file_id': fields.many2one('delivery.carrier.file',
162+ 'Carrier File')
163 }
164
165=== modified file 'base_delivery_carrier_files/carrier_file_demo.yml'
166--- base_delivery_carrier_files/carrier_file_demo.yml 2014-03-13 09:19:28 +0000
167+++ base_delivery_carrier_files/carrier_file_demo.yml 2014-03-24 10:53:45 +0000
168@@ -28,7 +28,7 @@
169 property_stock_account_output: account.o_income
170 description: Ice cream can be mass-produced and thus is widely available in developed parts of the world. Ice cream can be purchased in large cartons (vats and squrounds) from supermarkets and grocery stores, in smaller quantities from ice cream shops, convenience stores, and milk bars, and in individual servings from small carts or vans at public events.
171 -
172- !record {model: stock.picking, id: outgoing_shipment_carrier_file}:
173+ !record {model: stock.picking.out, id: outgoing_shipment_carrier_file}:
174 type: out
175 location_dest_id: location_delivery_counter
176 carrier_id: delivery.delivery_carrier
177@@ -41,7 +41,7 @@
178 location_id: location_refrigerator
179 location_dest_id: location_delivery_counter
180 -
181- !record {model: stock.picking, id: outgoing_shipment_carrier_file_manual}:
182+ !record {model: stock.picking.out, id: outgoing_shipment_carrier_file_manual}:
183 type: out
184 location_dest_id: location_delivery_counter
185 carrier_id: delivery.free_delivery_carrier
186
187=== modified file 'base_delivery_carrier_files/csv_writer/unicode_writer.py'
188--- base_delivery_carrier_files/csv_writer/unicode_writer.py 2012-02-20 13:45:30 +0000
189+++ base_delivery_carrier_files/csv_writer/unicode_writer.py 2014-03-24 10:53:45 +0000
190@@ -8,7 +8,6 @@
191 import StringIO
192
193
194-
195 class UnicodeWriter(object):
196 """
197 A CSV writer which will write rows to CSV file "f",
198
199=== modified file 'base_delivery_carrier_files/stock.py'
200--- base_delivery_carrier_files/stock.py 2014-03-13 09:19:28 +0000
201+++ base_delivery_carrier_files/stock.py 2014-03-24 10:53:45 +0000
202@@ -26,8 +26,11 @@
203 _inherit = 'stock.picking'
204
205 _columns = {
206- 'carrier_file_generated': fields.boolean('Carrier File Generated', readonly=True,
207- help="The file for the delivery carrier has been generated."),
208+ 'carrier_file_generated': fields.boolean('Carrier File Generated',
209+ readonly=True,
210+ help="The file for "
211+ "the delivery carrier "
212+ "has been generated."),
213 }
214
215 def generate_carrier_files(self, cr, uid, ids, auto=True, context=None):
216@@ -53,21 +56,25 @@
217 continue
218 if picking.carrier_file_generated:
219 continue
220- if not picking.carrier_id or not picking.carrier_id.carrier_file_id:
221+ carrier = picking.carrier_id
222+ if not carrier or not carrier.carrier_file_id:
223 continue
224- if auto and not picking.carrier_id.carrier_file_id.auto_export:
225+ if auto and not carrier.carrier_file_id.auto_export:
226 continue
227 p_carrier_file_id = picking.carrier_id.carrier_file_id.id
228- carrier_file_ids.setdefault(p_carrier_file_id, []).append(picking.id)
229+ carrier_file_ids.setdefault(p_carrier_file_id, []).\
230+ append(picking.id)
231
232- for carrier_file_id, carrier_picking_ids in carrier_file_ids.iteritems():
233+ for carrier_file_id, carrier_picking_ids\
234+ in carrier_file_ids.iteritems():
235 carrier_file_obj.generate_files(cr, uid, carrier_file_id,
236 carrier_picking_ids,
237 context=context)
238 return True
239
240 def action_done(self, cr, uid, ids, context=None):
241- result = super(stock_picking, self).action_done(cr, uid, ids, context=context)
242+ result = super(stock_picking, self).action_done(cr, uid, ids,
243+ context=context)
244 self.generate_carrier_files(cr, uid, ids, auto=True, context=context)
245 return result
246
247@@ -75,5 +82,17 @@
248 if default is None:
249 default = {}
250 default.update({'carrier_file_generated': False})
251- return super(stock_picking, self).copy(cr, uid, id, default, context=context)
252-
253+ return super(stock_picking, self).copy(cr, uid, id, default,
254+ context=context)
255+
256+
257+class stock_picking_out(orm.Model):
258+ _inherit = 'stock.picking.out'
259+
260+ _columns = {
261+ 'carrier_file_generated': fields.boolean('Carrier File Generated',
262+ readonly=True,
263+ help="The file for "
264+ "the delivery carrier "
265+ "has been generated."),
266+ }
267
268=== modified file 'base_delivery_carrier_files/stock_view.xml'
269--- base_delivery_carrier_files/stock_view.xml 2014-03-13 09:19:28 +0000
270+++ base_delivery_carrier_files/stock_view.xml 2014-03-24 10:53:45 +0000
271@@ -3,12 +3,14 @@
272 <data>
273 <record id="view_picking_out_form_carrier_file" model="ir.ui.view">
274 <field name="name">stock.picking.out.form</field>
275- <field name="model">stock.picking</field>
276+ <field name="model">stock.picking.out</field>
277 <field name="inherit_id" ref="stock.view_picking_out_form"/>
278 <field name="arch" type="xml">
279 <data>
280- <page string="Additional info" position="inside">
281- <field name="carrier_file_generated"/>
282+ <page string="Additional Info" position="inside">
283+ <group>
284+ <field name="carrier_file_generated"/>
285+ </group>
286 </page>
287 </data>
288 </field>
289@@ -16,7 +18,7 @@
290
291 <record id="view_picking_out_search_carrier_file" model="ir.ui.view">
292 <field name="name">stock.picking.out.search</field>
293- <field name="model">stock.picking</field>
294+ <field name="model">stock.picking.out</field>
295 <field name="inherit_id" ref="stock.view_picking_out_search"/>
296 <field name="arch" type="xml">
297 <data>
298
299=== modified file 'base_delivery_carrier_files/test/carrier_file.yml'
300--- base_delivery_carrier_files/test/carrier_file.yml 2012-02-20 13:45:30 +0000
301+++ base_delivery_carrier_files/test/carrier_file.yml 2014-03-24 10:53:45 +0000
302@@ -26,7 +26,7 @@
303 I deliver outgoing shipment.
304 -
305 !python {model: stock.partial.picking}: |
306- context.update({'active_model': 'stock.picking', 'active_id': ref('outgoing_shipment_carrier_file'), 'active_ids': [ref('outgoing_shipment_carrier_file')]})
307+ context.update({'active_model': 'stock.picking.out', 'active_id': ref('outgoing_shipment_carrier_file'), 'active_ids': [ref('outgoing_shipment_carrier_file')]})
308 -
309 !record {model: stock.partial.picking, id: partial_outgoing}:
310 picking_id: outgoing_shipment_carrier_file
311@@ -36,5 +36,5 @@
312 -
313 I check shipment details after shipment, the carrier file must have been generated
314 -
315- !assert {model: stock.picking, id: outgoing_shipment_carrier_file, string: Carrier file should be generated}:
316+ !assert {model: stock.picking.out, id: outgoing_shipment_carrier_file, string: Carrier file should be generated}:
317 - carrier_file_generated == True
318
319=== modified file 'base_delivery_carrier_files/test/carrier_file_manual.yml'
320--- base_delivery_carrier_files/test/carrier_file_manual.yml 2012-02-20 13:45:30 +0000
321+++ base_delivery_carrier_files/test/carrier_file_manual.yml 2014-03-24 10:53:45 +0000
322@@ -26,7 +26,7 @@
323 I deliver outgoing shipment.
324 -
325 !python {model: stock.partial.picking}: |
326- context.update({'active_model': 'stock.picking', 'active_id': ref('outgoing_shipment_carrier_file_manual'), 'active_ids': [ref('outgoing_shipment_carrier_file_manual')]})
327+ context.update({'active_model': 'stock.picking.out', 'active_id': ref('outgoing_shipment_carrier_file_manual'), 'active_ids': [ref('outgoing_shipment_carrier_file_manual')]})
328 -
329 !record {model: stock.partial.picking, id: partial_outgoing}:
330 picking_id: outgoing_shipment_carrier_file_manual
331@@ -36,16 +36,16 @@
332 -
333 I check shipment details after shipping, the carrier file must not have been generated
334 -
335- !assert {model: stock.picking, id: outgoing_shipment_carrier_file_manual, string: Carrier file should be generated}:
336+ !assert {model: stock.picking.out, id: outgoing_shipment_carrier_file_manual, string: Carrier file should be generated}:
337 - carrier_file_generated is False
338 -
339 I generate the carrier files of my shipment from the wizard
340 -
341 !python {model: delivery.carrier.file.generate}: |
342- wizard_id = self.create(cr, uid, {}, {'active_ids': [ref('outgoing_shipment_carrier_file_manual')], 'active_model': 'stock.picking'})
343+ wizard_id = self.create(cr, uid, {}, {'active_ids': [ref('outgoing_shipment_carrier_file_manual')], 'active_model': 'stock.picking.out'})
344 self.action_generate(cr, uid, [wizard_id], {'active_ids': [ref('outgoing_shipment_carrier_file_manual')]})
345 -
346 I check shipment details after manual generation, the carrier file must have been generated
347 -
348- !assert {model: stock.picking, id: outgoing_shipment_carrier_file_manual, string: Carrier file should be generated}:
349+ !assert {model: stock.picking.out, id: outgoing_shipment_carrier_file_manual, string: Carrier file should be generated}:
350 - carrier_file_generated == True
351
352=== modified file 'base_delivery_carrier_files/wizard/__init__.py'
353--- base_delivery_carrier_files/wizard/__init__.py 2012-04-02 06:59:30 +0000
354+++ base_delivery_carrier_files/wizard/__init__.py 2014-03-24 10:53:45 +0000
355@@ -19,4 +19,4 @@
356 #
357 ##############################################################################
358
359-import generate_carrier_files
360+from . import generate_carrier_files
361
362=== modified file 'base_delivery_carrier_files/wizard/generate_carrier_files.py'
363--- base_delivery_carrier_files/wizard/generate_carrier_files.py 2012-04-02 06:59:30 +0000
364+++ base_delivery_carrier_files/wizard/generate_carrier_files.py 2014-03-24 10:53:45 +0000
365@@ -19,24 +19,25 @@
366 #
367 ##############################################################################
368
369-from osv import osv, fields
370+from openerp.osv import orm, fields
371 from tools.translate import _
372
373
374-class DeliveryCarrierFileGenerate(osv.osv_memory):
375+class DeliveryCarrierFileGenerate(orm.TransientModel):
376
377 _name = 'delivery.carrier.file.generate'
378
379 def _get_picking_ids(self, cr, uid, context=None):
380- if context is None: context = {}
381+ if context is None:
382+ context = {}
383 res = False
384- if (context.get('active_model', False) == 'stock.picking' and
385- context.get('active_ids', False)):
386+ if (context.get('active_model', False) == 'stock.picking.out' and
387+ context.get('active_ids', False)):
388 res = context['active_ids']
389 return res
390
391 _columns = {
392- 'picking_ids': fields.many2many('stock.picking',
393+ 'picking_ids': fields.many2many('stock.picking.out',
394 string='Delivery Orders'),
395 }
396
397@@ -51,7 +52,7 @@
398 context = context or {}
399 form = self.browse(cr, uid, ids, context=context)[0]
400 if not form.picking_ids:
401- raise osv.except_osv(_('Error'), _('No delivery orders selected'))
402+ raise orm.except_orm(_('Error'), _('No delivery orders selected'))
403
404 picking_obj = self.pool.get('stock.picking')
405 picking_ids = [picking.id for picking in form.picking_ids]
406@@ -61,5 +62,3 @@
407 context=context)
408
409 return {'type': 'ir.actions.act_window_close'}
410-
411-DeliveryCarrierFileGenerate()
412
413=== modified file 'base_delivery_carrier_files/wizard/generate_carrier_files_view.xml'
414--- base_delivery_carrier_files/wizard/generate_carrier_files_view.xml 2012-02-20 13:45:30 +0000
415+++ base_delivery_carrier_files/wizard/generate_carrier_files_view.xml 2014-03-24 10:53:45 +0000
416@@ -5,7 +5,6 @@
417 <record id="view_delivery_carrier_file_generate" model="ir.ui.view">
418 <field name="name">delivery.carrier.file.generate</field>
419 <field name="model">delivery.carrier.file.generate</field>
420- <field name="type">form</field>
421 <field name="arch" type="xml">
422 <form string="Carrier Files">
423 <label string="Generate the carrier files for the selected delivery orders."/>
424@@ -42,7 +41,7 @@
425 <field name="key2">client_action_multi</field>
426 <field name="value" eval="'ir.actions.act_window,' + str(ref('action_delivery_carrier_file_generate'))" />
427 <field name="key">action</field>
428- <field name="model">stock.picking</field>
429+ <field name="model">stock.picking.out</field>
430 </record>
431
432 </data>

Subscribers

People subscribed via source and target branches