Merge lp:~openerp-dev/openobject-addons/trunk-bug-953324-rpr into lp:openobject-addons

Proposed by Rajesh Prajapati (OpenERP)
Status: Work in progress
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-bug-953324-rpr
Merge into: lp:openobject-addons
Diff against target: 102 lines (+30/-8)
2 files modified
stock/stock.py (+24/-2)
stock/stock_view.xml (+6/-6)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-bug-953324-rpr
Reviewer Review Type Date Requested Status
Rajesh Prajapati (OpenERP) (community) Needs Resubmitting
Purnendu Singh (OpenERP) (community) Needs Fixing
Review via email: mp+123274@code.launchpad.net

Description of the change

Hello

       I added the onchange method for UOM to check the UOM in stock.move and stock.inventory.line in stock

Thanks.
Rajesh

To post a comment you must log in.
Revision history for this message
Purnendu Singh (OpenERP) (purnendu-singh) wrote :

Hello,

You should update 2 points in your mp:

1) Place the newly created onchange_uom method to proper place!!

2) Your forget to do the same thing for stock.inventory.line!!

to check go to warehouse-->inventory control-->physical inventory
 here create a new inventory and create lines. You can change the UOM of different categories!! So, please update the code as u did for stock.move

Thanks,
Purnendu Singh

review: Needs Fixing
7376. By Rajesh Prajapati (OpenERP)

[FIX] stock: method onchange_uom added for stock.inventory.line

7377. By Rajesh Prajapati (OpenERP)

[FIX] stock: method on_change_product_id improved to consider the proper UOM as per change

Revision history for this message
Rajesh Prajapati (OpenERP) (rpr-tinyerp) wrote :

Hello

      Added method for stock.inventory.line and improved onchange_product_id to consider proper UOM.

Thanks.
Rajesh

review: Needs Resubmitting
7378. By Rajesh Prajapati (OpenERP)

[FIX] stock: space removed

Revision history for this message
Amit Parik (amit-parik) wrote :

Hello Rajesh,

on_change_uom is not a better solution to do this, but there must be a check_uom constraint which will also useful for import time. Because if someone try to import inventory line with csv file then on_change will never raise.

So for this bug lp:~openerp-dev/openobject-addons/trunk-bug-953324-mma branch is correct.

Thank you!

7379. By Rajesh Prajapati (OpenERP)

[MERGE] merge with main addons

7380. By Rajesh Prajapati (OpenERP)

[MERGE] merge with main addons

7381. By Rajesh Prajapati (OpenERP)

[MERGE] merge with main addons

Unmerged revisions

7381. By Rajesh Prajapati (OpenERP)

[MERGE] merge with main addons

7380. By Rajesh Prajapati (OpenERP)

[MERGE] merge with main addons

7379. By Rajesh Prajapati (OpenERP)

[MERGE] merge with main addons

7378. By Rajesh Prajapati (OpenERP)

[FIX] stock: space removed

7377. By Rajesh Prajapati (OpenERP)

[FIX] stock: method on_change_product_id improved to consider the proper UOM as per change

7376. By Rajesh Prajapati (OpenERP)

[FIX] stock: method onchange_uom added for stock.inventory.line

7375. By Rajesh Prajapati (OpenERP)

