You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create StockTransfer Module. The goal is to allow to transfer stock quantity of an inventoryItem from one stock location to the another.I want to track the quantity transfered, the stock location that the stock was moved from, the stock location that the quantity was moved to and the product variant involved. To do this I
Define StockTransfer model with columns of id and qty
Then I proceed to create link from StockTransfer to StockLocation
This is the link definition. This is to track the stock location where we are decrementing the quantity.
Then another link definition from StockTransfer model to StockLocation model. The purpose of the link definition is to track the new quantity to be added to the new stock location. Below is the link definition
Then finally the linking between the StockTransfer model and ProductVariant model.
// link from vendor stock to product variantimportVendorModulefrom"src/modules/vendor";import{defineLink}from"@medusajs/framework/utils";importProductModulefrom"@medusajs/medusa/product";exportdefaultdefineLink(VendorModule.linkable.vendorStock,ProductModule.linkable.productVariant);
Now when I run npx medusa db:generate to create the links, I run into the error below Error initializing link modules. Error: Link module VendorStockTransferStockLocationStockLocationLink already defined.
This means that its not possible to create 2 links from one model to another core model.
I can implement this using the following using the model below
Hi @kowalski21,
currently we do not support the same link definition between two modules using the exact same keys.
I believe in your case you can have a single link with extra fields: to, from, and qty to track everything.
The main stock_transfer_id + stock_location_id is the starting point, and to/from is the destination.
Package.json file
Node.js version
v20.15.0
Database and its version
PostgreSQL 16.2
Operating system name and version
MacOS Sequioa Version 15.2
Browser name
Google Chrome
What happended?
StockTransfer
model with columns ofid
andqty
StockTransfer
toStockLocation
This is the link definition. This is to track the stock location where we are decrementing the quantity.
Then another link definition from
StockTransfer
model toStockLocation
model. The purpose of the link definition is to track the new quantity to be added to the new stock location. Below is the link definitionThen finally the linking between the
StockTransfer
model andProductVariant
model.Now when I run
npx medusa db:generate
to create the links, I run into the error belowError initializing link modules. Error: Link module VendorStockTransferStockLocationStockLocationLink already defined.
This means that its not possible to create 2 links from one model to another core model.
I can implement this using the following using the model below
Then create joins using the
"__pg_connection__"
module but it goes againstthe philosophy of each module being independent on its own.
Expected behavior
There should not be any error and linking modules should be created
Actual behavior
Error initializing link modules. Error: Link module VendorStockTransferStockLocationStockLocationLink already defined.
Link to reproduction repo
https://github.com/kowalski21/medusa-pharmacy
The text was updated successfully, but these errors were encountered: