← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~agilebg/purchase-wkfl/imp_product_by_supplier into lp:purchase-wkfl

 

Lorenzo Battistini - Agile BG has proposed merging lp:~agilebg/purchase-wkfl/imp_product_by_supplier into lp:purchase-wkfl.

Requested reviews:
  Purchase Core Editors (purchase-core-editors)

For more details, see:
https://code.launchpad.net/~agilebg/purchase-wkfl/imp_product_by_supplier/+merge/219017

adding funciotnalities from product_search_reference.
Now it's possible to search products everywhere by supplier code
-- 
https://code.launchpad.net/~agilebg/purchase-wkfl/imp_product_by_supplier/+merge/219017
Your team Purchase Core Editors is requested to review the proposed merge of lp:~agilebg/purchase-wkfl/imp_product_by_supplier into lp:purchase-wkfl.
=== modified file 'product_by_supplier/product.py'
--- product_by_supplier/product.py	2013-11-12 01:44:31 +0000
+++ product_by_supplier/product.py	2014-05-09 16:21:02 +0000
@@ -2,6 +2,7 @@
 ##############################################################################
 #
 #    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
 #    Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
 #    Author: Yannick Gouin <yannick.gouin@xxxxxxxxxxxxxx>
 #
@@ -53,4 +54,46 @@
                                  ),
     }
 
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+
+class product_product(orm.Model):
+    _inherit = 'product.product'
+
+    def _partner_ref2(self, cr, user, ids, name, arg, context=None):
+        res = {}
+        for product in self.browse(cr, user, ids, context=context):
+            res[product.id] = '\n'.join(
+                [x.product_code for x in product.seller_ids if x.product_code]
+                ) or ''
+        return res
+
+    def _partner_ref2_search(self, cr, user, obj, name, args, context={}):
+        supplierinfo_obj = self.pool.get('product.supplierinfo')
+        args = args[:]
+        i = 0
+        while i < len(args):
+            args[i] = ('product_code', args[i][1], args[i][2])
+            i += 1
+        supplierinfo_ids = supplierinfo_obj.search(cr, user, args)
+        product_ids = [x.product_id.id for x in supplierinfo_obj.browse(
+            cr, user,
+            supplierinfo_ids) if x.product_id]
+        return [('id', 'in', product_ids)]
+
+    _columns = {
+        'partner_ref2': fields.function(
+            _partner_ref2, method=True,
+            type='char', string='Supplier codes',
+            fnct_search=_partner_ref2_search),
+    }
+
+    def name_search(
+            self, cr, user, name='', args=None, operator='ilike',
+            context=None, limit=80):
+        ids = self.search(
+            cr, user, [('partner_ref2', '=', name)] + args,
+            limit=limit, context=context)
+        if ids:
+            return self.name_get(cr, user, ids, context=context)
+        return super(product_product, self).name_search(
+            cr, user, name=name, args=args,
+            operator=operator, context=context, limit=limit)

=== modified file 'product_by_supplier/product_view.xml'
--- product_by_supplier/product_view.xml	2014-02-06 19:59:12 +0000
+++ product_by_supplier/product_view.xml	2014-05-09 16:21:02 +0000
@@ -1,6 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <openerp>
     <data>
+        
+        <!-- Supplier info -->
+        
         <record id="view_product_supplierinfo_search" model="ir.ui.view">
             <field name="name">product.supplierinfo.search</field>
             <field name="model">product.supplierinfo</field>
@@ -71,5 +74,30 @@
             sequence="15"
             action="action_product_supplier_info"
             parent="purchase.menu_procurement_management_product"/>
+        
+        <!-- Product -->
+
+        <record model="ir.ui.view" id="product_product_tree_view_inherit">
+            <field name="name">product.product.tree.inherit</field>
+            <field name="model">product.product</field>
+            <field name="inherit_id" ref="product.product_product_tree_view"/>
+            <field name="arch" type="xml">
+                <field name="state" position="before">
+                    <field name="partner_ref2"/>
+                </field>
+            </field>
+        </record>
+        
+        <record model="ir.ui.view" id="product_search_form_view">
+            <field name="name">product_search_form_view</field>
+            <field name="model">product.product</field>
+            <field name="inherit_id" ref="product.product_search_form_view"/>
+            <field name="arch" type="xml">
+                <field name="name" position="after">
+                    <field name="partner_ref2"/>
+                </field>
+            </field>
+        </record>
+        
     </data>
 </openerp>


Follow ups