[IMP] point_of_sale: restrict print sale datails
Have two pos config opened, with at least one connected to a POS box with a printer Do some sales on both Click on the printer icon in the pos UI to print today's sales Before this commit, the ticket that was printed contained sales for both point of sales After this commit, it only contains sales of the point of sale from which the print request has been sent OPW 1958885 Before this commmit everyone could print the sale datails for all day for the current PoS Config from the UI. After this commit cashiers can only print the current session, disregarding the date. TASK-ID: 1978713 closes odoo/odoo#33036 Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
This commit is contained in:
committed by
Pierre Masereel
parent
9d9a866cc3
commit
af86bc7288
@@ -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
|
||||
|
||||
|
||||
@@ -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(){
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
@@ -89,7 +89,7 @@
|
||||
<t t-name="SaleDetailsButton">
|
||||
<div class="oe_status">
|
||||
<div class="js_connected oe_icon">
|
||||
<i class='fa fa-fw fa-print' role="img" aria-label="Print" title="Print"></i>
|
||||
<i class='fa fa-fw fa-print' role="img" aria-label="Print" title="Print a report with all the sales of the current PoS Session"></i>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
Reference in New Issue
Block a user