Merge lp:~openerp-dev/openobject-addons/6.1-opw-576033-rgo into lp:openobject-addons/6.1

Proposed by Ravi Gohil (OpenERP)
Status: Rejected
Rejected by: Naresh(OpenERP)
Proposed branch: lp:~openerp-dev/openobject-addons/6.1-opw-576033-rgo
Merge into: lp:openobject-addons/6.1
Diff against target: 49 lines (+19/-9)
2 files modified
product/product.py (+0/-9)
stock/product.py (+19/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/6.1-opw-576033-rgo
Reviewer Review Type Date Requested Status
Naresh(OpenERP) (community) Disapprove
Ravi Gohil (OpenERP) (community) Needs Resubmitting
Review via email: mp+120982@code.launchpad.net

This proposal supersedes a proposal from 2012-06-20.

Description of the change

Hello,

If we just created a product and saved it, it is impossible to change the unit of the product with the unit which has other category than current unit's category.

Fix has been back-ported from the trunk branch: lp:~openerp-dev/openobject-addons/trunk-bug-894648-amp.

Kindly review the fix.

Thanks.

To post a comment you must log in.
Revision history for this message
Naresh(OpenERP) (nch-openerp) : Posted in a previous version of this proposal
review: Approve
Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote : Posted in a previous version of this proposal

well this fix seems some what complicated when a user tries to update the field externally either through say xmlrpc script.

you check the category ID for old and new along with if the move exist or not
 product_move = self.pool.get('stock.move').search(cr, uid, [('product_id', '=', ids[0])])

but you do the move check for just the first product and not all the product that are to be written.

say for eg: I want product with ID 4,5 to change there default UOM from PCE to KM and I have stock move for the product 5. so actually this should not allow me to update but in your case it does.

can you please recheck.

Thanks,
Naresh

review: Needs Fixing
Revision history for this message
Ravi Gohil (OpenERP) (rgo-openerp) wrote :

Hello,

Thanks for the review.

I have updated the fix as suggested in above comment.

Please review the fix.

Thanks.

Revision history for this message
Ravi Gohil (OpenERP) (rgo-openerp) :
review: Needs Resubmitting
6961. By Ravi Gohil (OpenERP)

[FIX] product: Fixed the issue caused when multiple ids passed to write: (Maintenance Case : 576033)

Revision history for this message
Naresh(OpenERP) (nch-openerp) wrote :

only covers stock what about other modules where product is interacted like SO, PO inventories etc.....

review: Disapprove

Unmerged revisions

6961. By Ravi Gohil (OpenERP)

[FIX] product: Fixed the issue caused when multiple ids passed to write: (Maintenance Case : 576033)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'product/product.py'
2--- product/product.py 2012-04-03 13:05:28 +0000
3+++ product/product.py 2012-08-23 13:51:19 +0000
4@@ -354,15 +354,6 @@
5 return {'value': {'uom_po_id': uom_id}}
6 return {}
7
8- def write(self, cr, uid, ids, vals, context=None):
9- if 'uom_po_id' in vals:
10- new_uom = self.pool.get('product.uom').browse(cr, uid, vals['uom_po_id'], context=context)
11- for product in self.browse(cr, uid, ids, context=context):
12- old_uom = product.uom_po_id
13- if old_uom.category_id.id != new_uom.category_id.id:
14- raise osv.except_osv(_('UoM categories Mismatch!'), _("New UoM '%s' must belong to same UoM category '%s' as of old UoM '%s'. If you need to change the unit of measure, you may desactivate this product from the 'Procurement & Locations' tab and create a new one.") % (new_uom.name, old_uom.category_id.name, old_uom.name,))
15- return super(product_template, self).write(cr, uid, ids, vals, context=context)
16-
17 _defaults = {
18 'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'product.template', context=c),
19 'list_price': lambda *a: 1,
20
21=== modified file 'stock/product.py'
22--- stock/product.py 2012-06-19 07:40:07 +0000
23+++ stock/product.py 2012-08-23 13:51:19 +0000
24@@ -493,6 +493,25 @@
25 "there is a specific valuation account set on the destination location. When not set on the product, the one from the product category is used."),
26 }
27
28+ def write(self, cr, uid, ids, vals, context=None):
29+ if 'uom_po_id' in vals:
30+ new_uom = self.pool.get('product.uom').browse(cr, uid, vals['uom_po_id'], context=context)
31+ write_ids = []
32+ warning = ""
33+ for product in self.browse(cr, uid, ids, context=context):
34+ product_move = self.pool.get('stock.move').search(cr, uid, [('product_id', '=', product.id)])
35+ if product_move:
36+ old_uom = product.uom_po_id
37+ if old_uom.category_id.id != new_uom.category_id.id:
38+ warning += _("Product's new UoM '%s' must belong to same UoM category '%s' as of old UoM '%s'.Because product %s 's stock move is already created'") % (new_uom.name, old_uom.category_id.name, old_uom.name, product.name) + "\n"
39+ else:
40+ write_ids.append(product.id)
41+ else:
42+ write_ids.append(product.id)
43+ if warning:
44+ raise osv.except_osv(_('UoM categories Mismatch!'), warning)
45+ return super(product_template, self).write(cr, uid, write_ids, vals, context=context)
46+
47 product_template()
48
49 class product_category(osv.osv):