chore: add compare_at_unit_price when price list price is retrieved (#9564)
* chore: add compare_at_unit_price when price list price is retrieved * chore: add test for update item + more fixes along the way * chore: fix tests * chore: add refresh spec * Apply suggestions from code review Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com> * chore: use undefined checker * chore: switch to map --------- Co-authored-by: Adrien de Peretti <adrien.deperetti@gmail.com>
This commit is contained in:
@@ -10,6 +10,7 @@ describe("Order Exchange - Actions", function () {
|
||||
id: "1",
|
||||
quantity: 1,
|
||||
unit_price: 10,
|
||||
compare_at_unit_price: null,
|
||||
order_id: "1",
|
||||
|
||||
detail: {
|
||||
@@ -28,6 +29,7 @@ describe("Order Exchange - Actions", function () {
|
||||
id: "2",
|
||||
quantity: 2,
|
||||
unit_price: 100,
|
||||
compare_at_unit_price: null,
|
||||
order_id: "1",
|
||||
|
||||
detail: {
|
||||
@@ -46,6 +48,7 @@ describe("Order Exchange - Actions", function () {
|
||||
id: "3",
|
||||
quantity: 3,
|
||||
unit_price: 20,
|
||||
compare_at_unit_price: null,
|
||||
order_id: "1",
|
||||
|
||||
detail: {
|
||||
@@ -127,6 +130,7 @@ describe("Order Exchange - Actions", function () {
|
||||
order_id: "1",
|
||||
quantity: 1,
|
||||
unit_price: 10,
|
||||
compare_at_unit_price: null,
|
||||
detail: {
|
||||
quantity: 1,
|
||||
order_id: "1",
|
||||
@@ -144,6 +148,7 @@ describe("Order Exchange - Actions", function () {
|
||||
order_id: "1",
|
||||
quantity: 2,
|
||||
unit_price: 100,
|
||||
compare_at_unit_price: null,
|
||||
detail: {
|
||||
quantity: 2,
|
||||
order_id: "1",
|
||||
@@ -161,6 +166,7 @@ describe("Order Exchange - Actions", function () {
|
||||
order_id: "1",
|
||||
quantity: 3,
|
||||
unit_price: 20,
|
||||
compare_at_unit_price: null,
|
||||
detail: {
|
||||
quantity: 3,
|
||||
order_id: "1",
|
||||
|
||||
@@ -10,6 +10,7 @@ describe("Order Return - Actions", function () {
|
||||
id: "1",
|
||||
quantity: 1,
|
||||
unit_price: 10,
|
||||
compare_at_unit_price: null,
|
||||
order_id: "1",
|
||||
|
||||
detail: {
|
||||
@@ -28,6 +29,7 @@ describe("Order Return - Actions", function () {
|
||||
id: "2",
|
||||
quantity: 2,
|
||||
unit_price: 100,
|
||||
compare_at_unit_price: null,
|
||||
order_id: "1",
|
||||
|
||||
detail: {
|
||||
@@ -46,6 +48,7 @@ describe("Order Return - Actions", function () {
|
||||
id: "3",
|
||||
quantity: 3,
|
||||
unit_price: 20,
|
||||
compare_at_unit_price: null,
|
||||
order_id: "1",
|
||||
|
||||
detail: {
|
||||
@@ -144,6 +147,7 @@ describe("Order Return - Actions", function () {
|
||||
order_id: "1",
|
||||
quantity: 1,
|
||||
unit_price: 10,
|
||||
compare_at_unit_price: null,
|
||||
detail: {
|
||||
order_id: "1",
|
||||
quantity: 1,
|
||||
@@ -161,6 +165,7 @@ describe("Order Return - Actions", function () {
|
||||
order_id: "1",
|
||||
quantity: 2,
|
||||
unit_price: 100,
|
||||
compare_at_unit_price: null,
|
||||
detail: {
|
||||
order_id: "1",
|
||||
quantity: 2,
|
||||
@@ -178,6 +183,7 @@ describe("Order Return - Actions", function () {
|
||||
order_id: "1",
|
||||
quantity: 3,
|
||||
unit_price: 20,
|
||||
compare_at_unit_price: null,
|
||||
detail: {
|
||||
quantity: 3,
|
||||
order_id: "1",
|
||||
@@ -284,6 +290,7 @@ describe("Order Return - Actions", function () {
|
||||
order_id: "1",
|
||||
quantity: 1,
|
||||
unit_price: 10,
|
||||
compare_at_unit_price: null,
|
||||
detail: {
|
||||
quantity: 1,
|
||||
order_id: "1",
|
||||
@@ -301,6 +308,7 @@ describe("Order Return - Actions", function () {
|
||||
order_id: "1",
|
||||
quantity: 2,
|
||||
unit_price: 100,
|
||||
compare_at_unit_price: null,
|
||||
detail: {
|
||||
quantity: 2,
|
||||
order_id: "1",
|
||||
@@ -318,6 +326,7 @@ describe("Order Return - Actions", function () {
|
||||
order_id: "1",
|
||||
quantity: 3,
|
||||
unit_price: 20,
|
||||
compare_at_unit_price: null,
|
||||
detail: {
|
||||
quantity: 3,
|
||||
order_id: "1",
|
||||
|
||||
@@ -1994,7 +1994,10 @@ export default class OrderModuleService<
|
||||
if (!isExistingItem) {
|
||||
addedItems[item.id] = {
|
||||
...item,
|
||||
unit_price: item.detail?.unit_price ?? item.unit_price,
|
||||
quantity: item.detail?.quantity ?? item.quantity,
|
||||
unit_price: item.detail?.unit_price || item.unit_price,
|
||||
compare_at_unit_price:
|
||||
item.detail?.compare_at_unit_price || item.compare_at_unit_price,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2026,13 +2029,15 @@ export default class OrderModuleService<
|
||||
|
||||
const newItem = itemsToUpsert.find((d) => d.item_id === item.id)!
|
||||
const unitPrice = newItem?.unit_price ?? item.unit_price
|
||||
const compareAtUnitPrice =
|
||||
newItem?.compare_at_unit_price ?? item.compare_at_unit_price
|
||||
|
||||
calculated.order.items[idx] = {
|
||||
...lineItem,
|
||||
actions,
|
||||
quantity: newItem.quantity,
|
||||
unit_price: unitPrice,
|
||||
raw_unit_price: new BigNumber(unitPrice),
|
||||
compare_at_unit_price: compareAtUnitPrice,
|
||||
detail: {
|
||||
...newItem,
|
||||
...item,
|
||||
|
||||
Reference in New Issue
Block a user