diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 2e8ced959e2..0d342840eba 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -12,6 +12,7 @@ from odoo.tools import float_is_zero from odoo.exceptions import UserError from odoo.http import request from odoo.addons import decimal_precision as dp +from odoo.osv.expression import AND _logger = logging.getLogger(__name__) @@ -1175,41 +1176,50 @@ class ReportSaleDetails(models.AbstractModel): @api.model - def get_sale_details(self, date_start=False, date_stop=False, configs=False): - """ Serialise the orders of the day information + def get_sale_details(self, date_start=False, date_stop=False, config_ids=False, session_ids=False): + """ Serialise the orders of the requested time period, configs and sessions. - params: date_start, date_stop string representing the datetime of order + :param date_start: The dateTime to start, default today 00:00:00. + :type date_start: str. + :param date_stop: The dateTime to stop, default date_start + 23:59:59. + :type date_stop: str. + :param config_ids: Pos Config id's to include. + :type config_ids: list of numbers. + :param session_ids: Pos Config id's to include. + :type session_ids: list of numbers. + + :returns: dict -- Serialised sales. """ - if not configs: - configs = self.env['pos.config'].search([]) + domain = [('state', 'in', ['paid','invoiced','done'])] - user_tz = pytz.timezone(self.env.context.get('tz') or self.env.user.tz or 'UTC') - today = user_tz.localize(fields.Datetime.from_string(fields.Date.context_today(self))) - today = today.astimezone(pytz.timezone('UTC')) - if date_start: - date_start = fields.Datetime.from_string(date_start) + if (session_ids): + AND(domain, [('session_id', 'in', session_ids)]) else: - # start by default today 00:00:00 - date_start = today + if date_start: + date_start = fields.Datetime.from_string(date_start) + else: + # start by default today 00:00:00 + user_tz = pytz.timezone(self.env.context.get('tz') or self.env.user.tz or 'UTC') + today = user_tz.localize(fields.Datetime.from_string(fields.Date.context_today(self))) + date_start = today.astimezone(pytz.timezone('UTC')) - if date_stop: - # set time to 23:59:59 - date_stop = fields.Datetime.from_string(date_stop) - else: - # stop by default today 23:59:59 - date_stop = today + timedelta(days=1, seconds=-1) + if date_stop: + date_stop = fields.Datetime.from_string(date_stop) + # avoid a date_stop smaller than date_start + if (date_stop < date_start): + date_stop = date_start + timedelta(days=1, seconds=-1) + else: + # stop by default today 23:59:59 + date_stop = date_start + timedelta(days=1, seconds=-1) - # avoid a date_stop smaller than date_start - date_stop = max(date_stop, date_start) + AND(domain, [ + ('date_order', '>=', fields.Datetime.to_string(date_start)), + ('date_order', '<=', fields.Datetime.to_string(date_stop)),]) - date_start = fields.Datetime.to_string(date_start) - date_stop = fields.Datetime.to_string(date_stop) + if config_ids: + AND(domain, [('config_id', 'in', config_ids)]) - orders = self.env['pos.order'].search([ - ('date_order', '>=', date_start), - ('date_order', '<=', date_stop), - ('state', 'in', ['paid','invoiced','done']), - ('config_id', 'in', configs.ids)]) + orders = self.env['pos.order'].search(domain) user_currency = self.env.company_id.currency_id diff --git a/addons/point_of_sale/static/src/js/chrome.js b/addons/point_of_sale/static/src/js/chrome.js index f1a79a22064..5e1ad64eb32 100644 --- a/addons/point_of_sale/static/src/js/chrome.js +++ b/addons/point_of_sale/static/src/js/chrome.js @@ -406,9 +406,11 @@ var ProxyStatusWidget = StatusWidget.extend({ /* --------- The Sale Details --------- */ -// Generates a report to print the sales of the -// day on a ticket - +/** Print an overview of todays sales. + * + * If the current cashier is a manager all sales of the day will be printed, else only the sales of the current + * session will be printed. + */ var SaleDetailsButton = PosBaseWidget.extend({ template: 'SaleDetailsButton', start: function(){ diff --git a/addons/point_of_sale/static/src/js/devices.js b/addons/point_of_sale/static/src/js/devices.js index 683ca3f6853..b981ef66ac8 100644 --- a/addons/point_of_sale/static/src/js/devices.js +++ b/addons/point_of_sale/static/src/js/devices.js @@ -480,11 +480,16 @@ var ProxyDevice = core.Class.extend(mixins.PropertiesMixin,{ send_printing_job(); }, + /** Print an overview of todays sales. + * + * By default this will print all sales of the day for current PoS config. + */ print_sale_details: function() { var self = this; rpc.query({ model: 'report.point_of_sale.report_saledetails', method: 'get_sale_details', + args: [false, false, false, [this.pos.pos_session.id]], }) .then(function(result){ var env = { diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index e7ce7f53213..9caea22a4b5 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -89,7 +89,7 @@
- +