-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
stock_valuation_history.py
87 lines (70 loc) · 2.79 KB
/
stock_valuation_history.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
# @ 2016 Kmee - www.kmee.com.br - Daniel Sadamo <daniel.sadamo@kmee.com.br>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, api, _
from openerp.osv import osv, fields
class WizardValuationHistory(models.TransientModel):
_inherit = 'wizard.valuation.history'
'''TODO - We need to use the old API because the Context is not being
pass to the method read_group( ORM ), the reason seems because this
method still not migrated to new API.'''
@api.model
def compute(self, cr, uid, ids, date, context=None):
context['history_date'] = date
fields = [
'fiscal_classification_id',
'product_id',
'location_id',
'move_id',
'company_id',
'date',
'source',
'quantity',
'inventory_value',
'price_unit_on_quant'
]
group_by = [
'product_id',
'location_id',
'fiscal_classification_id'
]
result = self.pool.get('stock.history').read_group(
cr, uid, domain=[['date', '<=', date]], fields=fields,
groupby=group_by, context=context)
return result
@api.multi
def open_report_xls(self):
data = self.read()[0]
ctx = self.env.context.copy()
ctx['history_date'] = data['date']
ctx['search_default_group_by_product'] = True
ctx['search_default_group_by_location'] = True
return {
'domain': "[('date', '<=', '" + data['date'] + "')]",
'name': _('Stock Value At Date'),
'type': 'ir.actions.report.xml',
'report_name': 'wizard.valuation.history',
'datas': data,
'context': ctx,
'nodestroy': True
}
class StockHistory(osv.osv):
_inherit = 'stock.history'
_columns = {
'fiscal_classification_id': fields.related(
'product_id', 'fiscal_classification_id', type='many2one',
relation='account.product.fiscal.classification', string='NCM'
)
}
def read_group(self, cr, uid, domain, fields, groupby, offset=0,
limit=None, context=None, orderby=False, lazy=True):
res = super(StockHistory, self).read_group(
cr, uid, domain, fields, groupby, offset=offset, limit=limit,
context=context, orderby=orderby, lazy=lazy)
if 'fiscal_classification_id' in fields:
product_obj = self.pool.get('product.product')
for line in res:
product = product_obj.browse(cr, uid, line['product_id'][0])
fiscal_class = product.fiscal_classification_id.code
line.update({'fiscal_classification_id': fiscal_class})
return res