Merge lp:~openerp-dev/openobject-addons/trunk-bug-707287-aag into lp:openobject-addons

Proposed by Atik Agewan(OpenERP)
Status: Merged
Approved by: Fabien (Open ERP)
Approved revision: no longer in the source branch.
Merged at revision: 5620
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-bug-707287-aag
Merge into: lp:openobject-addons
Diff against target: 33 lines (+16/-0)
1 file modified
product/product.py (+16/-0)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-707287-aag
Reviewer Review Type Date Requested Status
Rucha (Open ERP) (community) Needs Information
qdp (OpenERP) Needs Fixing
Atik Agewan(OpenERP) (community) Needs Resubmitting
Review via email: mp+80213@code.launchpad.net

Description of the change

 Hello,

  Product :User can not change the existing UOM category ,Old Uom and New Uom category should be same.

 Thanks,
  Atik

To post a comment you must log in.
Revision history for this message
Rucha (Open ERP) (rpa-openerp) wrote :

please improve the code,

29 + product = self.pool.get('product.product')
30 + uom_obj = self.pool.get('product.uom')
31 + product_uom1 = product.browse(cr, uid, ids)[0]
32 + category_1 = uom_obj.browse(cr, uid, product_uom1.uom_id.id).category_id

you are in product class, can't you simply do it by self instead of self.pool.get(..)?
you don't need to use uom_obj,
product_uom1.uom_id.category_id will give you the category,
also make sure to use proper variable name, product_uom1 doesn't suits for browse record for product,
simplify the other code please,

thanks

review: Needs Fixing
Revision history for this message
Atik Agewan(OpenERP) (aag-openerp) wrote :

 Hello,

  Changes is Done as per your suggestion.
  But we need uom_obj in product write method to browse new uom's category
  like ..
     new_category = uom_obj.browse(cr, uid, vals['uom_po_id']).category_id

 Thanks,
  Atik

review: Needs Resubmitting
Revision history for this message
Rucha (Open ERP) (rpa-openerp) wrote :

I have made improvement in code,
Thanks

review: Approve
Revision history for this message
qdp (OpenERP) (qdp) wrote :

Hi,

line 22: update_check=True? really? what for? a wrong copy/paste?
line 25: new_uom definition can be remvoed from the loop and placed two lines above
lines 22 to 30: i don't know if you noticed it, but the same problem could appear if we change the default uom of a product that already has stock moves.. but fortunately there is a constraint that ensure that the uom and the purchase uom of a product belong to the same group, so it will never be the case and this test is enough. Still, as explicit is better that implicit, you should check that case also in your code.
e.g: the line 23 should be replaced by something like
 if 'uom_po_id' in vals or 'uom_id' in vals:
 ...

Thanks

review: Needs Fixing
Revision history for this message
Rucha (Open ERP) (rpa-openerp) wrote :

I have checked all possible cases, for a product, changing both uom_id and uom_po_id, only uom_po_id , only uom_id, and its working fine with checking only "if 'uom_po_id' in vals" without any fail (the reason is changing uom_id will change uom_po_id too, and if not there will be difference in categ of current uom_id/uom_po_id, so again it will raise constraint error),
can you check again please, or I am missing something?
thanks for others.

review: Needs Information
Revision history for this message
Atik Agewan(OpenERP) (aag-openerp) wrote :

 Hello ,

  update_check=True is removed.
  new_uom definition removed from loop.

 Thanks

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 2011-10-11 14:03:35 +0000
3+++ product/product.py 2011-11-04 09:58:25 +0000
4@@ -166,6 +166,13 @@
5 if value == 'reference':
6 return {'value': {'factor': 1, 'factor_inv': 1}}
7 return {}
8+
9+ def write(self, cr, uid, ids, vals, context=None):
10+ if 'category_id' in vals:
11+ for uom in self.browse(cr, uid, ids, context=context):
12+ if uom.category_id != vals['category_id']:
13+ raise osv.except_osv(_('Warning'),_("Cannot change the category of existing UoM '%s'.") % (uom.name,))
14+ return super(product_uom, self).write(cr, uid, ids, vals, context=context)
15
16 product_uom()
17
18@@ -328,6 +335,15 @@
19 return {'value': {'uom_po_id': uom_id}}
20 return False
21
22+ def write(self, cr, uid, ids, vals, context=None):
23+ if 'uom_po_id' in vals:
24+ new_uom = self.pool.get('product.uom').browse(cr, uid, vals['uom_po_id'], context=context)
25+ for product in self.browse(cr, uid, ids, context=context):
26+ old_uom = product.uom_po_id
27+ if old_uom.category_id.id != new_uom.category_id.id:
28+ raise osv.except_osv(_('UoM categories Mismatch!'), _("New UoM '%s' must belongs to same UoM category '%s' as of old UoM '%s'.") % (new_uom.name, old_uom.category_id.name, old_uom.name,))
29+ return super(product_template, self).write(cr, uid, ids, vals, context=context)
30+
31 _defaults = {
32 'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'product.template', context=c),
33 'list_price': lambda *a: 1,

Subscribers

People subscribed via source and target branches

to all changes: