Server IP : 127.0.0.2 / Your IP : 18.222.34.209 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /opt/odoo/addons/point_of_sale/report/ |
Upload File : |
# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import api, fields, models, tools class PosOrderReport(models.Model): _name = "report.pos.order" _description = "Point of Sale Orders Statistics" _auto = False _order = 'date desc' date = fields.Datetime(string='Date Order', readonly=True) order_id = fields.Many2one('pos.order', string='Order', readonly=True) partner_id = fields.Many2one('res.partner', string='Partner', readonly=True) product_id = fields.Many2one('product.product', string='Product', readonly=True) product_tmpl_id = fields.Many2one('product.template', string='Product Template', readonly=True) state = fields.Selection( [('draft', 'New'), ('paid', 'Paid'), ('done', 'Posted'), ('invoiced', 'Invoiced'), ('cancel', 'Cancelled')], string='Status') user_id = fields.Many2one('res.users', string='Salesperson', readonly=True) price_total = fields.Float(string='Total Price', readonly=True) price_sub_total = fields.Float(string='Subtotal w/o discount', readonly=True) total_discount = fields.Float(string='Total Discount', readonly=True) average_price = fields.Float(string='Average Price', readonly=True, group_operator="avg") location_id = fields.Many2one('stock.location', string='Location', readonly=True) company_id = fields.Many2one('res.company', string='Company', readonly=True) nbr_lines = fields.Integer(string='# of Lines', readonly=True, oldname='nbr') product_qty = fields.Integer(string='Product Quantity', readonly=True) journal_id = fields.Many2one('account.journal', string='Journal') delay_validation = fields.Integer(string='Delay Validation') product_categ_id = fields.Many2one('product.category', string='Product Category', readonly=True) invoiced = fields.Boolean(readonly=True) config_id = fields.Many2one('pos.config', string='Point of Sale', readonly=True) pos_categ_id = fields.Many2one('pos.category', string='Public Category', readonly=True) stock_location_id = fields.Many2one('stock.location', string='Warehouse', readonly=True) pricelist_id = fields.Many2one('product.pricelist', string='Pricelist', readonly=True) session_id = fields.Many2one('pos.session', string='Session', readonly=True) @api.model_cr def init(self): tools.drop_view_if_exists(self._cr, 'report_pos_order') self._cr.execute(""" CREATE OR REPLACE VIEW report_pos_order AS ( SELECT MIN(l.id) AS id, COUNT(*) AS nbr_lines, s.date_order AS date, SUM(l.qty) AS product_qty, SUM(l.qty * l.price_unit) AS price_sub_total, SUM((l.qty * l.price_unit) * (100 - l.discount) / 100) AS price_total, SUM((l.qty * l.price_unit) * (l.discount / 100)) AS total_discount, (SUM(l.qty*l.price_unit)/SUM(l.qty * u.factor))::decimal AS average_price, SUM(cast(to_char(date_trunc('day',s.date_order) - date_trunc('day',s.create_date),'DD') AS INT)) AS delay_validation, s.id as order_id, s.partner_id AS partner_id, s.state AS state, s.user_id AS user_id, s.location_id AS location_id, s.company_id AS company_id, s.sale_journal AS journal_id, l.product_id AS product_id, pt.categ_id AS product_categ_id, p.product_tmpl_id, ps.config_id, pt.pos_categ_id, pc.stock_location_id, s.pricelist_id, s.session_id, s.invoice_id IS NOT NULL AS invoiced FROM pos_order_line AS l LEFT JOIN pos_order s ON (s.id=l.order_id) LEFT JOIN product_product p ON (l.product_id=p.id) LEFT JOIN product_template pt ON (p.product_tmpl_id=pt.id) LEFT JOIN product_uom u ON (u.id=pt.uom_id) LEFT JOIN pos_session ps ON (s.session_id=ps.id) LEFT JOIN pos_config pc ON (ps.config_id=pc.id) GROUP BY s.id, s.date_order, s.partner_id,s.state, pt.categ_id, s.user_id, s.location_id, s.company_id, s.sale_journal, s.pricelist_id, s.invoice_id, s.create_date, s.session_id, l.product_id, pt.categ_id, pt.pos_categ_id, p.product_tmpl_id, ps.config_id, pc.stock_location_id HAVING SUM(l.qty * u.factor) != 0 ) """)