fix: infer MA currency on PL create (#2232)

**What**
- a MoneyAmount record can be created with either providing region or currency. MA records cannot be inserted in the DB without currency due to not null constraints therefore the currency needs to be inferred from provided region

**How**
- by using the same utility that fixes this issue on PL update

**Testing**
- extend the "create PL" integration test to handle a MA with a region

---

FIXES CORE-525
This commit is contained in:
Frane Polić authored and GitHub committed 2022-09-19 18:30:31 +00:00
1 parent e1fe5ed094
commit de85a971c6
3 files changed
+33 -10

No files matched your search

@@ -44,6 +44,7 @@ describe("PriceListService", () => {
priceListRepository,
moneyAmountRepository,
featureFlagRouter: new FlagRouter({}),
regionService: RegionServiceMock,
})
beforeEach(async () => {
@@ -129,7 +130,8 @@ describe("PriceListService", () => {
updateRelatedMoneyAmountRepository.save = jest
.fn()
.mockImplementation(() => Promise.resolve())
updateRelatedMoneyAmountRepository.updatePriceListPrices = new MoneyAmountRepository().updatePriceListPrices
updateRelatedMoneyAmountRepository.updatePriceListPrices =
new MoneyAmountRepository().updatePriceListPrices
const updateRelatedPriceListService = new PriceListService({
manager: MockManager,
+5 -2
View File
@@ -140,7 +140,8 @@ class PriceListService extends TransactionBaseService {
const priceList = await priceListRepo.save(entity)
if (prices) {
await moneyAmountRepo.addPriceListPrices(priceList.id, prices)
const prices_ = await this.addCurrencyFromRegion(prices)
await moneyAmountRepo.addPriceListPrices(priceList.id, prices_)
}
if (customer_groups) {
@@ -507,7 +508,9 @@ class PriceListService extends TransactionBaseService {
const prices_: typeof prices = []
const regionServiceTx = this.regionService_.withTransaction(this.manager_)
for (const p of prices) {
for (const price of prices) {
const p = { ...price }
if (p.region_id) {
const region = await regionServiceTx.retrieve(p.region_id)