Commit Graph

215 Commits

Author SHA1 Message Date
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
3e197e3adf feat(medusa): Add feature flags to store response (#1819)
**What**
- Add `feature_flags` string array to store response

**Why**
- to provide conditional ui in admin corresponding to enabled features

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-07-11 09:42:58 +00:00
Oliver Windall Juhl
02967f95b1 fix(medusa): Refresh adjustments when region on cart is changed (#1827)
* fix(medusa): Refresh adjustments when region on cart is changed

* fix test

* Fix unit test

* fix: integration tests

* fix: comment
2022-07-11 10:51:55 +02:00
Adrien de Peretti
2d03634cfc feat(medusa, medusa-js, medusa-react): Implement Sales Channel deletion (#1804) 2022-07-07 10:47:51 +02:00
Frane Polić
0d1624cf6a feat(medusa, medusa-js, medusa-react): Implement Sales Channel creation (#1795) 2022-07-06 22:18:05 +02: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
Philip Korsholm
413b2850bf feat(medusa): SC service (#1784)
* add sales channel service and empty api index

* add integration testing file

* add tyeps

* remove ts directive

* add sales channel test

* update import

* remove unused import

* fix tests
2022-07-05 14:40:10 +02:00
Philip Korsholm
41681b45b1 Feat(medusa): implement feature flags (#1768)
* feat: add feature flag loading in projects

* fix: make feature flag consume itself

* fix: rename container registration to featureFlagRouter

* fix: refactor

* behavioral feature flags

* add environment to server

* limit "useTemplateDb" to non feature flagged migrations

* filter migrations and entities according to those which are enabled in the environment

* run only migrations that are enabled when running 'medusa migrations run'

* add logging to the featureflag loader

* initial implementation of featureFlagEntity

* column descriptors

* initial startServerWithEnv (to be refactored)

* update commands

* final touches

* update loaders to fix unit tests

* enable all batch job tests

* update seed method

* add api test capabilities

* revert batch job test

* revert formatting changes

* pr feedback

* pr feedback

* remove unused imports

* rename feature flag decorators

* pr feedback

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
2022-07-04 15:39:30 +02:00
Adrien de Peretti
e53c06eab8 feat(medusa): Apply query transformers to Collection and CustomerGroups (#1667) 2022-07-02 13:01:52 +02:00
Sebastian Rindom
fee0f88a62 fix: add shipping taxes (#1759)
**What**
Adds taxes to the shipping prices when listing in admin. Allows store operators to see correct prices when processing returns.
2022-07-02 10:35:16 +00:00
Philip Korsholm
bf47d1aecd feat(medusa): Add batch strategy for order exports (#1603) 2022-06-29 09:54:37 +02:00
Adrien de Peretti
c0f624ad3b feat(medusa): Allow to filter the batch jobs with nullable date (#1747) 2022-06-29 09:44:56 +02:00
Adrien de Peretti
fb7abbf407 feat(medusa): Add file size calculation for product export (#1726) 2022-06-28 15:27:36 +02:00
Sebastian Rindom
c6dc9086cf feat(medusa): Add line item totals to cart totals decoration (#1740) 2022-06-28 12:11:47 +02:00
Sebastian Rindom
2a32609b74 fix(medusa): Normalizes email before saving customer (#1719) 2022-06-27 10:56:12 +02:00
Adrien de Peretti
89cb717461 fix(medusa): Product export strategy (#1713) 2022-06-27 10:48:56 +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
Zakaria El Asri
f0be31120f refactor(medusa): Migrate ProductService to TS (#1625)
* refactor: product service

* fix: type errors in consumers

* fix: use Status enum instead of ProductStatus

* fix: remove ProductStatus

* fix: rename ProductStatus

* fix: product model nullable fields

* fix: explicit typecasting in listVariants

* fix: use atomicPhase in public methods

* fix: use transactionManager in protected methods

* fix: remove disable eslint rule comment

* fix: retrieveVariants relations

* fix: retrieveVariants

* fix: FilterableProductProps validation

* fix: nullable thumbnail

* fix: tests by making model column types more explicit

* move upsert method to repo layer

* fix: unit tests

* fix: integration tests

* fix: product tags query + integration test

* fix: rename FindWithRelationsOptions to FindWithoutRelationsOptions

* fix (productRepository): use string[] for relations

* refactor: extract price relation filtering logic into util

* fix: failing unit test

* rename DTO suffix to Input suffix

* fix: missing awaits

* fix: check for images and tags length

* fix: remove unneeded function

* extract types used in product service to types folder

* fix: use text instead of varchar

* remove: reorderOptions from ProductService

* fix: product model

* fix: add private retrieve method

* fix: conflicts

* fix: failing unit test

* fix: integration test

* fix: remove ProductSelector type

* fix: remove validateId

* fix: use spread operator

* fix: repo method typings

* fix: remove comment
2022-06-20 10:50:46 +01:00
olivermrbl
c85ef984cc Merge branch 'master' into develop 2022-06-19 12:59:08 +02:00
Oliver Windall Juhl
6b23208d63 fix(medusa): Include adjustments when authorizing payment (#1697) 2022-06-19 12:58:47 +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
Sebastian Rindom
14366f536d fix: adds tax calculation to product pricing (#1354)
* fix: adds tax calculation to product pricing

* fix: dedupe

* fix: merge inconsistencies

* fix: merge inconsistencies
2022-06-14 10:11:18 +02:00
Adrien de Peretti
9a3ff32b42 refactor(medusa): Convert DraftOrderService to TS (#1259) 2022-06-13 20:29:23 +02:00
Zakaria El Asri
247ad6dc6d fix: includes variant prices when listing products using a search query (#1607)
* fix: return prices when lsiting products with a query

* add: integration test

* fix: integration test

* fix: move WithRequiredProperty to common.ts

* fix: comment
2022-06-05 21:52:31 +01:00
Philip Korsholm
3f23edea23 fix(medusa): Allow de-selecting configurations in price lists (#1596) 2022-05-30 19:34:34 +02:00
Kasper Fabricius Kristensen
083ab09361 fix(medusa): Prevent discount type updates (#1584) 2022-05-30 09:44:53 +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
Kasper Fabricius Kristensen
5414148254 fix(medusa): Post /admin/discounts/:id not updating condition operator (#1573) 2022-05-24 12:28:40 +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
f0ecef6b9a fix(medisa): Deleting price list should use remove (#1540) 2022-05-19 18:56:58 +02:00
Sebastian Rindom
f17e44d88a fix(medusa): join claim items on receive return (#1539) 2022-05-19 13:04:25 +02:00
Kasper Fabricius Kristensen
46d9e6c44c fix(medusa): add q param to listAndCount product types and product tags (#1531) 2022-05-18 11:31:02 +02:00
Kasper Fabricius Kristensen
5ae5f15e98 fix(medusa): RMA on items from swaps and claims (#1182) 2022-05-17 11:19:46 +02:00
Oliver Windall Juhl
a87e1cdf65 feat(medusa): Add endpoint for retrieving a DiscountCondition (#1525) 2022-05-17 11:17:17 +02:00
Adrien de Peretti
edeac8ac72 feat(medusa): Add /admin/products/:id/variants end point (#1471)
* feat(medusa): Add /admin/products/:id/variants end point

* test(medusa): Fix get-variants test casees

* feat(medusa): Include the config to the ProdutService#retrieveVariants as a method parameter

* feat(medusa): Improve get-variants endpoint

* feat(medusa): Improve get-variants endpoint

* test(medusa): Fix unit tests

* test(medusa): Fix unit tests

* feat(medusa): Improve typings

* feat(medusa): Update according to feedback

* feat(medusa): Update according to feedback

* test(medusa): Fix list-variants tests

* feat(medusa): Getting the variants from the product end point should use the productVariantService

* fix(medusa): list-variants expand possibly undefined

* Fix(medusa): List-variants endpoint

* fix(medusa): Tests suite for list-variant

* test(integration-tests): Fix yarn lock

* test(integration-tests): Fix yarn lock
2022-05-16 12:19:34 +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
Adrien de Peretti
0b2a3a0f0e Merge pull request #1475 from medusajs/fix-cartServiceCreateLostShippingAddress 2022-05-11 22:02:24 +02:00
Frane Polić
03c5617896 fix(medusa): allow price list prices update when region_id is provided (#1472) 2022-05-11 07:43:19 +02:00
Adrien de Peretti
65186036b5 Merge branch 'develop' into fix-cartServiceCreateLostShippingAddress 2022-05-10 11:16:19 +02:00
adrien2p
9b5354502f test(medusa): Fix test pipelines 2022-05-10 11:09:52 +02:00
Zakaria El Asri
f71b9b3a87 fix(medusa): support searching for price lists (#1407) 2022-05-08 18:45:18 +02:00
Kasper Fabricius Kristensen
e7cb76ab6e fix: Cascade remove prices + option values on variant and product delete (#1465) 2022-05-08 16:12:31 +02:00
Philip Korsholm
e2d08316dd fix: Use correct product price when fetching product for pricelist (#1416) 2022-05-08 13:03:29 +02:00
Philip Korsholm
f7386bf4b3 fix: Update is_giftcard type when filtering products (#1427)
* transform is_giftcard parameter and default to false

* add test for non gift_cards

* make default optional
2022-04-25 14:55:33 +02:00
Kasper Fabricius Kristensen
7a1e394b9d Feat/expand on list discounts (#1304) 2022-04-21 15:22:07 +02:00
Adrien de Peretti
530bbd4cac refactor: LineItemService migration to TS + refactoring + fix (#1254)
* refactor(medusa): LineItemService migration to TS + refactoring

* feat(medusa): Cleanup line-item service

* feat(medusa): Rebase develop

* test(medusa): Fix integration cart tests

* fix(medusa): Cart service updateUnitPrices
2022-04-14 20:53:35 +02:00
Adrien de Peretti
12c06b4c9d refactor(medusa): Cleanup and fix CartService (#1306)
* refactor(medusa): Cleanup + fix

* styles(medusa): Lint

* refactor(medusa): Finalize cleanup

* feat(medusa): Prefer the usage of bulk operations instead of sequential/conccurent operations

* feat(medusa): Improve cart service

* refactor(medusa): Explicitly specifying protected methods when needed as well as enfore the usage of the local transactionManager_ in those methods

* tests(medusa): Fix tests according to the new changes

* feat(medusa): Cleanup after rebase

* test(medusa): Fix cart service tests
2022-04-13 18:35:13 +02:00
Oliver Windall Juhl
edc6d9d29c fix: Remove region_id from countries on region deletes (#1330)
* Remove region id from countries on delete

* Update snapshots
2022-04-13 10:52:25 +02:00