[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) <rhe@odoo.com>
This commit is contained in:
vlst
2023-06-14 10:53:57 +02:00
parent 280f3de900
commit e82f75d66f
9 changed files with 20 additions and 24 deletions
@@ -11,7 +11,7 @@
<t t-name="l10n_fr_pos_cert.OrderLinesReceipt" t-inherit="point_of_sale.OrderLinesReceipt" t-inherit-mode="extension" owl="1">
<xpath expr="//t[@t-foreach='receipt.orderlines']" position="inside">
<t t-if="receipt.l10n_fr_hash !== false and line.price_manually_set">
<t t-if="receipt.l10n_fr_hash !== false and line.price_type === 'manual'">
<div class="pos-receipt-right-padding">
Old unit price:
<span class="oldPrice">
@@ -3,7 +3,7 @@
<t t-name="l10n_fr_pos_cert.Orderline" t-inherit="point_of_sale.Orderline" t-inherit-mode="extension" owl="1">
<xpath expr="//ul[hasclass('info-list')]" position="inside">
<t t-if="pos.globalState.is_french_country() !== false and props.line.price_manually_set">
<t t-if="pos.globalState.is_french_country() !== false and props.line.price_type === 'manual'">
<li class="info">
Old unit price:
<span class="oldPrice">
@@ -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') {
@@ -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,
@@ -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(
@@ -86,7 +86,7 @@ export class DiscountButton extends Component {
)
: this.env._t("No tax")),
extras: {
price_automatically_set: true,
price_type: "automatic",
},
});
}
+1 -1
View File
@@ -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;
@@ -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,
}
@@ -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()),
}