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",
|
||||
"medusa-core-utils": "^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 { BaseService } from "medusa-interfaces"
|
||||
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 {
|
||||
/**
|
||||
@@ -16,7 +17,6 @@ class EconomicService extends BaseService {
|
||||
* customer_number_world: 678,
|
||||
* unit_number: 42,
|
||||
* payment_terms_number: 42,
|
||||
* shipping_product_number: 42,
|
||||
* layout_number: 42,
|
||||
* vatzone_number_eu: 42,
|
||||
* vatzone_number_dk: 42,
|
||||
@@ -45,30 +45,25 @@ class EconomicService extends BaseService {
|
||||
})
|
||||
}
|
||||
|
||||
decideCustomerAndVatNumber_(country) {
|
||||
// Add these to utils
|
||||
const EUCountries = []
|
||||
const WorldCountries = []
|
||||
decideCustomerAndVatNumber_(country_code) {
|
||||
const upperCased = country_code.toUpperCase()
|
||||
if (EUCountries.includes(upperCased)) {
|
||||
return {
|
||||
vat: this.options_.vatzone_number_eu,
|
||||
customer: this.options_.customer_number_eu,
|
||||
}
|
||||
}
|
||||
|
||||
const flag = false
|
||||
switch (flag) {
|
||||
case EUCountries.includes(country): {
|
||||
return {
|
||||
vat: this.options_.vatzone_number_eu,
|
||||
customer: this.options_.customer_number_eu,
|
||||
}
|
||||
if (upperCased === "DK") {
|
||||
return {
|
||||
vat: this.options_.vatzone_number_dk,
|
||||
customer: this.options_.customer_number_dk,
|
||||
}
|
||||
case WorldCountries.includes(country): {
|
||||
return {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
vat: this.options_.vatzone_number_world,
|
||||
customer: this.options_.customer_number_world,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,10 +75,13 @@ class EconomicService extends BaseService {
|
||||
)
|
||||
// If the discount has an item specific allocation method,
|
||||
// we need to fetch the discount for each item
|
||||
const itemDiscounts = await this.totalsService_.getAllocationItemDiscounts(
|
||||
discount,
|
||||
order
|
||||
)
|
||||
let itemDiscounts = []
|
||||
if (discount) {
|
||||
itemDiscounts = await this.totalsService_.getAllocationItemDiscounts(
|
||||
discount,
|
||||
order
|
||||
)
|
||||
}
|
||||
|
||||
order.items.forEach((item) => {
|
||||
// For bundles, we create an order line for each item in the bundle
|
||||
@@ -136,13 +134,12 @@ class EconomicService extends BaseService {
|
||||
|
||||
async createInvoiceFromOrder(order) {
|
||||
// Fetch currency code from order region
|
||||
const {
|
||||
currency_code,
|
||||
billing_address,
|
||||
} = await this.regionService_.retrieve(order.region_id)
|
||||
const { currency_code } = await this.regionService_.retrieve(
|
||||
order.region_id
|
||||
)
|
||||
|
||||
const vatZoneAndCustomer = this.decideCustomerAndVatNumber_(
|
||||
billing_address.country
|
||||
order.billing_address.country_code
|
||||
)
|
||||
|
||||
const lines = await this.createEconomicLinesFromOrder(order)
|
||||
@@ -175,7 +172,6 @@ class EconomicService extends BaseService {
|
||||
async draftEconomicInvoice(orderId) {
|
||||
const order = await this.orderService_.retrieve(orderId)
|
||||
const invoice = await this.createInvoiceFromOrder(order)
|
||||
|
||||
try {
|
||||
const draftInvoice = await this.economic_.post(
|
||||
`${ECONOMIC_BASE_URL}/invoices/drafts`,
|
||||
@@ -185,7 +181,7 @@ class EconomicService extends BaseService {
|
||||
await this.orderService_.setMetadata(
|
||||
order._id,
|
||||
"economicDraftId",
|
||||
draftInvoice.draftInvoiceNumber
|
||||
draftInvoice.data.draftInvoiceNumber
|
||||
)
|
||||
|
||||
const invoiceOrder = await this.orderService_.retrieve(order._id)
|
||||
@@ -198,7 +194,7 @@ class EconomicService extends BaseService {
|
||||
async bookEconomicInvoice(orderId) {
|
||||
try {
|
||||
const order = await this.orderService_.retrieve(orderId)
|
||||
const { economicDraftId } = order.setMetadata
|
||||
const { economicDraftId } = order.metadata
|
||||
|
||||
if (!economicDraftId) {
|
||||
throw new MedusaError(
|
||||
|
||||
30
packages/medusa-plugin-economic/src/utils/eu-countries.js
Normal file
30
packages/medusa-plugin-economic/src/utils/eu-countries.js
Normal file
@@ -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",
|
||||
]
|
||||
8
packages/medusa-plugin-economic/utils/eu-countries.js
Normal file
8
packages/medusa-plugin-economic/utils/eu-countries.js
Normal file
@@ -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;
|
||||
5588
packages/medusa-plugin-economic/yarn.lock
Normal file
5588
packages/medusa-plugin-economic/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@@ -32,7 +32,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"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",
|
||||
"build": "babel src -d dist",
|
||||
"serve": "node dist/app.js",
|
||||
@@ -70,4 +70,4 @@
|
||||
"winston": "^3.2.1"
|
||||
},
|
||||
"gitHead": "35e0930650d5f4aedf2610749cd131ae8b7e17cc"
|
||||
}
|
||||
}
|
||||
@@ -230,7 +230,6 @@ class OrderService extends BaseService {
|
||||
return this.retrieve(order._id)
|
||||
})
|
||||
.catch(error => {
|
||||
console.log(error)
|
||||
throw error
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user