Merge branch 'integration/dummy-project' of github.com:medusajs/medusa into integration/dummy-project
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"medusa-core-utils": "^0.3.0",
|
"medusa-core-utils": "^0.3.0",
|
||||||
"medusa-interfaces": "^0.3.0",
|
"medusa-interfaces": "^0.3.0",
|
||||||
"medusa-test-utils": "^0.3.0"
|
"medusa-test-utils": "^0.3.0",
|
||||||
|
"moment": "^2.27.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import axios from "axios"
|
|||||||
import moment from "moment"
|
import moment from "moment"
|
||||||
import { BaseService } from "medusa-interfaces"
|
import { BaseService } from "medusa-interfaces"
|
||||||
import { MedusaError } from "medusa-core-utils"
|
import { MedusaError } from "medusa-core-utils"
|
||||||
|
import EUCountries from "../utils/eu-countries"
|
||||||
|
|
||||||
ECONOMIC_BASE_URL = "https://restapi.e-conomic.com"
|
const ECONOMIC_BASE_URL = "https://restapi.e-conomic.com"
|
||||||
|
|
||||||
class EconomicService extends BaseService {
|
class EconomicService extends BaseService {
|
||||||
/**
|
/**
|
||||||
@@ -16,7 +17,6 @@ class EconomicService extends BaseService {
|
|||||||
* customer_number_world: 678,
|
* customer_number_world: 678,
|
||||||
* unit_number: 42,
|
* unit_number: 42,
|
||||||
* payment_terms_number: 42,
|
* payment_terms_number: 42,
|
||||||
* shipping_product_number: 42,
|
|
||||||
* layout_number: 42,
|
* layout_number: 42,
|
||||||
* vatzone_number_eu: 42,
|
* vatzone_number_eu: 42,
|
||||||
* vatzone_number_dk: 42,
|
* vatzone_number_dk: 42,
|
||||||
@@ -45,30 +45,25 @@ class EconomicService extends BaseService {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
decideCustomerAndVatNumber_(country) {
|
decideCustomerAndVatNumber_(country_code) {
|
||||||
// Add these to utils
|
const upperCased = country_code.toUpperCase()
|
||||||
const EUCountries = []
|
if (EUCountries.includes(upperCased)) {
|
||||||
const WorldCountries = []
|
return {
|
||||||
|
vat: this.options_.vatzone_number_eu,
|
||||||
|
customer: this.options_.customer_number_eu,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const flag = false
|
if (upperCased === "DK") {
|
||||||
switch (flag) {
|
return {
|
||||||
case EUCountries.includes(country): {
|
vat: this.options_.vatzone_number_dk,
|
||||||
return {
|
customer: this.options_.customer_number_dk,
|
||||||
vat: this.options_.vatzone_number_eu,
|
|
||||||
customer: this.options_.customer_number_eu,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case WorldCountries.includes(country): {
|
}
|
||||||
return {
|
|
||||||
vat: this.options_.vatzone_number_world,
|
return {
|
||||||
customer: this.options_.customer_number_world,
|
vat: this.options_.vatzone_number_world,
|
||||||
}
|
customer: this.options_.customer_number_world,
|
||||||
}
|
|
||||||
default:
|
|
||||||
return {
|
|
||||||
vat: this.options_.vatzone_number_dk,
|
|
||||||
customer: this.options_.customer_number_dk,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,10 +75,13 @@ class EconomicService extends BaseService {
|
|||||||
)
|
)
|
||||||
// If the discount has an item specific allocation method,
|
// If the discount has an item specific allocation method,
|
||||||
// we need to fetch the discount for each item
|
// we need to fetch the discount for each item
|
||||||
const itemDiscounts = await this.totalsService_.getAllocationItemDiscounts(
|
let itemDiscounts = []
|
||||||
discount,
|
if (discount) {
|
||||||
order
|
itemDiscounts = await this.totalsService_.getAllocationItemDiscounts(
|
||||||
)
|
discount,
|
||||||
|
order
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
order.items.forEach((item) => {
|
order.items.forEach((item) => {
|
||||||
// For bundles, we create an order line for each item in the bundle
|
// For bundles, we create an order line for each item in the bundle
|
||||||
@@ -136,13 +134,12 @@ class EconomicService extends BaseService {
|
|||||||
|
|
||||||
async createInvoiceFromOrder(order) {
|
async createInvoiceFromOrder(order) {
|
||||||
// Fetch currency code from order region
|
// Fetch currency code from order region
|
||||||
const {
|
const { currency_code } = await this.regionService_.retrieve(
|
||||||
currency_code,
|
order.region_id
|
||||||
billing_address,
|
)
|
||||||
} = await this.regionService_.retrieve(order.region_id)
|
|
||||||
|
|
||||||
const vatZoneAndCustomer = this.decideCustomerAndVatNumber_(
|
const vatZoneAndCustomer = this.decideCustomerAndVatNumber_(
|
||||||
billing_address.country
|
order.billing_address.country_code
|
||||||
)
|
)
|
||||||
|
|
||||||
const lines = await this.createEconomicLinesFromOrder(order)
|
const lines = await this.createEconomicLinesFromOrder(order)
|
||||||
@@ -175,7 +172,6 @@ class EconomicService extends BaseService {
|
|||||||
async draftEconomicInvoice(orderId) {
|
async draftEconomicInvoice(orderId) {
|
||||||
const order = await this.orderService_.retrieve(orderId)
|
const order = await this.orderService_.retrieve(orderId)
|
||||||
const invoice = await this.createInvoiceFromOrder(order)
|
const invoice = await this.createInvoiceFromOrder(order)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const draftInvoice = await this.economic_.post(
|
const draftInvoice = await this.economic_.post(
|
||||||
`${ECONOMIC_BASE_URL}/invoices/drafts`,
|
`${ECONOMIC_BASE_URL}/invoices/drafts`,
|
||||||
@@ -185,7 +181,7 @@ class EconomicService extends BaseService {
|
|||||||
await this.orderService_.setMetadata(
|
await this.orderService_.setMetadata(
|
||||||
order._id,
|
order._id,
|
||||||
"economicDraftId",
|
"economicDraftId",
|
||||||
draftInvoice.draftInvoiceNumber
|
draftInvoice.data.draftInvoiceNumber
|
||||||
)
|
)
|
||||||
|
|
||||||
const invoiceOrder = await this.orderService_.retrieve(order._id)
|
const invoiceOrder = await this.orderService_.retrieve(order._id)
|
||||||
@@ -198,7 +194,7 @@ class EconomicService extends BaseService {
|
|||||||
async bookEconomicInvoice(orderId) {
|
async bookEconomicInvoice(orderId) {
|
||||||
try {
|
try {
|
||||||
const order = await this.orderService_.retrieve(orderId)
|
const order = await this.orderService_.retrieve(orderId)
|
||||||
const { economicDraftId } = order.setMetadata
|
const { economicDraftId } = order.metadata
|
||||||
|
|
||||||
if (!economicDraftId) {
|
if (!economicDraftId) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
export default [
|
||||||
|
"BE",
|
||||||
|
"BG",
|
||||||
|
"CZ",
|
||||||
|
"DK",
|
||||||
|
"DE",
|
||||||
|
"EE",
|
||||||
|
"IE",
|
||||||
|
"EL",
|
||||||
|
"ES",
|
||||||
|
"FR",
|
||||||
|
"HR",
|
||||||
|
"IT",
|
||||||
|
"CY",
|
||||||
|
"LV",
|
||||||
|
"LT",
|
||||||
|
"LU",
|
||||||
|
"HU",
|
||||||
|
"MT",
|
||||||
|
"NL",
|
||||||
|
"AT",
|
||||||
|
"PL",
|
||||||
|
"PT",
|
||||||
|
"RO",
|
||||||
|
"SI",
|
||||||
|
"SK",
|
||||||
|
"FI",
|
||||||
|
"SE",
|
||||||
|
"UK",
|
||||||
|
]
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports["default"] = void 0;
|
||||||
|
var _default = ["BE", "BG", "CZ", "DK", "DE", "EE", "IE", "EL", "ES", "FR", "HR", "IT", "CY", "LV", "LT", "LU", "HU", "MT", "NL", "AT", "PL", "PT", "RO", "SI", "SK", "FI", "SE", "UK"];
|
||||||
|
exports["default"] = _default;
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -32,7 +32,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "nodemon --watch plugins/ --watch src/ --exec babel-node src/app.js",
|
"start": "nodemon --watch plugins/ --watch src/ --exec babel-node src/app.js",
|
||||||
"watch": "babel -w src --out-dir dist --ignore **/__tests__",
|
"watch": "babel -w src --out-dir dist/ --ignore **/__tests__",
|
||||||
"prepare": "cross-env NODE_ENV=production npm run build",
|
"prepare": "cross-env NODE_ENV=production npm run build",
|
||||||
"build": "babel src -d dist",
|
"build": "babel src -d dist",
|
||||||
"serve": "node dist/app.js",
|
"serve": "node dist/app.js",
|
||||||
|
|||||||
@@ -230,7 +230,6 @@ class OrderService extends BaseService {
|
|||||||
return this.retrieve(order._id)
|
return this.retrieve(order._id)
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log(error)
|
|
||||||
throw error
|
throw error
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user