From e82f75d66f1a1242a4236c4eff5eef68b413c9d1 Mon Sep 17 00:00:00 2001 From: vlst Date: Tue, 13 Jun 2023 13:29:33 +0000 Subject: [PATCH] [IMP] point_of_sale, *: Unify price type field *: l10n_fr_pos_cert, pos_discount, pos_loyalty, pos_sale, pos_self_order The `Orderline` model contains the fields: `price_manually_set` and `price_automatically_set`. They are meant to signify what type of price the orderline has: `automatic`, `manual` or `original`. It's very confusing to manage the two fields when in fact they only describe three types of setting the orderline price. This PR replaces the 2 fields with a single one: `price_type`, which will take one of the 3 possible values. closes odoo/odoo#124858 Task: 3358265 Signed-off-by: Heinz Robin (rhe) --- .../static/src/xml/OrderReceipt.xml | 2 +- .../static/src/xml/Orderline.xml | 2 +- .../screens/product_screen/product_screen.js | 4 ++-- .../screens/ticket_screen/ticket_screen.js | 2 +- .../static/src/app/store/models.js | 24 ++++++++----------- .../static/src/js/DiscountButton.js | 2 +- addons/pos_loyalty/static/src/js/Loyalty.js | 2 +- .../SaleOrderManagementScreen.js | 4 ++-- addons/pos_self_order/controllers/ordering.py | 2 +- 9 files changed, 20 insertions(+), 24 deletions(-) diff --git a/addons/l10n_fr_pos_cert/static/src/xml/OrderReceipt.xml b/addons/l10n_fr_pos_cert/static/src/xml/OrderReceipt.xml index e014f6aebb8..ca55a4fe041 100644 --- a/addons/l10n_fr_pos_cert/static/src/xml/OrderReceipt.xml +++ b/addons/l10n_fr_pos_cert/static/src/xml/OrderReceipt.xml @@ -11,7 +11,7 @@ - +
Old unit price: diff --git a/addons/l10n_fr_pos_cert/static/src/xml/Orderline.xml b/addons/l10n_fr_pos_cert/static/src/xml/Orderline.xml index 87417bd4bfa..d51460ee103 100644 --- a/addons/l10n_fr_pos_cert/static/src/xml/Orderline.xml +++ b/addons/l10n_fr_pos_cert/static/src/xml/Orderline.xml @@ -3,7 +3,7 @@ - +
  • Old unit price: diff --git a/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js b/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js index eec88231a5f..ac8b67c298a 100644 --- a/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js +++ b/addons/point_of_sale/static/src/app/screens/product_screen/product_screen.js @@ -128,7 +128,7 @@ export class ProductScreen extends ControlButtonsMixin(Component) { this.currentOrder.get_selected_orderline().set_discount(val); } else if (numpadMode === "price") { var selected_orderline = this.currentOrder.get_selected_orderline(); - selected_orderline.price_manually_set = true; + selected_orderline.price_type = "manual"; selected_orderline.set_unit_price(val); } } @@ -162,7 +162,7 @@ export class ProductScreen extends ControlButtonsMixin(Component) { Object.assign(options, { price: code.value, extras: { - price_manually_set: true, + price_type: "manual", }, }); } else if (code.type === "weight" || code.type === 'quantity') { 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 a0f1dc76061..013a1e07837 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 @@ -547,7 +547,7 @@ export class TicketScreen extends Component { return { quantity: -qty, price: orderline.price, - extras: { price_automatically_set: true }, + extras: { price_type: "automatic" }, merge: false, refunded_orderline_id: orderline.id, tax_ids: orderline.tax_ids, 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 58ae94d1a11..90c8803e6f9 100644 --- a/addons/point_of_sale/static/src/app/store/models.js +++ b/addons/point_of_sale/static/src/app/store/models.js @@ -1817,10 +1817,10 @@ export class Orderline extends PosModel { super.setup(...arguments); this.pos = options.pos; this.order = options.order; - this.price_manually_set = options.price_manually_set || false; + this.price_type = options.price_type; this.uuid = this.uuid || uuidv4(); - this.price_automatically_set = options.price_automatically_set || false; + this.price_type = options.price_type || "original"; if (options.json) { try { this.init_from_JSON(options.json); @@ -1860,8 +1860,7 @@ export class Orderline extends PosModel { this.product = this.pos.db.get_product_by_id(json.product_id); this.set_product_lot(this.product); this.price = json.price_unit; - this.price_manually_set = json.price_manually_set; - this.price_automatically_set = json.price_automatically_set; + this.price_type = json.price_type; this.set_discount(json.discount); this.set_quantity(json.qty, "do not recompute unit price"); this.set_description(json.description); @@ -1899,8 +1898,7 @@ export class Orderline extends PosModel { orderline.discount = this.discount; orderline.price = this.price; orderline.selected = false; - orderline.price_manually_set = this.price_manually_set; - orderline.price_automatically_set = this.price_automatically_set; + orderline.price_type = this.price_type; orderline.customerNote = this.customerNote; return orderline; } @@ -2076,7 +2074,7 @@ export class Orderline extends PosModel { } // just like in sale.order changing the quantity will recompute the unit price - if (!keep_price && !(this.price_manually_set || this.price_automatically_set)) { + if (!keep_price && this.price_type === "original") { this.set_unit_price( this.product.get_price( this.order.pricelist, @@ -2232,8 +2230,7 @@ export class Orderline extends PosModel { price_extra: this.get_price_extra(), customer_note: this.get_customer_note(), refunded_orderline_id: this.refunded_orderline_id, - price_manually_set: this.price_manually_set, - price_automatically_set: this.price_automatically_set, + price_type: this.price_type, }; } //used to create a json of the ticket, to be sent to the printer @@ -2249,8 +2246,7 @@ export class Orderline extends PosModel { product_name_wrapped: this.generate_wrapped_product_name(), price_lst: this.get_taxed_lst_unit_price(), fixed_lst_price: this.get_fixed_lst_price(), - price_manually_set: this.price_manually_set, - price_automatically_set: this.price_automatically_set, + price_type: this.price_type, display_discount_policy: this.display_discount_policy(), price_display_one: this.get_display_price_one(), price_display: this.get_display_price(), @@ -3388,7 +3384,7 @@ export class Order extends PosModel { if (lines[i].get_product() === tip_product) { lines[i].set_unit_price(tip); lines[i].set_lst_price(tip); - lines[i].price_automatically_set = true; + lines[i].price_type = "automatic"; lines[i].order.tip_amount = tip; return; } @@ -3398,7 +3394,7 @@ export class Order extends PosModel { quantity: 1, price: tip, lst_price: tip, - extras: { price_automatically_set: true }, + extras: { price_type: "automatic" }, }); } } @@ -3410,7 +3406,7 @@ export class Order extends PosModel { this.pricelist = pricelist; var lines_to_recompute = this.get_orderlines().filter( - (line) => !(line.price_manually_set || line.price_automatically_set) + (line) => line.price_type === "original" ); lines_to_recompute.forEach((line) => { line.set_unit_price( diff --git a/addons/pos_discount/static/src/js/DiscountButton.js b/addons/pos_discount/static/src/js/DiscountButton.js index 4c5515a21c2..69feb1fdd8b 100644 --- a/addons/pos_discount/static/src/js/DiscountButton.js +++ b/addons/pos_discount/static/src/js/DiscountButton.js @@ -86,7 +86,7 @@ export class DiscountButton extends Component { ) : this.env._t("No tax")), extras: { - price_automatically_set: true, + price_type: "automatic", }, }); } diff --git a/addons/pos_loyalty/static/src/js/Loyalty.js b/addons/pos_loyalty/static/src/js/Loyalty.js index 9f845cb3557..0f4243fb369 100644 --- a/addons/pos_loyalty/static/src/js/Loyalty.js +++ b/addons/pos_loyalty/static/src/js/Loyalty.js @@ -516,7 +516,7 @@ patch(Order.prototype, "pos_loyalty.Order", { line.coupon_id = options.coupon_id; line.reward_identifier_code = options.reward_identifier_code; line.points_cost = options.points_cost; - line.price_automatically_set = true; + line.price_type = "automatic"; } line.giftBarcode = options.giftBarcode; line.giftCardId = options.giftCardId; diff --git a/addons/pos_sale/static/src/js/OrderManagementScreen/SaleOrderManagementScreen.js b/addons/pos_sale/static/src/js/OrderManagementScreen/SaleOrderManagementScreen.js index f583e1afa8d..a3ecd7fd03a 100644 --- a/addons/pos_sale/static/src/js/OrderManagementScreen/SaleOrderManagementScreen.js +++ b/addons/pos_sale/static/src/js/OrderManagementScreen/SaleOrderManagementScreen.js @@ -216,7 +216,7 @@ export class SaleOrderManagementScreen extends ControlButtonsMixin(Component) { description: line.name, price: line.price_unit, tax_ids: orderFiscalPos ? undefined : line.tax_id, - price_manually_set: true, + price_type: "manual", sale_order_origin_id: clickedOrder, sale_order_line_id: line, customer_note: line.customer_note, @@ -360,7 +360,7 @@ export class SaleOrderManagementScreen extends ControlButtonsMixin(Component) { order: globalState.get_order(), product: down_payment_product, price: down_payment, - price_automatically_set: true, + price_type: "automatic", sale_order_origin_id: clickedOrder, down_payment_details: tab, } diff --git a/addons/pos_self_order/controllers/ordering.py b/addons/pos_self_order/controllers/ordering.py index e7b22143adf..903fd58f571 100644 --- a/addons/pos_self_order/controllers/ordering.py +++ b/addons/pos_self_order/controllers/ordering.py @@ -299,7 +299,7 @@ class PosSelfOrderController(http.Controller): item.get("description"), ), "customer_note": item.get("customer_note"), - "price_manually_set": False, + "pricec_type": "original", "note": "", "uuid": str(uuid.uuid4()), }