Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculation of appropriate reference price #549

Closed
novoj opened this issue Apr 30, 2024 · 3 comments · Fixed by #595
Closed

Calculation of appropriate reference price #549

novoj opened this issue Apr 30, 2024 · 3 comments · Fixed by #595
Assignees
Labels
breaking change Backward incompatible data model change enhancement New feature or request
Milestone

Comments

@novoj
Copy link
Collaborator

novoj commented Apr 30, 2024

Consider following example:

{
  queryProduct(
    filterBy: {
      entityPrimaryKeyInSet: [
        103885
      ],
      priceInCurrency: EUR,
      priceInPriceLists: [
        "employee-basic-price",
        "basic"
      ]
    }
  ) {
    recordPage {
      data {
        primaryKey
        attributes {
          code
        }
        priceForSale {
          priceWithoutTax
          priceWithTax
          taxRate
        }
        referencePrice: price(priceList: "basic") {
          priceWithoutTax
          priceWithTax
          taxRate
        }
      }
    }
  }
}

We can only specify a single price in the referencePrice: price(priceList: "basic") part. The real use cases often work with multiple fallback price lists and need to consider the inner record handling logic of the price. So we want to extend support for the following declaration:

referencePrice: price(priceLists: ["reference", "basic_milagro_cz", basic"]) {
          priceWithoutTax
          priceWithTax
          taxRate
        }

which would take the first available price according to the passed sequence of price lists and use it as the result price for the field. The logic will also take into account the price inner record handling logic:

  • for LOWEST_PRICE it returns the first available price that has the same innerRecordId as the price for sale
  • for SUM, it returns the sum of the first available prices selected for each different innerRecordId that also has the sale price available.

This needs to be added to the EntityContract interface and opened both in GraphQL and consider propagating to the REST API as well (since this logic is hard to compute on the client side).

@novoj novoj added the enhancement New feature or request label Apr 30, 2024
@novoj novoj added this to the Beta milestone Apr 30, 2024
@novoj novoj self-assigned this Apr 30, 2024
novoj added a commit that referenced this issue May 13, 2024
This commit adds ability to calculate multiple prices respecting the price inner record handling logic and selected price for sale for visualization purposes.
@novoj
Copy link
Collaborator Author

novoj commented May 13, 2024

@lho the logic is prepared in method io.evitadb.api.requestResponse.data.PricesContract#getPriceForSaleWithAccompanyingPrices including basic tests. Please:

  • add the logic to GraphQL API
  • consider relevant support also in REST API
  • add tests
  • document usage in reference documentation (or transfer issue back to me after implementation on your side)

novoj added a commit that referenced this issue May 30, 2024
Reimplemented logic for calculation all prices for sale function to mimic the logic in price for sale function (the original logic was flawed). Added new method for calculating all prices for sale with accompanying prices.
@novoj novoj added the breaking change Backward incompatible data model change label May 30, 2024
@novoj
Copy link
Collaborator Author

novoj commented May 30, 2024

This issue changes behaviour of allPricesForSale and breaks backward compatibility for someone who relied on flawed implementation logic. Now the method mimics the calculation and behavior of priceForSale, which is more consistent.

@lukashornych
Copy link
Collaborator

@novoj the GQL support, tests and user documentation are done.

@lukashornych lukashornych linked a pull request Jun 3, 2024 that will close this issue
lukashornych added a commit that referenced this issue Jun 3, 2024
…-reference-price

feat(#549): calculation of appropriate reference price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Backward incompatible data model change enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants