From 44ce4baaddbdb68d0c49888fcc1867da965f496d Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Fri, 8 May 2020 09:26:54 +0000 Subject: [PATCH] [FIX] point_of_sale: wrong date on invoice created from pos - Have a user in an early timezone (for example Samoa Standard Time); - Open a POS session in the evening (say 20h). - Buy something, pay and ask for an invoice. Before this commit, the date of the order was correct (today at 20h), but the date of the invoice was wrong (it shows tomorrows date). This issue occurs because the invoice date wasn't taking into account the timezone. Now, both dates are corrected. opw-2231820 closes odoo/odoo#51001 X-original-commit: 19e9c4a0380e7ad7af297d13909dcbc63629a20d Signed-off-by: Jorge Pinna Puissant (jpp) --- addons/point_of_sale/models/pos_order.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 74cf28f310a..736a8eb72d1 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -381,6 +381,7 @@ class PosOrder(models.Model): if not order.partner_id: raise UserError(_('Please provide a partner for the sale.')) + timezone = pytz.timezone(self._context.get('tz') or self.env.user.tz or 'UTC') move_vals = { 'payment_reference': order.name, 'invoice_origin': order.name, @@ -392,7 +393,7 @@ class PosOrder(models.Model): # considering partner's sale pricelist's currency 'currency_id': order.pricelist_id.currency_id.id, 'invoice_user_id': order.user_id.id, - 'invoice_date': order.date_order.date(), + 'invoice_date': order.date_order.astimezone(timezone).date(), 'fiscal_position_id': order.fiscal_position_id.id, 'invoice_line_ids': [(0, None, order._prepare_invoice_line(line)) for line in order.lines], 'invoice_cash_rounding_id': order.config_id.rounding_method.id if order.config_id.cash_rounding else False