[FIX] stock: onchange method added for no_check_UOM in stock.move and stock.inventory.line

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'stock/stock.py'
2--- stock/stock.py 2013-12-18 15:57:15 +0000
3+++ stock/stock.py 2014-01-15 16:02:43 +0000
4@@ -1683,6 +1683,17 @@
5 'You try to assign a lot which is not from the same product.',
6 ['prodlot_id'])]
7
8+ def onchange_uom(self, cr, uid, ids, product_id, product_uom, context=None):
9+ res = {'value':{}}
10+ if not product_uom or not product_id:
11+ return res
12+ product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
13+ uom = self.pool.get('product.uom').browse(cr, uid, product_uom, context=context)
14+ if uom.category_id.id != product.uom_id.category_id.id:
15+ res['warning'] = {'title': _('Warning'), 'message': _('Selected Unit of Measure does not belong to the same category as the product Unit of Measure')}
16+ res['value'].update({'product_uom': product.uom_id.id})
17+ return res
18+
19 def _default_location_destination(self, cr, uid, context=None):
20 """ Gets default address of partner for destination location
21 @return: Address id or False
22@@ -2921,7 +2932,18 @@
23 'location_id': _default_stock_location
24 }
25
26- def on_change_product_id(self, cr, uid, ids, location_id, product, uom=False, to_date=False):
27+ def onchange_uom(self, cr, uid, ids, product_id, product_uom, context=None):
28+ res = {'value':{}}
29+ if not product_uom or not product_id:
30+ return res
31+ product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
32+ uom = self.pool.get('product.uom').browse(cr, uid, product_uom, context=context)
33+ if uom.category_id.id != product.uom_id.category_id.id:
34+ res['warning'] = {'title': _('Warning'), 'message': _('Selected Unit of Measure does not belong to the same category as the product Unit of Measure')}
35+ res['value'].update({'product_uom': product.uom_id.id})
36+ return res
37+
38+ def on_change_product_id(self, cr, uid, ids, location_id, product, to_date=False):
39 """ Changes UoM and name if product_id changes.
40 @param location_id: Location id
41 @param product: Changed product_id
42@@ -2931,7 +2953,7 @@
43 if not product:
44 return {'value': {'product_qty': 0.0, 'product_uom': False, 'prod_lot_id': False}}
45 obj_product = self.pool.get('product.product').browse(cr, uid, product)
46- uom = uom or obj_product.uom_id.id
47+ uom = obj_product.uom_id.id
48 amount = self.pool.get('stock.location')._product_get(cr, uid, location_id, [product], {'uom': uom, 'to_date': to_date, 'compute_child': False})[product]
49 result = {'product_qty': amount, 'product_uom': uom, 'prod_lot_id': False}
50 return {'value': result}
51
52=== modified file 'stock/stock_view.xml'
53--- stock/stock_view.xml 2013-12-18 15:57:15 +0000
54+++ stock/stock_view.xml 2014-01-15 16:02:43 +0000
55@@ -58,7 +58,7 @@
56 <field name="arch" type="xml">
57 <form string="Stock Inventory Lines" version="7.0">
58 <group col="4">
59- <field context="{'location':location_id, 'uom':product_uom, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,product_uom,parent.date)" domain="[('type','&lt;&gt;','service')]"/>
60+ <field context="{'location':location_id, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,parent.date)" domain="[('type','&lt;&gt;','service')]"/>
61 <field name="product_qty"/>
62 <field name="product_uom" groups="product.group_uom"/>
63 <field name="prod_lot_id" groups="stock.group_production_lot"/>
64@@ -130,9 +130,9 @@
65 <field name="inventory_line_id">
66 <tree string="Products" editable="bottom">
67 <field domain="[('usage','=','internal')]" name="location_id" groups="stock.group_locations"/>
68- <field context="{'location':location_id, 'uom':product_uom, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,product_uom,parent.date)" domain="[('type','&lt;&gt;','service')]"/>
69+ <field context="{'location':location_id, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,parent.date)" domain="[('type','&lt;&gt;','service')]"/>
70 <field name="product_qty"/>
71- <field name="product_uom" groups="product.group_uom"/>
72+ <field name="product_uom" string="Unit of Measure" on_change="onchange_uom(product_id, product_uom, context)" groups="product.group_uom"/>
73 <field name="prod_lot_id" groups="stock.group_production_lot"/>
74 <button name="%(stock.action_view_stock_inventory_line_split)d"
75 string="Split inventory lines" groups="stock.group_inventory_valuation"
76@@ -143,7 +143,7 @@
77 <group>
78 <group>
79 <field domain="[('usage','=','internal')]" name="location_id"/>
80- <field context="{'location':location_id, 'uom':product_uom, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,product_uom,parent.date)" domain="[('type','&lt;&gt;','service')]"/>
81+ <field context="{'location':location_id, 'to_date':parent.date}" name="product_id" on_change="on_change_product_id(location_id,product_id,parent.date)" domain="[('type','&lt;&gt;','service')]"/>
82 </group>
83 <group>
84 <label for="product_qty"/>
85@@ -1138,7 +1138,7 @@
86 <field name="create_date" invisible="1" groups="base.group_no_one"/>
87 <field name="product_id" on_change="onchange_product_id(product_id,location_id,location_dest_id, False)"/>
88 <field name="product_qty" on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"/>
89- <field name="product_uom" string="Unit of Measure" groups="product.group_uom"/>
90+ <field name="product_uom" string="Unit of Measure" on_change="onchange_uom(product_id, product_uom, context)" groups="product.group_uom"/>
91 <field name="product_uos" groups="product.group_uos"/>
92 <button name="%(stock.move_scrap)d"
93 string="Scrap Products" type="action"
94@@ -1234,7 +1234,7 @@
95 <field name="product_qty"
96 on_change="onchange_quantity(product_id, product_qty, product_uom, product_uos)"
97 class="oe_inline"/>
98- <field name="product_uom" groups="product.group_uom" class="oe_inline"/>
99+ <field name="product_uom" on_change="onchange_uom(product_id, product_uom, context)" groups="product.group_uom" class="oe_inline"/>
100 <button name="%(stock.move_scrap)d"
101 string="Scrap" type="action"
102 icon="terp-gtk-jump-to-ltr" context="{'scrap': True}"

Subscribers

People subscribed via source and target branches

to all changes: