Merge lp:~agilebg/purchase-wkfl/imp_product_by_supplier into lp:~purchase-core-editors/purchase-wkfl/7.0

Proposed by Alex Comba - Agile BG
Status: Needs review
Proposed branch: lp:~agilebg/purchase-wkfl/imp_product_by_supplier
Merge into: lp:~purchase-core-editors/purchase-wkfl/7.0
Diff against target: 212 lines (+132/-17)
2 files modified
product_by_supplier/product.py (+55/-2)
product_by_supplier/product_view.xml (+77/-15)
To merge this branch: bzr merge lp:~agilebg/purchase-wkfl/imp_product_by_supplier
Reviewer Review Type Date Requested Status
Pedro Manuel Baeza Needs Resubmitting
Leonardo Pistone Needs Fixing
Lorenzo Battistini (community) Approve
Review via email: mp+225197@code.launchpad.net

This proposal supersedes a proposal from 2014-05-09.

Description of the change

adding funciotnalities from product_search_reference.
Now it's possible to search products everywhere by supplier code

In the rev. 34 I merged https://code.launchpad.net/~agilebg/purchase-wkfl/fix_1335153 useful to fix the following bug: https://bugs.launchpad.net/purchase-wkfl/+bug/1335153

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote : Posted in a previous version of this proposal

Hi, Lorenzo, thanks for expanding this module.

I see a possible problem giving more priority to partner search than to any other, because you make a return in case that there are ids in this search. I think you must join all results to allow for example "Search more..." option to appear.

Regards.

review: Needs Information (code review)
Revision history for this message
Lorenzo Battistini (elbati) wrote : Posted in a previous version of this proposal

Hello Pedro,
just modified the name_search.
Thanks

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote : Posted in a previous version of this proposal

Thanks for the changes.

Regards.

review: Approve (code review)
Revision history for this message
Lorenzo Battistini (elbati) :
review: Approve
35. By Lorenzo Battistini

[FIX] without this change, the _partner_ref2_search method only works when template ID == product ID

36. By Lorenzo Battistini

[IMP] PEP8

Revision history for this message
Leonardo Pistone (lepistone) wrote :

Hi.

l27: where you do '\n'.join I would feel more confortable having u'\n'.join because char fields are unicode, at least with translated fields (by the way, "at least" is a bad inconsistency in the framework).

l32: context={} -> context=None

self.pool.get -> self.pool[]

thanks

review: Needs Fixing
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

This project is now hosted on https://github.com/OCA/purchase-workflow. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Needs Resubmitting
37. By Hurrinico

[FIX] lep's fixing

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

@hurrinco: this won't be merged on Launchpad, as the project is now managed on github. Please migrate the MP to a github PR (cf. Pedro's comment above)

Revision history for this message
Nicola Malcontenti - Agile BG (hurrin1c0) wrote :

