← Back to team overview

credativ team mailing list archive

[Merge] lp:~matthieuchoplin/credativ-openerp/ERP-449 into lp:credativ-openerp

 

Matthieu Choplin has proposed merging lp:~matthieuchoplin/credativ-openerp/ERP-449 into lp:credativ-openerp.

Requested reviews:
  credativ (credativ)

For more details, see:
https://code.launchpad.net/~matthieuchoplin/credativ-openerp/ERP-449/+merge/202729

Hello,

this branch aims to answer the Jira issue ERP-449
-- 
https://code.launchpad.net/~matthieuchoplin/credativ-openerp/ERP-449/+merge/202729
Your team credativ is requested to review the proposed merge of lp:~matthieuchoplin/credativ-openerp/ERP-449 into lp:credativ-openerp.
=== modified file 'wms_integration/__init__.py'
--- wms_integration/__init__.py	2013-02-08 08:17:27 +0000
+++ wms_integration/__init__.py	2014-01-22 18:30:51 +0000
@@ -23,3 +23,4 @@
 import purchase
 import stock_dispatch
 import stock
+import res_users

=== modified file 'wms_integration/__openerp__.py'
--- wms_integration/__openerp__.py	2013-01-15 12:24:55 +0000
+++ wms_integration/__openerp__.py	2014-01-22 18:30:51 +0000
@@ -35,7 +35,8 @@
                 'sale'],
     'update_xml': ['wms_integration_core_view.xml',
                    'stock_warehouse_view.xml',
-                   'settings/external.referential.type.csv'],
+                   'settings/external.referential.type.csv',
+                   'res_users_view.xml'],
     'demo_xml': [],
     'installable': True,
     'active': False,

=== added file 'wms_integration/res_users.py'
--- wms_integration/res_users.py	1970-01-01 00:00:00 +0000
+++ wms_integration/res_users.py	2014-01-22 18:30:51 +0000
@@ -0,0 +1,35 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution   
+#    Copyright (C) 2009 credativ Ltd (<http://credativ.co.uk>).
+#    All Rights Reserved
+#    $Id$
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU 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 General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+from osv import fields,osv
+
+
+class res_users(osv.osv):
+    _inherit = 'res.users'
+    _columns = {
+        'orium_report': fields.boolean('Receive Orium discrepancy report'),
+    }
+
+res_users()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+

=== added file 'wms_integration/res_users_view.xml'
--- wms_integration/res_users_view.xml	1970-01-01 00:00:00 +0000
+++ wms_integration/res_users_view.xml	2014-01-22 18:30:51 +0000
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+
+        <record id="view_users_form_wms_integration" model="ir.ui.view">
+                <field name="name">view.users.form.integration</field>
+                <field name="model">res.users</field>
+                <field name="type">form</field>
+                <field name="inherit_id" ref="base.view_users_form"/>
+                <field eval="16" name="priority"/>
+                <field name="arch" type="xml">
+                    <group name="default_filters" position="inside">
+                        <field name="orium_report" />
+                    </group>
+                </field>
+        </record>
+	</data>
+</openerp>

=== modified file 'wms_integration/stock.py'
--- wms_integration/stock.py	2013-02-28 08:16:06 +0000
+++ wms_integration/stock.py	2014-01-22 18:30:51 +0000
@@ -26,6 +26,8 @@
 import pooler
 import os
 DEBUG = True
+from email.mime.multipart import MIMEMultipart
+from email.mime.text import MIMEText
 
 _logger = logging.getLogger(__name__)
 
@@ -40,6 +42,7 @@
         'mapping_dispatch_orders_id': fields.many2one('external.mapping', string='Override Dispatch Export Mapping'),
         'mapping_purchase_orders_import_id': fields.many2one('external.mapping', string='Override Purchase Orders Import Mapping'),
         'mapping_dispatch_orders_import_id': fields.many2one('external.mapping', string='Override Dispatch Import Mapping'),
+        'mapping_stock_image_import_id': fields.many2one('external.mapping', string='Stock Image'),
     }
     
     def get_exportable_pos(self, cr, uid, ids, referential_id, context=None):
@@ -238,6 +241,86 @@
                 _cr.close()
         return True
 
