Hi,
I try to pass start_date and stop_date from wizard to report.py,
is there any other way to do it then my way? I tried self.env['model.wizard'] but does not work.
Wizard .py:
class GetDatesWizard(models.TransientModel):
_name = 'get.dates.wizard'
start_date = fields.Date("Start date")
stop_date = fields.Date("Stop date")
def create_report(self):
return {
'name': 'generate report',
'type': 'ir.actions.act_window',
'res_model': 'irco.nutri.report.costeplatos',
'view_mode': 'pivot',
}
Report .py:
class CostPlateReport(models.Model):
_name = "cost.plate.report"
_order = 'date desc'
partner = fields.Many2one('res.partner','Client')
date = fields.Date('Date')
plate = fields.Char('Plato')
cost = fields.Float('Cost')
def _query(self, with_clause='', fields={}, groupby='', from_clause=''):
with_ = ("WITH %s" % with_clause) if with_clause else ""
last_wizard_record = self.env['fechas.informe.nutricion.wizard'].search([ ])[-1]
start_date = last_wizard_record.start_date # does not work
stop_date = last_wizard_record.stop_date # does not work
select_ = """
min(m.id) as id,m.date as date,m.partner as partner,pt.name as plate,pc.cost as cost
"""
for field in fields.values():
select_ += field
from_ = """
irco_menu m
join irco_menu_plates p on (p.plate_menu_id=m.id)
join res_partner r on (r.id=p.partner)
join product_template pt on (p.plate_ids=pt.id)
join irco_plate_cost pc on (pc.product_template_id=pt.id)
join product_product pp on (pp.product_tmpl_id=pt.id)
%s
""" % from_clause
groupby_ = """
m.id, m.date,m.partner,pt.name,pc.cost %s
""" % (groupby)
return "%s (SELECT %s FROM %s WHERE m.state = 'done' GROUP BY %s)" % (with_, select_, from_, groupby_)
@api.model_cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute("""CREATE or REPLACE VIEW %s as (%s)""" % (self._table, self._query()))