-- ABS-26289/ ABS-26952

---WORKORDER table---
UPDATE WORKORDER WO SET WO.DELIVERFROM = 2
WHERE WO.DELIVERFROM NOT IN (0, 1, 2);
COMMIT;

COMMENT ON COLUMN WORKORDER.DELIVERFROM
  IS '0 = to be determined (WO must have status 05 – waiting for approval)
1 = direct order from supplier
2 = stock
3 = not applicable';
 
ALTER TABLE WORKORDER
  ADD CONSTRAINT DELIVERFROM_VALID1_1
  CHECK (DELIVERFROM BETWEEN 0 AND 3);

---WORKORDERLINE table---
ALTER TABLE WORKORDERLINE ADD (REPLENISHMENTSEQUENCENUMBER NUMBER NULL);

COMMENT ON COLUMN WORKORDERLINE.REPLENISHMENTSEQUENCENUMBER
  IS 'Will only be filled in case of a stock replenishment work order (origin = 12)';

DROP INDEX XAK1WORKORDERLINE;
CREATE UNIQUE INDEX XAK1WORKORDERLINE ON WORKORDERLINE 
(WORKORDER_ID ASC, 
 PRODUCT_LINK_ID ASC, 
 SIZEDEFINITION_LINK_ID ASC, 
 REQUESTEDGRADE_ID ASC, 
 REASONCODE_ID ASC, 
 CODEUNIQUELY ASC, 
 RENTALQTYADJUSTMENT_ID ASC, 
 NVL(REPLENISHMENTSEQUENCENUMBER,0) ASC);

---STOCKROOM table---
ALTER TABLE STOCKROOM DROP COLUMN LOCKEDFORSTOCKREPGENERATION;