← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/carriers-deliveries/7.0-associate-attachment-and-picking_rde into lp:carriers-deliveries

 

Romain Deheele - Camptocamp has proposed merging lp:~camptocamp/carriers-deliveries/7.0-associate-attachment-and-picking_rde into lp:carriers-deliveries.

Requested reviews:
  Stock and Logistic Core Editors (stock-logistic-core-editors)

For more details, see:
https://code.launchpad.net/~camptocamp/carriers-deliveries/7.0-associate-attachment-and-picking_rde/+merge/213427

Hi,

Currently, if the carrier file is configured to be:
- exported at delivery order process (one separate file by delivery order)
- saved as ir.attachment (thanks to base_delivery_carrier_files_document)
an attachment is created but without direct link with delivery order.
This MP allows to populate res_model and res_id on ir.attachment creation to link it with the delivery order (who has generated this attachment). To do that, the picking id needs to be added in context until attachment creation.

This change is useful to easily find the carrier file generated from a delivery order several days after.

Maybe we should add a checkbox to allow to decide if the carrier file must be linked directly with delivery order, or not?

Regards,

Romain
-- 
https://code.launchpad.net/~camptocamp/carriers-deliveries/7.0-associate-attachment-and-picking_rde/+merge/213427
Your team Stock and Logistic Core Editors is requested to review the proposed merge of lp:~camptocamp/carriers-deliveries/7.0-associate-attachment-and-picking_rde into lp:carriers-deliveries.
=== modified file 'base_delivery_carrier_files/carrier_file.py'
--- base_delivery_carrier_files/carrier_file.py	2014-03-24 10:53:06 +0000
+++ base_delivery_carrier_files/carrier_file.py	2014-03-31 09:48:31 +0000
@@ -97,6 +97,8 @@
                                  we have to generate a file
         :return: True if successful
         """
+        if context is None:
+            context = {}
         picking_obj = self.pool.get('stock.picking')
         log = logging.getLogger('delivery.carrier.file')
         file_generator = new_file_generator(carrier_file.type)
@@ -104,6 +106,8 @@
                     picking_obj.browse(cr, uid, picking_ids, context=context)]
         # must return a list of generated pickings ids to update
         files = file_generator.generate_files(pickings, carrier_file)
+        if carrier_file.auto_export:
+            context['picking_id'] = pickings and pickings[0].id
         for file in files:
             filename, file_content, picking_ids = file
             # we pass the errors because the files can still be

=== modified file 'base_delivery_carrier_files_document/carrier_file.py'
--- base_delivery_carrier_files_document/carrier_file.py	2014-03-27 14:49:41 +0000
+++ base_delivery_carrier_files_document/carrier_file.py	2014-03-31 09:48:31 +0000
@@ -48,13 +48,15 @@
                 'datas_fname': filename,
                 'datas': base64.encodestring(file_content),
                 'parent_id': carrier_file.document_directory_id.id,
-                'type': 'binary'}
+                'type': 'binary',
+                'res_model': 'stock.picking.out',
+                'res_id': carrier_file.auto_export and context['picking_id'] or False}
 
     def _write_file(self, cr, uid, carrier_file, filename, file_content,
                     context=None):
         if carrier_file.write_mode == 'document':
             vals = self._prepare_attachment(carrier_file, filename,
-                                            file_content)
+                                            file_content, context=context)
             self.pool['ir.attachment'].create(cr, uid, vals, context=context)
             return True
         else:


Follow ups