メインコンテンツにスキップ

google-sheets-mini-erp

A mini ERP with Google Apps Script

AI Summary

Google Sheets Mini ERP

A lightweight ERP framework for building inventory, order and other business management systems on Google Sheets.

Target Users

Intermediate GAS developers who need to quickly build internal inventory or sales management tools on Google Sheets.

Problems Solved

Managing relational business data across multiple sheets normally requires lots of custom Apps Script code and complexity.

Tags

Main Features

1
Sheet-as-Table CRUD abstraction

Define each sheet as a table; classes automatically handle primary/foreign keys so you implement CRUD in a few lines.

2
Built-in validation & business rules

Hooks for type checking, stock calculations and other common rules cut manual code and bugs.

3
Auto-generated menus & UI templates

Automatically generates custom menus, input forms and reports, slashing UI implementation time.

Usage Examples

【Introduction】Initialize library & list all products

// Load and initialize the library
const erp = MiniERP.init();

// Fetch every row from the "Products" sheet
const products = erp.table('Products').readAll();
Logger.log(products); // Inspect the result

Run this snippet to prove the library works: it treats the Products sheet as a table and logs its content.

【Basic】Insert a new product record

// New product data
const newProduct = {
  name: 'USB-C Hub',  // product name
  sku: 'HUB-001',     // SKU
  stock: 100,         // initial stock
  price: 29.99        // unit price
};

// Add the record and get the auto-generated ID
const id = erp.table('Products').create(newProduct);
Logger.log(`Created product with id: ${id}`);

With create() you get primary-key generation and sheet write in one line.

【Best Practice】Create order & update stock inside a transaction

function createOrderWithStockUpdate(orderData, orderLines) {
  erp.transaction(() => {
    // 1) Insert order header
    const orderId = erp.table('Orders').create(orderData);

    // 2) Insert order lines and update stock
    orderLines.forEach(line => {
      erp.table('OrderLines').create({ ...line, orderId });

      // 3) Decrease inventory
      erp.table('Products').update(line.productId, record => {
        record.stock -= line.qty; // adjust stock
        return record;
      });
    });
  }); // commited only if everything succeeds
}

transaction() guarantees data consistency by committing only if every step succeeds, otherwise all changes are rolled back.