def _cashreport_range(self, start_date=None, offset=0): if not start_date: start_date = util.currentDate() cashreport_name = _("Cashreport") date_from = start_date date_till = start_date f = format.LangFormat(self._cr, self._uid, self._context) # calc month if self.range == "month": dt_date_from = util.strToDate(util.getFirstOfMonth(start_date)) if offset: dt_date_from += relativedelta(months=offset) date_from = util.dateToStr(dt_date_from) date_till = util.getEndOfMonth(dt_date_from) month_name = helper.getMonthName(self._cr, self._uid, dt_date_from.month, context=self._context) cashreport_name = "%s - %s %s" % (cashreport_name, month_name, dt_date_from.year) # calc week elif self.range == "week": dt_date_from = util.strToDate(start_date) if offset: dt_date_from += relativedelta(weeks=offset) weekday = dt_date_from.weekday() dt_date_from = dt_date_from + relativedelta(days=-weekday) kw = dt_date_from.isocalendar()[1] date_from = util.dateToStr(dt_date_from) date_till = util.dateToStr(dt_date_from + relativedelta(days=weekday + (6 - weekday))) cashreport_name = _("%s - CW %s %s") % (cashreport_name, kw, dt_date_from.year) # calc date else: if offset: dt_date_from = util.strToDate(start_date) dt_date_from += relativedelta(days=offset) date_from = util.dateToStr(dt_date_from) date_till = date_from cashreport_name = _("%s - %s") % (cashreport_name, f.formatLang(date_from, date=True)) return (date_from, date_till, cashreport_name)
def action_report(self): session_obj = self.pool["pos.session"] for wizard in self: # get ids config_ids = [p.id for p in wizard.pos_ids] session_ids = session_obj.search(self._cr, self._uid, [("start_at",">=",wizard.date_from),("start_at","<=",wizard.date_till),("config_id","in",config_ids),("state","=","closed")], context=self._context) if not session_ids: return True datas = { "ids": session_ids, "model": "pos.session" } # get context report_ctx = self._context and dict(self._context) or {} # format f = format.LangFormat(self._cr, self._uid, self._context) if wizard.range == "month": dt = util.strToDate(wizard.date_from) dt_till = util.strToDate(wizard.date_till) report_name = _("%s - %s / %s %s") % (f.formatLang(wizard.date_from, date=True), f.formatLang(wizard.date_till, date=True), helper.getMonthName(self._cr, self._uid, dt.month, context=self._context), dt.year) if dt_till.year != dt.year or dt_till.month != dt.month: report_name = _("%s - %s %s") % (report_name, helper.getMonthName(self._cr, self._uid, dt_till.month, context=self._context), dt_till.year) elif wizard.range == "week": dt = util.strToDate(wizard.date_from) dt_till = util.strToDate(wizard.date_till) kw = dt.isocalendar()[1] kw_till = dt_till.isocalendar()[1] report_name = _("%s - %s / CW %s %s") % (f.formatLang(wizard.date_from, date=True), f.formatLang(wizard.date_till, date=True), kw, dt.year) if dt_till.year != dt.year or kw != kw_till: report_name = _("%s - CW %s %s") % (report_name, kw_till, dt_till.year) else: if wizard.date_from == wizard.date_till: report_name = f.formatLang(wizard.date_from, date=True) else: report_name = "%s - %s" % (f.formatLang(wizard.date_from, date=True), f.formatLang(wizard.date_till, date=True)) # report name report_ctx["cashreport_name"] = report_name # check options if wizard.detail: report_ctx["print_detail"] = True if wizard.separate: report_ctx["no_group"] = True if wizard.product: report_ctx["print_product"] = True # add report info report_ctx["pos_report_info"] = { "name" : report_name, "from" : wizard.date_from, "till" : wizard.date_till, "config_ids" : config_ids } # return return { "type": "ir.actions.report.xml", "report_name": "point_of_sale.report_sessionsummary", "datas": datas, "context" : report_ctx }