fix(pos): prevent null branch_id errors during sales
- process_sale now falls back to main branch when g.branch_id is missing - Accept branch_id from request body as override - Make update_inventory_stock trigger skip operations with NULL branch_id - Applied updated trigger to all active tenant DBs
This commit is contained in:
@@ -230,6 +230,13 @@ ALTER TABLE cfdi_queue ALTER COLUMN sale_id DROP NOT NULL;
|
||||
CREATE OR REPLACE FUNCTION update_inventory_stock()
|
||||
RETURNS TRIGGER AS $$
|
||||
BEGIN
|
||||
-- Skip operations that are not tied to a specific branch.
|
||||
-- Per-branch stock tracking requires a branch_id; without it we can't
|
||||
-- assign the stock to any location.
|
||||
IF NEW.branch_id IS NULL THEN
|
||||
RETURN NEW;
|
||||
END IF;
|
||||
|
||||
INSERT INTO inventory_stock (inventory_id, branch_id, stock)
|
||||
VALUES (NEW.inventory_id, NEW.branch_id, NEW.quantity)
|
||||
ON CONFLICT (inventory_id, branch_id) DO UPDATE
|
||||
|
||||
Reference in New Issue
Block a user