> @hurrinco: this won't be merged on Launchpad, as the project is now managed on
> github. Please migrate the MP to a github PR (cf. Pedro's comment above)
I've made a mistake, it's already on github https://github.com/OCA/purchase-workflow/pull/16#issuecomment-52650828

Unmerged revisions

37. By Hurrinico

[FIX] lep's fixing

36. By Lorenzo Battistini

[IMP] PEP8

35. By Lorenzo Battistini

[FIX] without this change, the _partner_ref2_search method only works when template ID == product ID

34. By Alex Comba - Agile BG

[MRG] Merged lp:~agilebg/purchase-wkfl/fix_1335153

33. By Lorenzo Battistini

[IMP] join all results to allow for example "Search more..." option to appear

32. By Lorenzo Battistini

[IMP] product_by_supplier adding funciotnalities from product_search_reference.
Now it's possible to search products everywhere by supplier code

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'product_by_supplier/product.py'
2--- product_by_supplier/product.py 2014-04-24 14:26:27 +0000
3+++ product_by_supplier/product.py 2014-08-19 09:38:26 +0000
4@@ -2,8 +2,10 @@
5 ##############################################################################
6 #
7 # OpenERP, Open Source Management Solution
8+# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
9 # Copyright (c) 2010-2013 Elico Corp. All Rights Reserved.
10 # Author: Yannick Gouin <yannick.gouin@elico-corp.com>
11+# Copyright (c) 2014 Lorenzo Battistini <lorenzo.battistini@agilebg.com>
12 #
13 # This program is free software: you can redistribute it and/or modify
14 # it under the terms of the GNU Affero General Public License as
15@@ -29,7 +31,7 @@
16 self, cr, uid, ids, field_names=None, arg=False, context=None):
17 context = context or {}
18 res = {}
19- product_obj = self.pool.get('product.product')
20+ product_obj = self.pool.['product.product']
21 for record in self.browse(cr, uid, ids, context=context):
22 res[record.id] = {}
23 product = product_obj.browse(
24@@ -56,4 +58,55 @@
25 ),
26 }
27
28-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
29+
30+class product_product(orm.Model):
31+ _inherit = 'product.product'
32+
33+ def _partner_ref2(self, cr, user, ids, name, arg, context=None):
34+ res = {}
35+ for product in self.browse(cr, user, ids, context=context):
36+ res[product.id] = u'\n'.join(
37+ [x.product_code for x in product.seller_ids if x.product_code]
38+ ) or ''
39+ return res
40+
41+ def _partner_ref2_search(self, cr, user, obj, name, args, context=None):
42+ supplierinfo_obj = self.pool.['product.supplierinfo']
43+ args = args[:]
44+ i = 0
45+ while i < len(args):
46+ args[i] = ('product_code', args[i][1], args[i][2])
47+ i += 1
48+ supplierinfo_ids = supplierinfo_obj.search(cr, user, args)
49+ product_template_ids = [
50+ x.product_id.id for x in supplierinfo_obj.browse(
51+ cr, user,
52+ supplierinfo_ids
53+ ) if x.product_id]
54+ product_ids = self.search(
55+ cr, user, [('product_tmpl_id', 'in', product_template_ids)],
56+ context=context)
57+ return [('id', 'in', product_ids)]
58+
59+ _columns = {
60+ 'partner_ref2': fields.function(
61+ _partner_ref2, method=True,
62+ type='char', string='Supplier codes',
63+ fnct_search=_partner_ref2_search),
64+ }
65+
66+ def name_search(
67+ self, cr, user, name='', args=None, operator='ilike',
68+ context=None, limit=80):
69+ main_results = super(product_product, self).name_search(
70+ cr, user, name=name, args=args,
71+ operator=operator, context=context, limit=limit)
72+ ids = self.search(
73+ cr, user, [('partner_ref2', '=', name)] + args,
74+ limit=limit, context=context)
75+ if ids:
76+ supplier_results = self.name_get(cr, user, ids, context=context)
77+ for supplier_result in supplier_results:
78+ if supplier_result not in main_results:
79+ main_results.append(supplier_result)
80+ return main_results
81
82=== modified file 'product_by_supplier/product_view.xml'
83--- product_by_supplier/product_view.xml 2014-04-28 09:22:50 +0000
84+++ product_by_supplier/product_view.xml 2014-08-19 09:38:26 +0000
85@@ -1,6 +1,9 @@
86 <?xml version="1.0" encoding="UTF-8"?>
87 <openerp>
88 <data>
89+
90+ <!-- Supplier info -->
91+
92 <record id="view_product_supplierinfo_search" model="ir.ui.view">
93 <field name="name">product.supplierinfo.search</field>
94 <field name="model">product.supplierinfo</field>
95@@ -22,8 +25,42 @@
96 </field>
97 </record>
98
99- <record id="view_product_supplierinfo_tree1" model="ir.ui.view">
100- <field name="name">product.supplierinfo.tree1</field>
101+ <record id="view_product_supplierinfo_form" model="ir.ui.view">
102+ <field name="name">product.supplierinfo.form</field>
103+ <field name="model">product.supplierinfo</field>
104+ <field name="priority">99</field>
105+ <field name="arch" type="xml">
106+ <form string="Supplier Information" version="7.0">
107+ <group col="4">
108+ <field name="name" context="{'default_customer': 0, 'search_default_supplier': 1, 'default_supplier': 1}"/>
109+ <field name="product_id"/>
110+ <field name="sequence"/>
111+ <field name="product_name"/>
112+ <field name="product_code"/>
113+ <field name="min_qty"/>
114+ <field name="product_uom" groups="product.group_uom"/>
115+ <field name="delay"/>
116+ <field name="company_id" groups="base.group_multi_company" widget="selection"/>
117+ </group>
118+ <p groups="product.group_purchase_pricelist" class="oe_grey">The prices below will only be taken into account when your pricelist is set as based on supplier prices.</p>
119+ <field groups="product.group_purchase_pricelist" name="pricelist_ids">
120+ <tree editable="bottom" string="Pricelist">
121+ <field name="min_quantity"/>
122+ <field name="price"/>
123+ </tree>
124+ <form version="7.0">
125+ <group>
126+ <field name="min_quantity"/>
127+ <field name="price"/>
128+ </group>
129+ </form>
130+ </field>
131+ </form>
132+ </field>
133+ </record>
134+
135+ <record id="view_product_supplierinfo_tree" model="ir.ui.view">
136+ <field name="name">product.supplierinfo.tree</field>
137 <field name="model">product.supplierinfo</field>
138 <field name="priority">90</field>
139 <field name="arch" type="xml">
140@@ -42,34 +79,59 @@
141 </field>
142 </record>
143
144- <record id="view_product_supplierinfo_form1" model="ir.ui.view">
145- <field name="name">product.supplierinfo.form1</field>
146- <field name="model">product.supplierinfo</field>
147- <field name="inherit_id" ref="product.product_supplierinfo_form_view"/>
148- <field name="priority">99</field>
149- <field name="arch" type="xml">
150- <xpath expr="//field[@name='sequence']" position="before">
151- <field name="product_id"/>
152- </xpath>
153- </field>
154- </record>
155-
156 <record id="action_product_supplier_info" model="ir.actions.act_window">
157 <field name="name">Product by Suppliers</field>
158 <field name="res_model">product.supplierinfo</field>
159 <field name="type">ir.actions.act_window</field>
160 <field name="view_type">form</field>
161 <field name="view_mode">tree,form</field>
162- <field name="view_id" ref="view_product_supplierinfo_tree1"/>
163 <field name="search_view_id" ref="view_product_supplierinfo_search"/>
164 <field name="context">{'search_default_supplier':1,'group_by':[]}</field>
165 </record>
166
167+ <record id="action_product_supplierinfo_form" model="ir.actions.act_window.view">
168+ <field eval="2" name="sequence"/>
169+ <field name="view_mode">form</field>
170+ <field name="view_id" ref="view_product_supplierinfo_form" />
171+ <field name="act_window_id" ref="action_product_supplier_info" />
172+ </record>
173+
174+ <record id="action_product_supplierinfo_tree" model="ir.actions.act_window.view">
175+ <field eval="1" name="sequence"/>
176+ <field name="view_mode">tree</field>
177+ <field name="view_id" ref="view_product_supplierinfo_tree" />
178+ <field name="act_window_id" ref="action_product_supplier_info" />
179+ </record>
180 <menuitem
181 id="menu_product_supplier_info"
182 name="Product by Suppliers"
183 sequence="15"
184 action="action_product_supplier_info"
185 parent="purchase.menu_procurement_management_product"/>
186+
187+ <!-- Product -->
188+
189+ <record model="ir.ui.view" id="product_product_tree_view_inherit">
190+ <field name="name">product.product.tree.inherit</field>
191+ <field name="model">product.product</field>
192+ <field name="inherit_id" ref="product.product_product_tree_view"/>
193+ <field name="arch" type="xml">
194+ <field name="state" position="before">
195+ <field name="partner_ref2"/>
196+ </field>
197+ </field>
198+ </record>
199+
200+ <record model="ir.ui.view" id="product_search_form_view">
201+ <field name="name">product_search_form_view</field>
202+ <field name="model">product.product</field>
203+ <field name="inherit_id" ref="product.product_search_form_view"/>
204+ <field name="arch" type="xml">
205+ <field name="name" position="after">
206+ <field name="partner_ref2"/>
207+ </field>
208+ </field>
209+ </record>
210+
211 </data>
212 </openerp>

Subscribers

People subscribed via source and target branches