[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) <jpp@odoo.com>
This commit is contained in:
Jorge Pinna Puissant
2020-05-11 09:32:36 +00:00
parent 0602f5989e
commit 44ce4baadd
+2 -1
View File
@@ -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