Reputation: 188
I am using following function to fetch records in my report.
def get_records(self):
recsss = self.pool.get('overtime_oms_bcube.overtime_oms_bcube').search(self.cr,self.uid, [], context=self.context)
resss = self.pool.get('overtime_oms_bcube.overtime_oms_bcube').browse(self.cr, self.uid, recsss)
return resss
and calling the records by following way:
<t t-set="i" t-value="1"/>
<tr t-foreach="get_records()" t-as="data">
<td style="display:none">
<t t-esc="i"/>
<t t-set="i" t-value="i+1"/>
</td>
<td t-esc="data['employee_code']"></td>
<td t-esc="data['employee'].name"></td>
<td t-esc="data['employee'].job_id.name"></td>
<td t-esc="data['no_of_days']"></td>
<td t-esc="data['employee'].contract_id.wage"></td>
<td t-esc="data['employee'].contract_id.wage*0.64516129"></td>
</tr>
The problem is that the resulting report is showing all the records saved in the data base. I want it to show only those records which are selected in the tree view. As you see the active/selected records in the image below.
And even in if we are in the single record view and generate a report, it still shows all the record but according to the flow it need to generate a report of that record from where we are generating that report.
please suggest something that helps in such requirement. Thanks in advance.
Upvotes: 1
Views: 1161
Reputation: 561
Relace this code:
def get_records(self):
recsss = self.pool.get('overtime_oms_bcube.overtime_oms_bcube').search(self.cr,self.uid, [], context=self.context)
resss = self.pool.get('overtime_oms_bcube.overtime_oms_bcube').browse(self.cr, self.uid, recsss)
return resss
withe the following
def get_records(self):
active_ids = self.context.get('active_ids',False)
recsss = self.pool.get('overtime_oms_bcube.overtime_oms_bcube').search(self.cr,self.uid, [('id','in',active_ids)], context=self.context)
resss = self.pool.get('overtime_oms_bcube.overtime_oms_bcube').browse(self.cr, self.uid, recsss)
return resss
It will generate the active Ids only. Cheers!
Upvotes: 1
Reputation: 76
Step 1: Create Wizard Example of odoo default product pricelist report wizard
Click on Print button system will call wizard print method
Step: 2: Create Print method in Wizard
def print_report(self, cr, uid, ids, context=None):
"""
To get the date and print the report
@return : return report
"""
if context is None:
context = {}
datas = {'ids': context.get('active_ids', [])}
res = self.read(cr, uid, ids, ['price_list','qty1', 'qty2','qty3','qty4','qty5'], context=context)
res = res and res[0] or {}
res['price_list'] = res['price_list'][0]
datas['form'] = res
return self.pool['report'].get_action(cr, uid, [], 'product.report_pricelist', data=datas, context=context)
In The Context you will get active ids and get_action method will print report
Upvotes: 2
Reputation: 14768
Try to check if active_ids
is present in context
when calling your method. If it is present, just use the IDs for your browse() call.
Upvotes: 0