1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| class stat_pos_order(osv.osv):
_name = 'stat.pos.order'
_description = 'POS orders stats'
_order = 'date'
_auto = False
_columns = {
'date' : fields.date('Date', readonly=True),
'day' : fields.char('Day', size=128, readonly=True),
'date_normal' : fields.date('Day', readonly=True),
'week' : fields.char('Week', readonly=True),
'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'),
('05','May'), ('06','June'), ('07','July'), ('08','August'), ('09','September'),
('10','October'), ('11','November'), ('12','December')], 'Month',readonly=True),
'year' : fields.char('Year', readonly=True),
'company_id':fields.many2one('res.company', 'Company', readonly=True),
'shop_id':fields.many2one('sale.shop', 'Shop', readonly=True),
'cashier_name': fields.char('Cashier', size=128),
'discount': fields.float('Remise', readonly=True),
'bon_achat': fields.float("Bon d'achat", readonly=True),
'amount_total': fields.float("Total", readonly=True),
'special_discount': fields.float('Special discount', readonly=True),
'loyalty_discount': fields.float('Loyalty discount', readonly=True),
'flask_discount': fields.float('Flask discount', readonly=True),
'total': fields.float('Total', readonly=True),
'average': fields.float('Average', readonly=True, group_operator="avg"),
'nbr': fields.integer('One', readonly=True)
}
def init(self, cr):
tools.drop_view_if_exists(cr, 'stat_pos_order')
cr.execute("""
CREATE OR REPLACE VIEW stat_pos_order AS (
SELECT
min(po.id) AS id,
to_number('1','999') AS nbr,
date_trunc('day',po.date_order) AS date,
to_char(date_trunc('week',po.date_order), 'WW') AS week,
to_char(date_trunc('day',po.date_order), 'YYYY') AS year,
to_char(date_trunc('day',po.date_order), 'MM') AS month,
to_char(date_trunc('day',po.date_order), 'YYYY-MM-DD') AS day,
po.company_id AS company_id,
po.shop_id AS shop_id,
po.cashier_name AS cashier_name,
po.discount AS discount,
po.bon_achat AS bon_achat,
po.special_discount AS special_discount,
po.loyalty_discount AS loyalty_discount,
po.flask_discount AS flask_discount,
po.total AS total,
avg(po.total) AS average,
to_char(po.date_order, 'YYYY-MM-DD HH24:MI:SS') AS date_normal
FROM
pos_order po
GROUP BY
date_trunc('day', po.date_order), po.company_id, po.shop_id, po.cashier_name, po.discount,
po.bon_achat, po.special_discount, po.loyalty_discount, po.flask_discount,
po.total, year, month, day, week, date_normal, nbr
)
""") |
Partager