Exemplo n.º 1
0
 def table_query(cls):
     pool = Pool()
     Month = pool.get('ir.calendar.month')
     month = Month.__table__()
     query = super(SaleOpportunityMonthly, cls).table_query()
     opportunity, = query.from_
     month_timestamp = DateTrunc('MONTH', opportunity.start_date)
     id_ = Extract('EPOCH', month_timestamp)
     month = cls.month.sql_cast(month_timestamp)
     query.columns += (
         id_.as_('id'),
         month.as_('month'),
     )
     query.group_by = [id_, month, opportunity.company]
     return query
Exemplo n.º 2
0
 def test_function_date_trunc(self):
     "Test DateTrunc function"
     cursor = Transaction().connection.cursor()
     date = dt.datetime(2001, 2, 16, 20, 38, 40, 100)
     for type_, result in [
         ('microsecond', dt.datetime(2001, 2, 16, 20, 38, 40, 100)),
         ('second', dt.datetime(2001, 2, 16, 20, 38, 40)),
         ('minute', dt.datetime(2001, 2, 16, 20, 38)),
         ('hour', dt.datetime(2001, 2, 16, 20)),
         ('day', dt.datetime(2001, 2, 16)),
         ('month', dt.datetime(2001, 2, 1)),
     ]:
         for type_ in [type_.lower(), type_.upper()]:
             with self.subTest(type_=type_):
                 cursor.execute(*Select([DateTrunc(type_, date)]))
                 value, = cursor.fetchone()
                 self.assertEqual(str(value), str(result))
Exemplo n.º 3
0
 def _column_date(cls, tables):
     context = Transaction().context
     sale = tables['line.sale']
     date = DateTrunc(context.get('period'), sale.sale_date)
     date = cls.date.sql_cast(date)
     return date
Exemplo n.º 4
0
 def _column_date(cls, tables, withs):
     context = Transaction().context
     move = tables['move']
     date = DateTrunc(context.get('period'), move.effective_date)
     date = cls.date.sql_cast(date)
     return date