When you cancel a sales document that has items with lots, or you issue a return note/credit note, warehouse quantity is corrected automatically. The lot stays reserved, though, unless you disconnect it first. That is why you first free the lots and then cancel or return.
Lots appear only on a sale with warehouse movement, and only if warehouse settings have Quantities per line (lots) enabled. The panel is Stock management (menu Select stock (lots)).
- Open the original sales document you want to cancel (not the credit note/return note).
- If it is locked, unlock it. Disconnect is shown only on an unlocked document (menu Lock document from editing/deletion).
- Select the item on the lines so the lots appear. On the lots grid, right-click and choose Disconnect from lots.

Then copy the document to a special cancellation, return note, or credit note. On a sales return the items come back to the warehouse and the lots are available again.
In warehouse settings, next to lots, you can choose which inbound documents (with movement) feed the lots. If you leave it empty, all documents with movement are used.

Automatic disconnect from lots
When you issue a return note, you can disconnect lots of the related document automatically. Prerequisite: each line must have a Position (lot). The related document must be filled in, so the original lines can be found.
For this to work, paste the code below into the run SQL field of the corresponding return document. It runs on save and updates up to 150 lines of the related document.

|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
-- doc -- execute block as declare i int = 0; declare main_doc_prodid int; declare main_doc_lineid int; declare main_doc_position varchar(1000); declare doc_related varchar(1000); begin doc_related=(select "Sxetika" from "pvlhseis" pvlin where "Aa"=:aa); while (i < 150) do begin if ((select count(ppl."Aa") from "pvlhseis" ppl,"grammes" ggr,"eidhpar" eid where ggr."Aapar"=ppl."Aa" and eid."Aa"=ppl."Parastatiko" and (ppl."Sxetiko"=:aa or doc_abbreviation(eid."Parastatiko",coalesce( ppl."Seira",'')||'#'||ppl."Ariumospar")=:doc_related) )>:i) then begin main_doc_prodid=(select first 1 skip (:i) ggr."Eidos" from "pvlhseis" ppl,"grammes" ggr,"eidhpar" eid, "kinhseis" kin where kin."Grammh"=ggr."Aa" and ggr."Aapar"=ppl."Aa" and eid."Aa"=ppl."Parastatiko" and (ppl."Sxetiko"=:aa or doc_abbreviation(eid."Parastatiko",coalesce( ppl."Seira",'')||'#'||ppl."Ariumospar")=:doc_related) ); main_doc_lineid=(select first 1 skip (:i) ggr."Aa" from "pvlhseis" ppl,"grammes" ggr,"eidhpar" eid, "kinhseis" kin where kin."Grammh"=ggr."Aa" and ggr."Aapar"=ppl."Aa" and eid."Aa"=ppl."Parastatiko" and (ppl."Sxetiko"=:aa or doc_abbreviation(eid."Parastatiko",coalesce( ppl."Seira",'')||'#'||ppl."Ariumospar")=:doc_related) ); main_doc_position=(select first 1 skip (:i) kin."Uesh" from "pvlhseis" ppl,"grammes" ggr,"eidhpar" eid, "kinhseis" kin where kin."Grammh"=ggr."Aa" and ggr."Aapar"=ppl."Aa" and eid."Aa"=ppl."Parastatiko" and (ppl."Sxetiko"=:aa or doc_abbreviation(eid."Parastatiko",coalesce( ppl."Seira",'')||'#'||ppl."Ariumospar")=:doc_related) ); if (:main_doc_prodid in (select ggr."Eidos" from "grammes" ggr where ggr."Aapar"=:aa)) then begin update "stockperdocline" stdl set stdl."Quantity"= (select grg."Posothta" from "grammes" grg where grg."Aa"=stdl."RelID") - (select sum(ggr."Posothta") from "grammes" ggr,"kinhseis" kks where ggr."Aa"=kks."Grammh" and ggr."Aapar"=:aa and ggr."Eidos"=:main_doc_prodid and kks."Uesh"=:main_doc_position ) where stdl."RelID"=:main_doc_lineid; end end else suspend; i = i + 1; end end -- doc-eof -- |
