Oliver Windall Juhl
5ac7f08e4d
fix(medusa): Incorrect swap difference due ( #2086 )
...
### What
Creating a swap on an order with a discount leads to an incorrect difference due.
**Scenario**
- Create a store with minimum 2 products (Prod A, Prod B)
- Create a discount that only works for Prod A
- Create an order for Prod A with the discount applied
- Create a swap between Prod A and Prod B
**Expected outcome**
We would expect the difference_due amount to come out to the sum of:
- -1 * (price of prod a - discount applied to prod a)
- price of prod b
**Actual outcome**
Instead the discount is applied across both products when calculating difference due. This results in a total that is instead the sum of:
- -1 * (price of prod a - discount applied to prod a)
- price of prod b - discount on prod b ignoring the condition
### How
Adds `line_item.adjustments` to relations in cart retrieval prior to setting the difference_due to car total
Fixes CORE-361
2022-08-24 14:07:44 +00:00
Adrien de Peretti
df66378535
feat(medusa): Attach or update cart sales channel ( #1873 )
...
What
Allow to create a cart with a sales channel, otherwise the default one is attached.
Also allow to update the sales channel on an existing cart and in that case the line items that does not belongs to the new sales channel attached are removed
How
Updating existing end points and service method to integrate the new requirements
Tests
Add new integration tests
Fixes CORE-270
Fixes CORE-272
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com >
2022-07-27 16:54:05 +00:00
Sebastian Rindom
8c283ac3b0
fix(medusa): Calculated price on cart shipping options ( #1878 )
2022-07-20 11:04:31 +02:00
Adrien de Peretti
110c995a6a
feat(medusa): Allow to query order/product by SC ( #1867 )
...
**What**
Allow to query the products and orders by sales channels
**How**
Updating the existing end points and repositories (if necessary) to take a new query params that is sales_channel_id as an array of string
**Tests**
Add new integration tests
Fixes CORE-295
Fixes CORE-288
2022-07-19 16:54:20 +00:00
Oliver Windall Juhl
4e375c2203
feat(medusa): Prevent default channel from being deleted ( #1835 )
...
**What**
Prevent the default channel from being deleted
Fixes CORE-317
2022-07-13 06:41:03 +00:00
Philip Korsholm
19f35ba6aa
Feat(medusa, medusa-js, medusa-react): Include sales channels in related queries as an optional expand parameter ( #1816 )
...
**What**
- Add `transformQuery` to get endpoints for product, order and cart
- ensure that the default relations (when getting a singular entity) includes sales channels when enabled
- Add `EmptyQueryParams` class in common types to prevent query parameters while using `transformQuery`
- update product-, order- and cartFactory to include sales channels if provided
- remove `packages/medusa/src/controllers/products/admin-list-products.ts`
**Testing**
- expands sales channel for single order
- expands sales channels for orders with expand parameter
- returns single product with sales channel
- expands sales channels for products with expand parameter
- returns cart with sales channel for single cart
Fixes CORE-293
Co-authored-by: Sebastian Rindom <7554214+srindom@users.noreply.github.com >
Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com >
2022-07-11 16:45:01 +00:00
Sebastian Rindom
39f2c0c15e
fix(medusa): calculates correct taxes and totals on order with gift cards ( #1807 )
...
**What**
Since the release of the Tax API the line item totals calculations on orders with gift cards have been wrong. To understand the bug consider the below order:
Region:
- tax_rate: 25%
- gift_cards_taxable: true
Order:
- applied gift card: 1000
- items:
- A: unit_price: 1000
- B: unit_price: 500
- Subtotal: 1500
**Previous calculation method**
1. Determine how much of the gift card is used for each item using `item_total / subtotal * gift_card_amount`:
- Item A: 1000/1500 * 1000 = 666.67
- Item B: 500/1500 * 1000 = 333.33
2. Calculate line item totals including taxes using `(unit_price - gift_card) * (1 + tax_rate)`
- Item A: 1000 - 666.67 = 333.33; vat amount -> 83.33
- Item B: 500 - 333.33 = 166.67; vat amount -> 41.67
3. Add up the line item totals: order subtotal = 500; vat amount = 125; total = 625
This is all correct at the totals level; but at the line item level we should still use the "original prices" i.e. the line item total for item a should be (1000 * 1.25) = 1250 with a tax amount of 250.
**New calculation method**
1. Use default totals calculations
- Item A: subtotal: 1000, tax_total: 250, total: 1250
- Item B: subtotal: 500, tax_total: 125, total: 625
2. Add up the line item totals: subtotal: 1500, tax_total: 375, total: 1875
3. Reduce total with gift card: subtotal: 1500 - 1000 = 500, tax_total: 375 - 250 = 125, total = 625
Totals can now be forwarded correctly to accounting plugins.
Fixes CORE-310.
2022-07-11 12:18:43 +00:00
Philip Korsholm
9d19cc0818
feat(medusa, medusa-js, medusa-react): Implement Sales Channel update ( #1797 )
2022-07-06 15:44:09 +02:00
Adrien de Peretti
263a661031
feat(medusa, medusa-js, medusa-react): Implement Sales Channel retrieval ( #1793 )
2022-07-06 12:17:26 +02:00
Sebastian Rindom
c6dc9086cf
feat(medusa): Add line item totals to cart totals decoration ( #1740 )
2022-06-28 12:11:47 +02:00
Adrien de Peretti
7b09b8c36c
feat(medusa/product-export-strategy): Implement the Product export strategy ( #1688 )
2022-06-22 23:42:31 +02:00
Adrien de Peretti
453688682c
feat(medusa): Support batch-job API ( #1547 )
...
* feat(medusa): Implement confirm batch job end point
* feat(medusa): Implement confirm batch-job end point
* feat(medusa): Add create batch job end point and implementation
* feat(medusa): remove cancelled related
* feat(medusa): Remove unrelated content for batch job creation
* feat(medusa): Cleanup migration
* feat(medusa): Cleanup context
* fix(medusa): Batch-job service import
* feat(medusa): Update migration
* test(medusa): Fix batch job tests
* feat(medusa): Start batch job end point
* feat(medusa): Continue end points
* feat(medusa): Continue end points
* feat(medusa): Finalize batch-job end points
* style(medusa): Lint
* feat(medusa): Cleanup
* feat(medusa): Fix list-batch-job endpoint column selection
* feat(medusa): Batch-job feedback
* feat(medusa): Update create-batch-job endpoint doc
* test(integration-tests): Fix batch-job integration reguarding the response status code
* feat(medusa): Finalize rebase from develop
* feat(medusa): Extend batch job status with ready_at and failed_at
* feat(medusa): Update migration and tests accordingly
* feat(medusa): Update status order on batchJob
* feat(medusa): Enhance batchJobService status update
* style(medusa): Cleanup
* style(medusa): Typo
* style(medusa): Remove unnecessary comment
* cleanup(medusa): Address feedback
* test(integration-tests): Update naming and snapshots
* fix(medusa): Update validator
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com >
* Fix(medusa): update validator
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com >
* test(intergration-tests): Fix creates batch job
* test(integration-tests): Fix snapshot
* feat(medusa): Re-work status
* tests(integration-tests): Fix batch job
* feat(medusa): Addresses feedback
* fix(medusa): Revert package.json script
* feat(medusa/batch-job-api): Improve status management
* feat(medusa): Improve batch job status and remove some context validation from the service
* feat(medusa): BatchJob api merge params
* feat(medusa): Apply last changes on the batch job service
* Update packages/medusa/src/services/batch-job.ts
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com >
* feat(medusa): BatchJobStrategy and loaders (#1434 )
* add batch job strategy interface
* update plugin loaders
* remove comment
* make map async
* ensure that only one of each strategy is registered
* register strategies plural
* add identifier and batchType properties
* extend batch job strategy identification method
* initial test
* update loaders to accomodate different ways of accessing batch job strategies
* identifier batch type field
* redo merge in plugins
* update interface and load only js files
* use switches instead of elif
* remove comments
* use static properties for strategy registration
* update tests
* fix unit tests
* update test names
* update isBatchJobStrategy method
* add check for TransactionBaseService in services for plugins
* update interfaces export
* update batchjob strategy interface with a prepare script
* update loaders
* update batchjob strategy interface
* remove everything but public interface methods from batchJobStrategy
* add default implementation to prepareBathJobForProcessing
* remove unused import
* docs: Add Services reference (#1548 )
* added events reference
* add upgrade guide for 1.3.0
* Update 1-3-0.md
* merge 1.3.0 with 1.3.1
* rename to 1.3.0
* added paypal documentation
* Improve storefront quickstart documents
* chore(deps): bump sqlite3 from 5.0.2 to 5.0.3 (#1453 )
Bumps [sqlite3](https://github.com/TryGhost/node-sqlite3 ) from 5.0.2 to 5.0.3.
- [Release notes](https://github.com/TryGhost/node-sqlite3/releases )
- [Changelog](https://github.com/TryGhost/node-sqlite3/blob/master/CHANGELOG.md )
- [Commits](https://github.com/TryGhost/node-sqlite3/compare/v5.0.2...v5.0.3 )
* fix: Issue with cache in CI pipeline
Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com >
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com >
Co-authored-by: Shahed Nasser <shahednasser@gmail.com >
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-16 13:57:18 +02:00
Adrien de Peretti
fa031fd28b
feat(medusa): Support deleting prices from a price list by product or variant ( #1555 )
2022-05-30 09:41:57 +02:00
Adrien de Peretti
4489b75f5a
feat(medusa): List batch jobs + Introduce composable handler pattern ( #1541 )
2022-05-20 10:22:42 +02:00
Oliver Windall Juhl
9ca45ea492
feat(medusa): Add endpoints specific to DiscountConditions ( #1355 )
2022-05-13 12:42:23 +02:00
Philip Korsholm
a69b52e031
Feat: Filter price lists by customer group ( #1431 )
...
* add customer groups to price list factory
* add integration test for filtering price lists by customer group
* normalize list price list query
* add customer groups to list-price-list queryparameters
* query based on customergroups if they exist for price lists
* remove verbose flag
* add another price list with a customer group
* remove console.log
* pr feedback
* add query type to repository
* add query type to repository
* set groups to undefined instead of deleting parameter
* remove wildcard destructing
* make buildQuery type specific to price lists
* steal Adriens types
* fix(medusa): support searching for price lists (#1407 )
* delete instead of settting groups to undefined
* add groups to query with q
* use simple customer group factory instead of manual creation
* Update simple-customer-group-factory.ts
* remove comma that breaks integration-tests
Co-authored-by: Zakaria El Asri <33696020+zakariaelas@users.noreply.github.com >
2022-05-12 04:22:46 +02:00
Philip Korsholm
e2d08316dd
fix: Use correct product price when fetching product for pricelist ( #1416 )
2022-05-08 13:03:29 +02:00
Adrien de Peretti
313cb0658b
feat(medusa): Improve config loading ( #1290 )
2022-04-21 12:49:56 +02:00
Zakaria El Asri
1cfeb5dbd8
feat: line item adjustments ( #1319 )
...
* add: crud services + model + totals
* fix: enforce unique constraint on line item adjustment model and update service (#1241 )
* add: unique constraint on model + fix service
* fix: unique constraint
* fix: add cascade on delete + fix discount relation
* fix: remove optional unique prop
* add: tests for ensuring line item adjustment db constraints (#1279 )
* add: tests for ensuring db constraints
* fix: use given when then
* feat: adjust cart to include line item adjustments (#1242 )
* fix: cart service + cart tests
* fix: remaining tests
* fix: swap tests
* fix: add relationship + fix oas
* refactor: applyDiscount
* fix: refactor applyDiscount and fix + add unit tests
* fix: plugins tests
* feat: line item adjustments draft orders (#1243 )
* fix: draft order tests
* fix: constraint
* fix: wrong variable name
* fix: unique constraint
* progress: add tests
* fix: add cascade on delete + fix discount relation
* fix: remove optional unique prop
* fix: cart removeLineItem + tests
* fix: cart unit tests
* fix: update snapshot
* remove: verbose option
* rename arg
Co-authored-by: Sebastian Rindom <skrindom@gmail.com >
* add: create adjustments for swap additional_items
* add: create adjustments for return lines
* fix: unit test for creating adjustment for additional_items
* fix: create adjustments only for non return items + no deletion when item is a return item
* add: integration tests
* refactor: use refreshAdjustments method
* refactor test
Co-authored-by: Sebastian Rindom <skrindom@gmail.com >
Co-authored-by: Sebastian Rindom <skrindom@gmail.com >
Co-authored-by: Sebastian Rindom <skrindom@gmail.com >
2022-04-12 15:49:31 +02:00
Sebastian Rindom
fb33dbaca3
feat: price list products ( #1239 )
...
* feat: add product list for price lists
* feat: add product list for price lists
* refactor: product list controller
* fix: add integration test for price list products
* fix: use getListConfig
2022-03-30 13:29:14 +02:00
Sebastian Rindom
e4af6b8f9c
chore: fix integration tests ( #1240 )
...
* chore: fix integration tests
* chore: fix integration tests
* fix: store tests
* fix: store tests
* fix: cleanup
2022-03-25 15:08:54 +01:00
Oliver Windall Juhl
a610805917
feat: Add DiscountConditions ( #1230 )
...
* feat: Add DiscountCondition entity + Join table per relation (#1146 )
* feat: Convert DiscountService to TypeScript (#1149 )
* feat: Add DiscountRepository + bulk insert and remove (#1156 )
* feat: Add `conditions` to payload in `POST /discounts` and `POST /discounts/:id` (#1170 )
* feat: Add DiscountRuleCondition entity
* fix relation
* fix join key
* Add discount rule condition repo
* add join table per relation
* Convert DiscountService to TypeScript
* feat: Add DiscountConditionRepository
* Add migration + remove use of valid_for
* revert changes to files, not done yet
* init work on create discount endpoint
* Add conditions to create discount endpoint
* Add conditions to update discount endpoint
* Add unique constraint to discount condition
* integration tests passing
* fix imports of models
* fix tests (excluding totals calculations)
* Fix commented code
* add unique constraint on discount condition
* Add generic way of generating retrieve configs
* Requested changes + ExactlyOne validator
* Remove isLocal flag from error handler
* Use postgres error constant
* remove commented code
* feat: Add `isValidForProduct` to check if Discount is valid for a given Product (#1172 )
* feat: Add `canApplyForCustomer` to check if Discount is valid for customer groups (#1212 )
* feat: Add `calculateDiscountForLineItem` (#1224 )
* feat: Adds discount condition test factory (#1228 )
* Remove use of valid_for
* Tests passing
* Remove valid_for form relations
* Add integration tests for applying discounts to cart
2022-03-24 16:47:50 +01:00
Sebastian Rindom
e3655b53f7
fix: storefront product filtering ( #1189 )
...
* fix: allow multiple ids in list + expand, fields param
* fix: add filtering by title
* fix: adds integration test
* fix: adds integration test of product variant filtering
* fix: integration tests
* fix: unit tests
* fix: refactor query param parsing
2022-03-17 23:28:15 +01:00
Sebastian Rindom
c56660fca9
feat: new tax api ( #979 )
...
* feat: add tax calculation strategy (#885 )
* feat: add tax calculation strategy
* fix: adds strategy loader
* fix: eslint ignore
* chore: cleanup
* fix: allow plugin overwrites
* fix: allow plugin overwrites
* fix: fake region
* Update packages/medusa/src/loaders/strategies.ts
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com >
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com >
* feat: adds tax related db entities + tax provider (#896 )
* feat: adds tax related db entities + tax provider
* fix: add tax provider tests
* fix: add tax service unit tests
* fix: tests + migrations
* fix: add inherited tax lines
* chore: rm tax-line repo
* fix: test
* fix: pr comments
* fix: unit test
* feat: totals service to ts (#911 )
* feat: adds tax related db entities + tax provider
* fix: add tax provider tests
* fix: add tax service unit tests
* fix: tests + migrations
* feat: totals service to ts
* fix: remove totals.js
* fix: add shipping methods
* fix: add inherited tax lines
* chore: rm tax-line repo
* fix: test
* fix: tests
* fix: tests
* fix: unit test
* fix: adds TotalsServiceProps
* feat: adds integration tests for automatic tax calculation + shipping tax rates (#945 )
* feat: adds tax related db entities + tax provider
* fix: add tax provider tests
* fix: add tax service unit tests
* fix: tests + migrations
* feat: totals service to ts
* fix: remove totals.js
* fix: add shipping methods
* fix: add inherited tax lines
* chore: rm tax-line repo
* fix: test
* fix: tests
* fix: tests
* fix: unit test
* fix: integration test helpers
* fix: adds factories + tests automatic tax rates
* fix: remove verbose
* fix: adds TotalsServiceProps
* fix: add shipping tax lines
* fix: add migration for shipping taxes
* fix: integration tests for shipping taxes
* fix: integration tests for shipping taxes
* fix: jsdoc types
* Feat/manual taxes (#950 )
* feat: adds tax related db entities + tax provider
* fix: add tax provider tests
* fix: add tax service unit tests
* fix: tests + migrations
* feat: totals service to ts
* fix: remove totals.js
* fix: add shipping methods
* fix: add inherited tax lines
* chore: rm tax-line repo
* fix: test
* fix: tests
* fix: tests
* fix: unit test
* fix: integration test helpers
* fix: adds factories + tests automatic tax rates
* fix: remove verbose
* fix: adds TotalsServiceProps
* fix: add shipping tax lines
* fix: add migration for shipping taxes
* fix: integration tests for shipping taxes
* fix: integration tests for shipping taxes
* fix: add integration tests for manual taxes
* fix: cart service - cleanup jsdoc
* feat: add /carts/id/taxes to manually calculate taxes
* feat: add integration tests for order tax calculations
* fix: unit tests
* fix: merge
* fix: rm verbose
* fix: unit tests
* fix: object -> cartOrOrder
* fix: rounding
* Feat/complete order w tax lines (#951 )
* feat: adds tax related db entities + tax provider
* fix: add tax provider tests
* fix: add tax service unit tests
* fix: tests + migrations
* feat: totals service to ts
* fix: remove totals.js
* fix: add shipping methods
* fix: add inherited tax lines
* chore: rm tax-line repo
* fix: test
* fix: tests
* fix: tests
* fix: unit test
* fix: integration test helpers
* fix: adds factories + tests automatic tax rates
* fix: remove verbose
* fix: adds TotalsServiceProps
* fix: add shipping tax lines
* fix: add migration for shipping taxes
* fix: integration tests for shipping taxes
* fix: integration tests for shipping taxes
* fix: add integration tests for manual taxes
* fix: cart service - cleanup jsdoc
* feat: add /carts/id/taxes to manually calculate taxes
* feat: add integration tests for order tax calculations
* feat: adds cart completion strategy + create order w. tax lines
* fix: unit tests
* fix: merge
* fix: rm verbose
* fix: unit tests
* fix: unit tests
* fix: unit tests
* fix: ensure calculation for list orders
* fix: unit tests
* fix: integration tests
* fix: adds cart order type gaurds
* Docs/tax api (#954 )
* feat: adds tax related db entities + tax provider
* fix: add tax provider tests
* fix: add tax service unit tests
* fix: tests + migrations
* feat: totals service to ts
* fix: remove totals.js
* fix: add shipping methods
* fix: add inherited tax lines
* chore: rm tax-line repo
* fix: test
* fix: tests
* fix: tests
* fix: unit test
* fix: integration test helpers
* fix: adds factories + tests automatic tax rates
* fix: remove verbose
* fix: adds TotalsServiceProps
* fix: add shipping tax lines
* fix: add migration for shipping taxes
* fix: integration tests for shipping taxes
* fix: integration tests for shipping taxes
* fix: add integration tests for manual taxes
* fix: cart service - cleanup jsdoc
* feat: add /carts/id/taxes to manually calculate taxes
* feat: add integration tests for order tax calculations
* feat: adds cart completion strategy + create order w. tax lines
* fix: unit tests
* fix: merge
* fix: rm verbose
* fix: unit tests
* fix: unit tests
* fix: unit tests
* fix: ensure calculation for list orders
* fix: unit tests
* fix: integration tests
* docs: documents tax related methods and types
* fix: require either item_id or shipping_method_id
* feat: product type tax rate (#969 )
* feat: adds tax related db entities + tax provider
* fix: add tax provider tests
* fix: add tax service unit tests
* fix: tests + migrations
* feat: totals service to ts
* fix: remove totals.js
* fix: add shipping methods
* fix: add inherited tax lines
* chore: rm tax-line repo
* fix: test
* fix: tests
* fix: tests
* fix: unit test
* fix: integration test helpers
* fix: adds factories + tests automatic tax rates
* fix: remove verbose
* fix: adds TotalsServiceProps
* fix: add shipping tax lines
* fix: add migration for shipping taxes
* fix: integration tests for shipping taxes
* fix: integration tests for shipping taxes
* fix: add integration tests for manual taxes
* fix: cart service - cleanup jsdoc
* feat: add /carts/id/taxes to manually calculate taxes
* feat: add integration tests for order tax calculations
* feat: adds cart completion strategy + create order w. tax lines
* fix: unit tests
* fix: merge
* fix: rm verbose
* fix: unit tests
* fix: unit tests
* fix: unit tests
* fix: ensure calculation for list orders
* fix: unit tests
* fix: integration tests
* docs: documents tax related methods and types
* fix: require either item_id or shipping_method_id
* feat: adds returns tests for new tax system
* feat: adds return lines + integration tests for swaps
* feat: return integration tests
* feat: adds product type tax rates
* feat: add tax management endpoints
* fix: create single migration
* fix: adds tax rates to js client
* fix: strats
* Fix/plugin tests (#998 )
* plugin testing setup
* fix: test sendgrid plugin
* fix: test sendgrid plugin
* chore: clean
* chore: clean
* fix: clean up tests
* fix: remove dirty import
* fix: sendgrid + brightpearl
* fix: plugin integration tests
* fix: klarna
* fix: shipping method tax
* fix: remove taxrates
* fix: unit tests
* fix: integration
* fix: integration
* fix: plugins tests
* fix: ignore plugins
* fix: tests
* fix: taxes (#1017 )
* fix: taxes
* fix: taxes
* fix: faulty ref
* fix: create tax-lines with claim items
* fix: snapshot tax-liens
* fix: allows integration test teardown to force deleting tables
* fix: tests
* fix: merge
* fix: adds tax-rates to client
* fix: adds tax-rates to medusa-react
* fix: tests
* fix: tests
* fix: add product types
* fix: adds tax provider endpoint + cascaded deletes on tax rate relations
* fix: move errors to service layer
* fix: cleanup api
* fix: unit tests
* fix: error handler in base-service
* fix: Add order region to swap on createFulfillment (#1110 )
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com >
2022-02-24 20:14:09 +01:00