[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) <jcb@odoo.com>
This commit is contained in:
Jitendra Prajapat
2023-09-06 13:25:27 +00:00
parent 91aceecc63
commit 4c8fddd570
11 changed files with 25 additions and 41 deletions
+2 -2
View File
@@ -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,
@@ -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.
@@ -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",
},
@@ -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();
@@ -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);
+1 -1
View File
@@ -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,
@@ -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,
@@ -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,
]
@@ -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();
@@ -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;
}
},
+1 -1
View File
@@ -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': [],