Merge lp:~openerp-dev/openobject-addons/trunk-wms-reportgroup-jco into lp:~openerp-dev/openobject-addons/trunk-wms

Proposed by Josse Colpaert (OpenERP)
Status: Merged
Merged at revision: 9665
Proposed branch: lp:~openerp-dev/openobject-addons/trunk-wms-reportgroup-jco
Merge into: lp:~openerp-dev/openobject-addons/trunk-wms
Diff against target: 189 lines (+36/-27)
4 files modified
mrp/mrp.py (+2/-0)
stock/stock.py (+2/-2)
stock_account/wizard/stock_valuation_history.py (+31/-24)
stock_account/wizard/stock_valuation_history_view.xml (+1/-1)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/trunk-wms-reportgroup-jco
Reviewer Review Type Date Requested Status
qdp (OpenERP) Pending
Review via email: mp+216146@code.launchpad.net

Description of the change

Update of Stock Valuation Report

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mrp/mrp.py'
2--- mrp/mrp.py 2014-04-03 09:24:44 +0000
3+++ mrp/mrp.py 2014-04-16 15:50:59 +0000
4@@ -1000,6 +1000,7 @@
5 'move_dest_id': production.move_prod_id.id,
6 'company_id': production.company_id.id,
7 'production_id': production.id,
8+ 'origin': production.name,
9 }
10 move_id = stock_move.create(cr, uid, data, context=context)
11 #a phantom bom cannot be used in mrp order so it's ok to assume the list returned by action_confirm
12@@ -1041,6 +1042,7 @@
13 'raw_material_production_id': production.id,
14 #this saves us a browse in create()
15 'price_unit': production_line.product_id.standard_price,
16+ 'origin': production.name,
17 })
18 return move_id
19
20
21=== modified file 'stock/stock.py'
22--- stock/stock.py 2014-04-16 14:53:13 +0000
23+++ stock/stock.py 2014-04-16 15:50:59 +0000
24@@ -281,9 +281,9 @@
25 'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'stock.quant', context=c),
26 }
27
28- def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False):
29+ def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False, lazy=True):
30 ''' Overwrite the read_group in order to sum the function field 'inventory_value' in group by'''
31- res = super(stock_quant, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby)
32+ res = super(stock_quant, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby, lazy=True)
33 if 'inventory_value' in fields:
34 for line in res:
35 if '__domain' in line:
36
37=== modified file 'stock_account/wizard/stock_valuation_history.py'
38--- stock_account/wizard/stock_valuation_history.py 2014-03-27 17:42:28 +0000
39+++ stock_account/wizard/stock_valuation_history.py 2014-04-16 15:50:59 +0000
40@@ -29,7 +29,7 @@
41 'domain': "[('date', '<=', '" + data['date'] + "')]",
42 'name': _('Stock Value At Date'),
43 'view_type': 'form',
44- 'view_mode': 'tree, graph',
45+ 'view_mode': 'tree,graph',
46 'res_model': 'stock.history',
47 'type': 'ir.actions.act_window',
48 'context': ctx,
49@@ -41,9 +41,9 @@
50 _auto = False
51 _order = 'date asc'
52
53- def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False):
54- res = super(stock_history, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby)
55- prod_dict= {}
56+ def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False, lazy=True):
57+ res = super(stock_history, self).read_group(cr, uid, domain, fields, groupby, offset=offset, limit=limit, context=context, orderby=orderby, lazy=lazy)
58+ prod_dict = {}
59 if 'inventory_value' in fields:
60 for line in res:
61 if '__domain' in line:
62@@ -57,14 +57,14 @@
63 prod_dict[line_rec.product_id.id] = line_rec.price_unit_on_quant
64 else:
65 prod_dict[line_rec.product_id.id] = product_obj.get_history_price(cr, uid, line_rec.product_id.id, line_rec.company_id.id, context=context)
66- inv_value += prod_dict[line_rec.product_id.id]
67+ inv_value += prod_dict[line_rec.product_id.id] * line_rec.quantity
68 line['inventory_value'] = inv_value
69 return res
70
71 def _get_inventory_value(self, cr, uid, ids, name, attr, context=None):
72 product_obj = self.pool.get("product.product")
73 res = {}
74- #Browse takes an immense amount of time because it seems to reload the report
75+ # Browse takes an immense amount of time because it seems to reload the report
76 for line in self.browse(cr, uid, ids, context=context):
77 if line.product_id.cost_method == 'real':
78 res[line.id] = line.quantity * line.price_unit_on_quant
79@@ -74,16 +74,17 @@
80
81 _columns = {
82 'move_id': fields.many2one('stock.move', 'Stock Move', required=True),
83- #'quant_id': fields.many2one('stock.quant'),
84- 'company_id': fields.related('move_id', 'company_id', type='many2one', relation='res.company', string='Company', required=True, select=True),
85+ 'quant_id': fields.many2one('stock.quant', 'Quant', required=True),
86+ 'quant_location_id': fields.related('quant_id', 'location_id', type='many2one', relation='stock.location', string='Actual Quant Location', select=True),
87 'location_id': fields.many2one('stock.location', 'Location', required=True),
88+ 'company_id': fields.many2one('res.company', 'Company'),
89 'product_id': fields.many2one('product.product', 'Product', required=True),
90 'product_categ_id': fields.many2one('product.category', 'Product Category', required=True),
91 'quantity': fields.integer('Product Quantity'),
92 'date': fields.datetime('Operation Date'),
93 'price_unit_on_quant': fields.float('Value'),
94- 'cost_method': fields.char('Cost Method'),
95 'inventory_value': fields.function(_get_inventory_value, string="Inventory Value", type='float', readonly=True),
96+ 'source': fields.char('Source')
97 }
98
99 def init(self, cr):
100@@ -92,48 +93,54 @@
101 CREATE OR REPLACE VIEW stock_history AS (
102 (SELECT
103 stock_move.id::text || '-' || quant.id::text AS id,
104+ quant.id AS quant_id,
105 stock_move.id AS move_id,
106- stock_move.location_dest_id AS location_id,
107+ location.location_id AS location_id,
108+ location.company_id AS company_id,
109 stock_move.product_id AS product_id,
110 product_template.categ_id AS product_categ_id,
111 quant.qty AS quantity,
112 stock_move.date AS date,
113- ir_property.value_text AS cost_method,
114- quant.cost as price_unit_on_quant
115+ quant.cost as price_unit_on_quant,
116+ stock_move.origin AS source
117 FROM
118 stock_quant as quant, stock_quant_move_rel, stock_move
119 LEFT JOIN
120 stock_location location ON stock_move.location_dest_id = location.id
121 LEFT JOIN
122+ stock_location other_location ON stock_move.location_id = other_location.id
123+ LEFT JOIN
124 product_product ON product_product.id = stock_move.product_id
125 LEFT JOIN
126 product_template ON product_template.id = product_product.product_tmpl_id
127- LEFT JOIN
128- ir_property ON (ir_property.name = 'cost_method' and ir_property.res_id = 'product.template,' || product_template.id::text)
129- WHERE stock_move.state = 'done' AND location.usage = 'internal' AND stock_quant_move_rel.quant_id = quant.id
130- AND stock_quant_move_rel.move_id = stock_move.id
131+ WHERE stock_move.state = 'done' AND location.usage in ('internal', 'transit') AND stock_quant_move_rel.quant_id = quant.id
132+ AND stock_quant_move_rel.move_id = stock_move.id AND ((other_location.company_id is null and location.company_id is not null) or
133+ (other_location.company_id is not null and location.company_id is null) or other_location.company_id != location.company_id)
134 ) UNION
135 (SELECT
136 '-' || stock_move.id::text || '-' || quant.id::text AS id,
137+ quant.id AS quant_id,
138 stock_move.id AS move_id,
139- stock_move.location_id AS location_id,
140+ location.location_id AS location_id,
141+ location.company_id AS company_id,
142 stock_move.product_id AS product_id,
143 product_template.categ_id AS product_categ_id,
144 - quant.qty AS quantity,
145 stock_move.date AS date,
146- ir_property.value_text AS cost_method,
147- quant.cost as price_unit_on_quant
148+ quant.cost as price_unit_on_quant,
149+ stock_move.origin AS source
150 FROM
151 stock_quant as quant, stock_quant_move_rel, stock_move
152 LEFT JOIN
153- stock_location location ON stock_move.location_id = location.id
154+ stock_location location ON stock_move.location_id = location.id
155+ LEFT JOIN
156+ stock_location other_location ON stock_move.location_dest_id = other_location.id
157 LEFT JOIN
158 product_product ON product_product.id = stock_move.product_id
159 LEFT JOIN
160 product_template ON product_template.id = product_product.product_tmpl_id
161- LEFT JOIN
162- ir_property ON (ir_property.name = 'cost_method' and ir_property.res_id = 'product.template,' || product_template.id::text)
163- WHERE stock_move.state = 'done' AND location.usage = 'internal' AND stock_quant_move_rel.quant_id = quant.id
164- AND stock_quant_move_rel.move_id = stock_move.id
165+ WHERE stock_move.state = 'done' AND location.usage in ('internal', 'transit') AND stock_quant_move_rel.quant_id = quant.id
166+ AND stock_quant_move_rel.move_id = stock_move.id AND ((other_location.company_id is null and location.company_id is not null) or
167+ (other_location.company_id is not null and location.company_id is null) or other_location.company_id != location.company_id)
168 )
169 )""")
170
171=== modified file 'stock_account/wizard/stock_valuation_history_view.xml'
172--- stock_account/wizard/stock_valuation_history_view.xml 2014-03-14 15:13:20 +0000
173+++ stock_account/wizard/stock_valuation_history_view.xml 2014-04-16 15:50:59 +0000
174@@ -48,6 +48,7 @@
175 <field name="move_id"/>
176 <field name="company_id" groups="base.group_multi_company"/>
177 <field name="date"/>
178+ <field name="source"/>
179 <field name="quantity" sum="# of Products "/>
180 <field name="inventory_value" sum="Total Value"/>
181 </tree>
182@@ -91,7 +92,6 @@
183 <field name="domain">[('date','&lt;=',time.strftime('%Y-%m-%d %H:%M:%S'))]</field>
184 <field name="view_type">form</field>
185 <field name="view_mode">tree,graph</field>
186- <field name="view_id" ref="view_stock_history_report_tree"/>
187 </record>
188 <menuitem action="action_history_tree"
189 id="menu_action_history_tree"