+    def import_stock_image(self, cr, uid, ids, context=None):
+        if context == None:
+            context = {}
+        if not isinstance(ids, list):
+            ids = [ids]
+        product_obj = self.pool.get('product.product')
+        user_obj = self.pool.get('res.users')
+        for warehouse in self.browse(cr, uid, ids):
+            if not warehouse.referential_id or not warehouse.mapping_purchase_orders_import_id:
+                continue
+            
+            _cr = pooler.get_db(cr.dbname).cursor()
+            try:
+                stock_image_import, fn = self.pool.get('external.referential')._import(_cr, uid, warehouse.mapping_stock_image_import_id, context=context)
+            except:
+                _cr.rollback()
+                raise
+            finally:
+                _cr.close()
+            if not fn:
+                continue
+            orium_list_dict = stock_image_import[0]
+            orium_dict = dict([(x['sku'], x) for x in orium_list_dict])
+            orium_sku_list = orium_dict.keys()
+            cr.execute("select p.default_code from mrp_bom b left join product_product p on b.product_id=p.id where b.bom_id is null")
+            bom_list = [x[0] for x in cr.fetchall()]
+            p_ids = product_obj.search(cr, uid, [], context=context)
+            made_dict = dict([(x['default_code'], x) for x in product_obj.read(cr, uid, p_ids, ['default_code', 'qty_available'], context)])
+            made_sku_list = made_dict.keys()
+            message = ""
+            list_to_check = [x for x in made_sku_list if x in orium_sku_list and x not in bom_list]
+            for z in list_to_check:
+                orium_qty = orium_dict[z]['qty'].strip()
+                made_qty = made_dict[z]['qty_available']
+                if not orium_qty:
+                    orium_qty = 0
+                if not made_qty:
+                    made_qty = 0
+                diff = int(orium_qty) - int(made_qty)
+                if diff != 0:
+                    message += "%s: %s \n" % (z, diff)
+            msg = MIMEMultipart()
+            subject = 'Stock Image Discrepancies with Orium'
+            msg['Subject'] = subject
+            me = 'erp@xxxxxxxx'
+            receiver_ids = user_obj.search(cr, uid, [('orium_report', '=', True)])
+            receivers = [x['user_email'] for x in user_obj.read(cr, uid, receiver_ids, ['user_email'])]
+            msg['From'] = me
+            msg['To'] = ', '.join(receivers)
+            msg['Body'] = 'Please find attached the "%s".' % subject
+            msg.preamble = 'Test preambule'
+            attachm = MIMEText(message)
+            attachm.add_header('Content-Disposition', 'attachment', filename='report')
+            msg.attach(attachm)
+            self.pool.get('ir.mail_server').send_email(cr, uid, msg)
+            _cr = pooler.get_db(cr.dbname).cursor()
+            try:
+                if fn:
+                    conn = self.pool.get('external.referential').external_connection(_cr, uid, warehouse.mapping_stock_image_import_id.referential_id.id, DEBUG, context=context)
+                    fpath, fname = os.path.split(fn)
+                    remote_csv_fn_rn = os.path.join(fpath, 'Archives', fname)
+                    _logger.info("Archiving imported STOCK IMAGE file %s as %s" % (fn, remote_csv_fn_rn))
+                    conn.rename_file(fn, remote_csv_fn_rn, context=context)
+                    conn.finalize_rename(context=context)
+                    _cr.commit()
+            except:
+                _cr.rollback()
+                raise
+            finally:
+                _cr.close()
+        return True
+
+    def run_import_stock_image_scheduler(self, cr, uid, context=None):
+        warehouse_ids = self.search(cr, uid, [], context=context)
+        for warehouse in self.browse(cr, uid, warehouse_ids, context=context):
+            if warehouse.referential_id:
+                _logger.info("Running Stock Image comparison scheduler for Warehouse %d" % (warehouse.id))
+                warehouse.import_stock_image(context=context)
+        return True
+
     def run_export_purchase_orders_scheduler(self, cr, uid, context=None):
         warehouse_ids = self.search(cr, uid, [], context=context)
         for warehouse in self.browse(cr, uid, warehouse_ids, context=context):

=== modified file 'wms_integration/stock_warehouse_view.xml'
--- wms_integration/stock_warehouse_view.xml	2013-02-05 15:26:02 +0000
+++ wms_integration/stock_warehouse_view.xml	2014-01-22 18:30:51 +0000
@@ -21,6 +21,7 @@
                                 <field name="mapping_dispatch_orders_id" domain="[('referential_id', '=', referential_id), ('model_id.model', '=', 'stock.move')]"/>
                                 <button name="import_dispatch_receipts" string="4 - Import Dispatch Receipts" colspan="2" type="object" />
                                 <field name="mapping_dispatch_orders_import_id" domain="[('referential_id', '=', referential_id), ('model_id.model', '=', 'stock.move')]"/>
+                                <button name="import_stock_image" string="5 - Import Stock Image" colspan="2" type="object" />
                             </page>
                             <page string="External Warehouse Settings">
                                 <field name="referential_id"/>


Follow ups