From 4c8fddd57029608bb616c2ff4761b7d41b674986 Mon Sep 17 00:00:00 2001 From: Jitendra Prajapat Date: Mon, 28 Aug 2023 10:24:58 +0530 Subject: [PATCH] [FIX] point_of_sale: modified flow of order date Before this commit: =================== In the back-end, there is only one field "date_order" is used, while on the frontend side, there are two separate fields: "creation_date" and "validation_date," which causes confusion in the code flow and leads to redundancies. After this commit: ================== Revised the order date flow by eliminating the confusion stemming from the separate "creation_date" and "validation_date" fields. Both have been consolidated into the "date_order" field, offering clarity to the order date process. task - 3482072 closes odoo/odoo#133293 Signed-off-by: Joseph Caburnay (jcb) --- addons/point_of_sale/models/pos_order.py | 4 ++-- .../screens/payment_screen/payment_screen.js | 2 +- .../app/screens/ticket_screen/ticket_screen.js | 12 +++--------- .../static/src/app/store/models.js | 17 ++++++----------- .../static/src/app/store/pos_store.js | 3 +-- addons/point_of_sale/tests/common.py | 2 +- .../tests/test_point_of_sale_flow.py | 16 ++++++++-------- .../static/src/overrides/models/loyalty.js | 2 +- .../screens/payment_screen/payment_screen.js | 2 +- .../static/src/overrides/models/models.js | 4 ---- addons/pos_self_order/controllers/orders.py | 2 +- 11 files changed, 25 insertions(+), 41 deletions(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index ce66d5721e7..04562bc7bac 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -45,7 +45,7 @@ class PosOrder(models.Model): 'pos_reference': ui_order['name'], 'sequence_number': ui_order['sequence_number'], 'partner_id': ui_order['partner_id'] or False, - 'date_order': ui_order['creation_date'].replace('T', ' ')[:19], + 'date_order': ui_order['date_order'].replace('T', ' ')[:19], 'fiscal_position_id': ui_order['fiscal_position_id'], 'pricelist_id': ui_order.get('pricelist_id'), 'amount_paid': ui_order['amount_paid'], @@ -1115,7 +1115,7 @@ class PosOrder(models.Model): 'partner_id': order.partner_id.id, 'user_id': order.user_id.id, 'sequence_number': order.sequence_number, - 'creation_date': str(order.date_order.astimezone(timezone)), + 'date_order': str(order.date_order.astimezone(timezone)), 'fiscal_position_id': order.fiscal_position_id.id, 'to_invoice': order.to_invoice, 'shipping_date': order.shipping_date, diff --git a/addons/point_of_sale/static/src/app/screens/payment_screen/payment_screen.js b/addons/point_of_sale/static/src/app/screens/payment_screen/payment_screen.js index e911d796bcb..f0c7ee20649 100644 --- a/addons/point_of_sale/static/src/app/screens/payment_screen/payment_screen.js +++ b/addons/point_of_sale/static/src/app/screens/payment_screen/payment_screen.js @@ -235,7 +235,7 @@ export class PaymentScreen extends Component { this.hardwareProxy.openCashbox(); } - this.currentOrder.initialize_validation_date(); + this.currentOrder.date_order = luxon.DateTime.now(); this.currentOrder.finalized = true; // 1. Save order to server. diff --git a/addons/point_of_sale/static/src/app/screens/ticket_screen/ticket_screen.js b/addons/point_of_sale/static/src/app/screens/ticket_screen/ticket_screen.js index b38009942a5..a9b1697bba2 100644 --- a/addons/point_of_sale/static/src/app/screens/ticket_screen/ticket_screen.js +++ b/addons/point_of_sale/static/src/app/screens/ticket_screen/ticket_screen.js @@ -3,7 +3,7 @@ import { Order } from "@point_of_sale/app/store/models"; import { registry } from "@web/core/registry"; import { useService } from "@web/core/utils/hooks"; -import { deserializeDateTime, deserializeDate } from "@web/core/l10n/dates"; +import { deserializeDateTime, deserializeDate, formatDateTime } from "@web/core/l10n/dates"; import { parseFloat } from "@web/views/fields/parsers"; import { _t } from "@web/core/l10n/translation"; @@ -372,13 +372,7 @@ export class TicketScreen extends Component { return this._getOrderList().filter(predicate); } getDate(order) { - let validation_date = order.validation_date || DateTime.now(); - if (typeof validation_date === "string") { - validation_date = DateTime.fromISO(validation_date); - } else if (validation_date instanceof Date) { - validation_date = DateTime.fromJSDate(validation_date); - } - return validation_date.toFormat("yyyy-MM-dd HH:mm a"); + return formatDateTime(order.date_order); } getTotal(order) { return this.env.utils.formatCurrency(order.get_total_with_tax()); @@ -633,7 +627,7 @@ export class TicketScreen extends Component { }, DATE: { repr: (order) => - deserializeDate(order.creation_date).toFormat("yyyy-MM-dd HH:mm a"), + deserializeDate(order.date_order).toFormat("yyyy-MM-dd HH:mm a"), displayName: _t("Date"), modelField: "date_order", }, diff --git a/addons/point_of_sale/static/src/app/store/models.js b/addons/point_of_sale/static/src/app/store/models.js index 479bc873369..d9d619221ae 100644 --- a/addons/point_of_sale/static/src/app/store/models.js +++ b/addons/point_of_sale/static/src/app/store/models.js @@ -9,6 +9,7 @@ import { formatDateTime, serializeDateTime, deserializeDate, + deserializeDateTime, } from "@web/core/l10n/dates"; import { roundDecimals as round_di, @@ -1299,7 +1300,7 @@ export class Order extends PosModel { this.selected_paymentline = undefined; this.screen_data = {}; // see Gui this.temporary = options.temporary || false; - this.creation_date = new Date(); + this.date_order = luxon.DateTime.now(); this.to_invoice = false; this.orderlines = new PosCollection(); this.paymentlines = new PosCollection(); @@ -1343,7 +1344,6 @@ export class Order extends PosModel { this.ticketCode = this._generateTicketCode(); // 5-digits alphanum code shown on the receipt this.uid = this.generate_unique_id(); this.name = _t("Order %s", this.uid); - this.validation_date = undefined; this.fiscal_position = this.pos.fiscal_positions.find(function (fp) { return fp.id === self.pos.config.default_fiscal_position_id[0]; }); @@ -1391,7 +1391,7 @@ export class Order extends PosModel { } else { this.name = _t("Order %s", this.uid); } - this.validation_date = json.creation_date; + this.date_order = deserializeDateTime(json.date_order); this.server_id = json.server_id || json.id || false; this.user_id = json.user_id; this.firstDraft = false; @@ -1498,7 +1498,7 @@ export class Order extends PosModel { user_id: this.pos.user.id, uid: this.uid, sequence_number: this.sequence_number, - creation_date: this.validation_date || this.creation_date, // todo: rename creation_date in master + date_order: serializeDateTime(this.date_order), fiscal_position_id: this.fiscal_position ? this.fiscal_position.id : false, server_id: this.server_id ? this.server_id : false, to_invoice: this.to_invoice ? this.to_invoice : false, @@ -1570,8 +1570,8 @@ export class Order extends PosModel { hour: date.getHours(), minute: date.getMinutes(), isostring: date.toISOString(), - localestring: this.formatted_validation_date, - validation_date: this.validation_date, + localestring: formatDateTime(luxon.DateTime.now()), + date_order: this.date_order, }, company: { email: company.email, @@ -1953,11 +1953,6 @@ export class Order extends PosModel { } } - initialize_validation_date() { - this.validation_date = new Date(); - this.formatted_validation_date = formatDateTime(DateTime.fromJSDate(this.validation_date)); - } - set_tip(tip) { var tip_product = this.pos.db.get_product_by_id(this.pos.config.tip_product_id[0]); var lines = this.get_orderlines(); diff --git a/addons/point_of_sale/static/src/app/store/pos_store.js b/addons/point_of_sale/static/src/app/store/pos_store.js index fe0e31b27e4..d4fc0a9d2e4 100644 --- a/addons/point_of_sale/static/src/app/store/pos_store.js +++ b/addons/point_of_sale/static/src/app/store/pos_store.js @@ -1129,8 +1129,7 @@ export class PosStore extends Reactive { } else { for (const order of orders) { const reactiveOrder = this.orders.find((o) => o.uid === order.id); - reactiveOrder.validation_date = null; - reactiveOrder.formatted_validation_date = null; + reactiveOrder.date_order = null; reactiveOrder.finalized = false; this.db.remove_order(reactiveOrder.uid); this.db.save_unpaid_order(reactiveOrder); diff --git a/addons/point_of_sale/tests/common.py b/addons/point_of_sale/tests/common.py index 17543c3de1f..a6ab74afd34 100644 --- a/addons/point_of_sale/tests/common.py +++ b/addons/point_of_sale/tests/common.py @@ -545,7 +545,7 @@ class TestPoSCommon(ValuationReconciliationTestCommon): 'amount_return': 0, 'amount_tax': total_amount_incl - total_amount_base, 'amount_total': total_amount_incl, - 'creation_date': fields.Datetime.to_string(fields.Datetime.now()), + 'date_order': fields.Datetime.to_string(fields.Datetime.now()), 'fiscal_position_id': fiscal_position.id, 'pricelist_id': self.config.pricelist_id.id, 'lines': order_lines, diff --git a/addons/point_of_sale/tests/test_point_of_sale_flow.py b/addons/point_of_sale/tests/test_point_of_sale_flow.py index fdbec7dc3a5..a272a7813f0 100644 --- a/addons/point_of_sale/tests/test_point_of_sale_flow.py +++ b/addons/point_of_sale/tests/test_point_of_sale_flow.py @@ -567,7 +567,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): 'amount_return': 0, 'amount_tax': atax, 'amount_total': untax + atax, - 'creation_date': fields.Datetime.to_string(fields.Datetime.now()), + 'date_order': fields.Datetime.to_string(fields.Datetime.now()), 'fiscal_position_id': False, 'lines': [[0, 0, @@ -598,7 +598,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): 'amount_return': 0, 'amount_tax': atax, 'amount_total': untax + atax, - 'creation_date': fields.Datetime.to_string(fields.Datetime.now()), + 'date_order': fields.Datetime.to_string(fields.Datetime.now()), 'fiscal_position_id': False, 'lines': [[0, 0, @@ -629,7 +629,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): 'amount_return': 0, 'amount_tax': atax, 'amount_total': untax + atax, - 'creation_date': fields.Datetime.to_string(fields.Datetime.now()), + 'date_order': fields.Datetime.to_string(fields.Datetime.now()), 'fiscal_position_id': False, 'lines': [[0, 0, @@ -912,7 +912,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): 'amount_return': 0, 'amount_tax': atax, 'amount_total': untax + atax, - 'creation_date': fields.Datetime.to_string(fields.Datetime.now()), + 'date_order': fields.Datetime.to_string(fields.Datetime.now()), 'fiscal_position_id': False, 'lines': [[0, 0, @@ -1121,7 +1121,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): 'amount_return': 10, 'amount_tax': 0, 'amount_total': 750, - 'creation_date': fields.Datetime.to_string(fields.Datetime.now()), + 'date_order': fields.Datetime.to_string(fields.Datetime.now()), 'fiscal_position_id': False, 'lines': [[0, 0, { 'discount': 0, @@ -1179,7 +1179,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): 'amount_return': 0, 'amount_tax': atax, 'amount_total': untax + atax, - 'creation_date': fields.Datetime.to_string(fields.Datetime.now()), + 'date_order': fields.Datetime.to_string(fields.Datetime.now()), 'fiscal_position_id': False, 'lines': [(0, 0, { 'discount': 0, @@ -1260,7 +1260,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): 'amount_tax': 0, 'amount_return':0, 'amount_total': 750, - 'creation_date': fields.Datetime.to_string(fields.Datetime.now()), + 'date_order': fields.Datetime.to_string(fields.Datetime.now()), 'fiscal_position_id': False, 'lines': [[0, 0, { 'discount': 0, @@ -1485,7 +1485,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): 'amount_tax': 0, 'amount_return': 0, 'amount_total': 450, - 'creation_date': fields.Datetime.to_string(fields.Datetime.now()), + 'date_order': fields.Datetime.to_string(fields.Datetime.now()), 'fiscal_position_id': False, 'lines': [[0, 0, { 'discount': 0, diff --git a/addons/pos_loyalty/static/src/overrides/models/loyalty.js b/addons/pos_loyalty/static/src/overrides/models/loyalty.js index e16440b81be..67de9b59f75 100644 --- a/addons/pos_loyalty/static/src/overrides/models/loyalty.js +++ b/addons/pos_loyalty/static/src/overrides/models/loyalty.js @@ -1501,7 +1501,7 @@ patch(Order.prototype, { [ [this.pos.config.id], code, - this.creation_date, + this.date_order, customerId, this.pricelist ? this.pricelist.id : false, ] diff --git a/addons/pos_online_payment/static/src/app/screens/payment_screen/payment_screen.js b/addons/pos_online_payment/static/src/app/screens/payment_screen/payment_screen.js index 6da133b68a1..c087c7492d2 100644 --- a/addons/pos_online_payment/static/src/app/screens/payment_screen/payment_screen.js +++ b/addons/pos_online_payment/static/src/app/screens/payment_screen/payment_screen.js @@ -68,7 +68,7 @@ patch(PaymentScreen.prototype, { // online payments to the order. // The validation process will be done by the server directly after a successful // online payment that makes the order fully paid. - this.currentOrder.initialize_validation_date(); + this.currentOrder.date_order = luxon.DateTime.now(); this.currentOrder.save_to_db(); this.pos.addOrderToUpdateSet(); diff --git a/addons/pos_restaurant/static/src/overrides/models/models.js b/addons/pos_restaurant/static/src/overrides/models/models.js index ad93f8d58a3..5a2c5123785 100644 --- a/addons/pos_restaurant/static/src/overrides/models/models.js +++ b/addons/pos_restaurant/static/src/overrides/models/models.js @@ -1,9 +1,7 @@ /** @odoo-module */ import { Order, Orderline, Payment } from "@point_of_sale/app/store/models"; -import { parseDateTime } from "@web/core/l10n/dates"; import { patch } from "@web/core/utils/patch"; -const { DateTime } = luxon; // New orders are now associated with the current table, if any. patch(Order.prototype, { @@ -31,8 +29,6 @@ patch(Order.prototype, { super.init_from_JSON(...arguments); if (this.pos.config.module_pos_restaurant) { this.tableId = json.table_id; - const creationDate = parseDateTime(json.creation_date) || DateTime.now(); //ex : json.creation_date = "2023-08-25 13:24:16+02:00" - this.validation_date = creationDate.toJSDate(); this.customerCount = json.customer_count; } }, diff --git a/addons/pos_self_order/controllers/orders.py b/addons/pos_self_order/controllers/orders.py index 9b16f2ff749..637c767cca1 100644 --- a/addons/pos_self_order/controllers/orders.py +++ b/addons/pos_self_order/controllers/orders.py @@ -35,7 +35,7 @@ class PosSelfOrderController(http.Controller): 'pos_session_id': pos_session.id, 'table_id': table.id if table else False, 'partner_id': False, - 'creation_date': str(fields.Datetime.now()), + 'date_order': str(fields.Datetime.now()), 'fiscal_position_id': pos_config.default_fiscal_position_id.id, 'statement_ids': [], 'lines': [],