Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add From date to To date to print a set of records in report in odoo 10?

I am creating a Bank module, where the customers can buy loans from the bank. In that I want to print a report statement. Before printing the records of a particular customer, i want to filter the dates. I want to filter it by giving From date to To date. So the loan amounts where the customer bought from the bank in that given dates should print.

Thank You,

Hope I will gain some knowledge.

like image 526
Navi Avatar asked Nov 18 '25 12:11

Navi


1 Answers

below code for wizard

class BankCustomer(models.TransientModel):
    _name = 'bank.customer'
    _description = 'Bank Customer Report'


    date_from = fields.Date(string='From date', required=True,default=lambda *a: time.strftime('%Y-%m-01'))
    date_to = fields.Date(string='To date', required=True,default=lambda *a: str(datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1))[:10])


@api.multi
def pdf_bank_customer_report(self):
    data = self.read()[0]
    datas = {
        'ids': [],
        'model': 'bank.customer',
        'form': data
    }
    return self.env['report'].with_context(landscape=True).get_action(self, 'module_name.template_name', data=datas)    




class BankCustomerReport(models.AbstractModel):
    _name = 'report.module_name.template_name



def get(self):
    self.env.cr.execute(""" you query """+ datas['date_from'],datas['date_to'] ))

    line_list = [i for i in self.env.cr.dictfetchall()]
    finallist = [] 

    import datetime
    for fin in line_list:
        #sale_date = datetime.datetime.strptime(fin['date'], '%Y-%m-%d').strftime('%d-%m-%y')
        finallist.append({
            'date': fin['date'],
 'here gat  you requirened field from query'
        })
       finally pass thislist to report template

    return finallist

@api.model
def render_html(self, docids, data=None):
    Report = self.env['report']
    sale_report = Report._get_report_from_name('module_name.report_template_name')
    context = dict(self._context or {})
    active_ids = context.get('active_ids', [])
    register = self.env['bank.customer'].browse(active_ids)
    docargs = {
        'doc_ids': self.ids,
        'doc_model': sale_report.model,
        'docs': register,
        'details':self.get_det,

    }
    return Report.render('module_name.report_template_name', docargs)
like image 151
Lakshminarayanan Avatar answered Nov 21 '25 05:11

Lakshminarayanan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!