1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU Affero General Public License as
9
# published by the Free Software Foundation, either version 3 of the
10
# License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU Affero General Public License for more details.
17
# You should have received a copy of the GNU Affero General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
##############################################################################
24
from report import report_sxw
26
class consumption_report(report_sxw.rml_parse):
27
def _get_consumption_lines(self,product_id):
29
""" Finds the consumption details for the product
30
@param self: The object pointer.
31
@param product_id: ID of the product
32
@comment: fetches the consumption details of the product using 'find_consumption_details'
33
which analyses stock moves to find consumption details
34
@return: List of dictionaries showing the consumption details
37
detail_list=self.localcontext.get('detail_list',[])
38
cr=self.cr;uid=self.uid
39
details=self.pool.get("product.product").find_consumption_details(cr,uid,[product_id],context=self.localcontext)
40
detail_list=details.get('detail_list',[])
43
def _get_us_date(self,date_string):
44
""" Converts the input date string to us format
45
@param self: The object pointer.
46
@param date_string: Expects date in ISO format YYYY-MM-DD
47
@comment: uses format_lang method to convert the date to the us format
48
@return: Returns either the us format date or an empty string
52
us_string=self.formatLang(date_string,date=True)
55
def _format_product_name(self,product_name,reference):
56
""" Adds the product name and reference
57
@param self: The object pointer.
58
@param product_name: name of the product
59
@param reference: Reference of the product
60
@comment: adds the the reference and the product name if there is a reference string
61
@return: returns '[reference] product_name' or 'product_name'
64
reference="[%s] "%reference
67
return reference+product_name
69
def __init__(self, cr, uid, name, context=None):
70
""" Parser __init__ override
72
super(consumption_report, self).__init__(cr, uid, name, context=context)
73
self.localcontext.update({
75
'_get_consumption_lines':self._get_consumption_lines,
76
'_get_':self._get_consumption_lines,
77
'_get_us_date':self._get_us_date,
78
'_format_product_name':self._format_product_name,
79
'source_loc_id':context.get('source_loc_id', False),#1. location id selected for getting consumption details in the wizard
80
'start_date':context.get('start_date',False),#2. getting start date selected in the wizard
81
'end_date':context.get('end_date',False),#3. getting end date selected in the wizard
84
report_sxw.report_sxw('report.product.consumption', 'product.product', 'addons/assembly_bom/report/consumption_report.rml', parser=consumption_report, header=False)
86
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: