From 32538c8c3d4663981982969cb451e46fe897ba7b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 21:46:08 +1000 Subject: [PATCH 01/13] Fixes for doc building - Separate doc build from doc requirements - Fix command which doesn't work properly on *nix --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 900a67c7b2..9cf8253b5f 100644 --- a/Makefile +++ b/Makefile @@ -44,12 +44,14 @@ coverage: coverage run InvenTree/manage.py test build company part stock order InvenTree coverage html -documentation: +docreqs: pip3 install -U -r docs/requirements.txt - cd docs & make html + +documentation: + cd docs && make html backup: python3 InvenTree/manage.py dbbackup python3 InvenTree/manage.py mediabackup -.PHONY: clean migrate requirements setup superuser install mysql style test coverage documentation backup \ No newline at end of file +.PHONY: clean migrate requirements setup superuser install mysql style test coverage docreqs documentation backup \ No newline at end of file From fae9a92a827361119bfa447638c8462b567cf3a6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 21:57:17 +1000 Subject: [PATCH 02/13] Improvements for makefile - Comments - Cleanup --- Makefile | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9cf8253b5f..33dbca8867 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ clean: rm -rf .tox rm -f .coverage +# Perform database migrations (after schema changes are made) migrate: python3 InvenTree/manage.py makemigrations company python3 InvenTree/manage.py makemigrations part @@ -16,40 +17,50 @@ migrate: python3 InvenTree/manage.py migrate --run-syncdb python3 InvenTree/manage.py check -requirements: +# Install all required packages +install: pip3 install -U -r requirements.txt +# Perform initial database setup setup: python3 InvenTree/setup.py + $(MAKE) migrate + $(MAKE) superuser +# Create a superuser account superuser: python3 InvenTree/manage.py createsuperuser -install: requirements setup migrate superuser - +# Install pre-requisites for mysql setup mysql: apt-get install mysql-server apt-get install libmysqlclient-dev pip3 install mysqlclient +# Run PEP style checks against source code style: flake8 InvenTree +# Run unit tests test: python3 InvenTree/manage.py check python3 InvenTree/manage.py test build company part stock order +# Run code coverage coverage: python3 InvenTree/manage.py check coverage run InvenTree/manage.py test build company part stock order InvenTree coverage html +# Install packages required to generate code docs docreqs: pip3 install -U -r docs/requirements.txt +# Build code docs documentation: cd docs && make html +# Make database backup backup: python3 InvenTree/manage.py dbbackup python3 InvenTree/manage.py mediabackup From d9cc03c5cae0ddeabd72d3f40e7f3d6635e424c6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 22:16:58 +1000 Subject: [PATCH 03/13] Improve installation documentation --- InvenTree/config_template.yaml | 5 ++-- Makefile | 6 ++-- docs/config.rst | 2 +- docs/start.rst | 50 ++++++++++++++++++++++++++-------- 4 files changed, 46 insertions(+), 17 deletions(-) diff --git a/InvenTree/config_template.yaml b/InvenTree/config_template.yaml index 1185dd2ee2..e5747a19c5 100644 --- a/InvenTree/config_template.yaml +++ b/InvenTree/config_template.yaml @@ -13,8 +13,8 @@ database: # Example Configuration - MySQL #ENGINE: django.db.backends.mysql #NAME: inventree - #USER: inventree - #PASSWORD: password + #USER: inventree_username + #PASSWORD: inventree_password #HOST: '' #PORT: '' @@ -52,4 +52,5 @@ log_queries: False # Backup options # Set the backup_dir parameter to store backup files in a specific location +# If unspecified, the local user's temp directory will be used #backup_dir: '/home/inventree/backup/' \ No newline at end of file diff --git a/Makefile b/Makefile index 33dbca8867..38e36a6f2b 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,10 @@ migrate: # Install all required packages install: pip3 install -U -r requirements.txt + python3 InvenTree/setup.py # Perform initial database setup setup: - python3 InvenTree/setup.py $(MAKE) migrate $(MAKE) superuser @@ -57,7 +57,7 @@ docreqs: pip3 install -U -r docs/requirements.txt # Build code docs -documentation: +docs: cd docs && make html # Make database backup @@ -65,4 +65,4 @@ backup: python3 InvenTree/manage.py dbbackup python3 InvenTree/manage.py mediabackup -.PHONY: clean migrate requirements setup superuser install mysql style test coverage docreqs documentation backup \ No newline at end of file +.PHONY: clean migrate requirements setup superuser install mysql style test coverage docreqs docs backup \ No newline at end of file diff --git a/docs/config.rst b/docs/config.rst index cfb283af69..1cdb4c3fc6 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -41,7 +41,7 @@ These requirements can be installed from the base directory with the command ``m It is up to the database adminstrator to create a new database to store inventree data, in addition to a username/password to access the data. .. important:: MySQL Collation: - When creating the database, the adminstrator must ensure that the collation option is set to *utf8_unicode_520_ci* to ensure that InvenTree features function correctly. + When creating the MySQL database, the adminstrator must ensure that the collation option is set to *utf8_unicode_520_ci* to ensure that InvenTree features function correctly. The database options then need to be adjusted to communicate the MySQL backend. Refer to the `Django docs `_ for further information. diff --git a/docs/start.rst b/docs/start.rst index 6150c22bb0..b6853ffc23 100644 --- a/docs/start.rst +++ b/docs/start.rst @@ -11,31 +11,58 @@ To install a complete *development* environment for InvenTree, follow the steps A makefile in the root directory provides shortcuts for the installation process, and can also be very useful during development. +Requirements +------------ + +To install InvenTree you will need the following: + +* python3 +* pip3 +* make + Installation ------------ +First, download the latest InvenTree source code: + +``git clone https://github.com/inventree/inventree/`` + InvenTree is a Python/Django application and relies on the pip package manager. All packages required to develop and test InvenTree can be installed via pip. Package requirements can be found in ``requirements.txt``. -To setup the InvenTree environment, run the command: +To setup the InvenTree environment, *cd into the inventree directory* and run the command: ``make install`` -which performs the following actions: +which installs all required Python packages using pip package manager. It also creates a (default) database configuration file which needs to be edited to meet user needs before proceeding (see next step below). -* Installs all required Python packages using pip package manager -* Generates a SECREY_KEY file required for the django authentication framework -* Performs initial database installation and migrations -* Prompts user to create a superuser account +Additionally, this step creates a *SECREY_KEY* file which is used for the django authentication framework. -Install Configuration ---------------------- +.. important:: + The *SECREY_KEY* file should never be shared or made public. -InvenTree provides a simple default setup which should work *out of the box* for testing and debug purposes. For installation in production environments, further configuration options are available in the ``config.yaml`` configuration file. +Database Configuration +----------------------- -The configuration file provides administrators control over various setup options without digging into the Django ``settings.py`` script. The default setup uses a sqlite database with *DEBUG* mode enabled. +Once the required packages are installed, the database configuration must be adjusted to suit your particular needs. InvenTree provides a simple default setup which should work *out of the box* for testing and debug purposes. + +As part of the previous *install* step, a configuration file (*config.yaml*) is created. The configuration file provides administrators control over various setup options without digging into the Django ``settings.py`` script. The default setup uses a local sqlite database with *DEBUG* mode enabled. For further information on installation configuration, refer to the `Configuration `_ section. +Initialize Database +------------------- + +Once install settings are correctly configured (in *config.yaml*) run the initial setup script: + +``make setup`` + +which performs the following functions: + +* Run initial database migrations, creating the required tables, etc +* Create initial administrator account + +The database should now be installed! + Run Development Server ---------------------- @@ -58,4 +85,5 @@ Other shorthand functions are provided for the development and testing process: * ``make test`` - Run all unit tests * ``make coverage`` - Run all unit tests and generate code coverage report * ``make style`` - Check Python codebase against PEP coding standards (using Flake) -* ``make documentation`` - Generate this documentation \ No newline at end of file +* ``make docreqs`` - Install the packages required to generate documentation +* ``make docs`` - Generate this documentation \ No newline at end of file From 6212c2aeda729ea76aa561d45c1c52d0682f8c52 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 22:31:21 +1000 Subject: [PATCH 04/13] Fix travis steps --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5df4432cef..897e14457c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ addons: -sqlite3 before_install: - - make requirements + - make install - make setup - make migrate From 10ca3b1b93cbf265ae337b34b17c0c84a4b97285 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 22:35:21 +1000 Subject: [PATCH 05/13] Remove defunct line --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 38e36a6f2b..4fb72e26de 100644 --- a/Makefile +++ b/Makefile @@ -65,4 +65,4 @@ backup: python3 InvenTree/manage.py dbbackup python3 InvenTree/manage.py mediabackup -.PHONY: clean migrate requirements setup superuser install mysql style test coverage docreqs docs backup \ No newline at end of file +.PHONY: clean migrate setup superuser install mysql style test coverage docreqs docs backup \ No newline at end of file From 04809251869e1954d4cb57f221eb3d10359144d9 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 22:54:48 +1000 Subject: [PATCH 06/13] Simplify makefile again - Remove setup target - Fix travis --- .travis.yml | 1 - Makefile | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 897e14457c..00d049b7a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,6 @@ addons: before_install: - make install - - make setup - make migrate script: diff --git a/Makefile b/Makefile index 4fb72e26de..d997c76344 100644 --- a/Makefile +++ b/Makefile @@ -22,11 +22,6 @@ install: pip3 install -U -r requirements.txt python3 InvenTree/setup.py -# Perform initial database setup -setup: - $(MAKE) migrate - $(MAKE) superuser - # Create a superuser account superuser: python3 InvenTree/manage.py createsuperuser @@ -65,4 +60,4 @@ backup: python3 InvenTree/manage.py dbbackup python3 InvenTree/manage.py mediabackup -.PHONY: clean migrate setup superuser install mysql style test coverage docreqs docs backup \ No newline at end of file +.PHONY: clean migrate superuser install mysql style test coverage docreqs docs backup \ No newline at end of file From e32048d3c6c06679eeb7384e9f0d7bba49cf27f8 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 22:55:02 +1000 Subject: [PATCH 07/13] Add documentation for data migration --- docs/index.rst | 1 + docs/migrate.rst | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 docs/migrate.rst diff --git a/docs/index.rst b/docs/index.rst index c90ff2fe25..5e7279066f 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -14,6 +14,7 @@ InvenTree Source Documentation Tables REST API Backup and Restore + Migrate Data InvenTree Modules Module Reference diff --git a/docs/migrate.rst b/docs/migrate.rst new file mode 100644 index 0000000000..78dfb39a6a --- /dev/null +++ b/docs/migrate.rst @@ -0,0 +1,33 @@ +Migrating Data +============== + +.. toctree:: + :titlesonly: + :maxdepth: 2 + :caption: Migrating Data + :hidden: + +In the case that data needs to be migrated from one database installation to another, the following procedure can be used to export data, initialize the new database, and re-import the data. + +Export Data +----------- + +``python3 manage.py dumpdata --exclude contenttypes --exclude auth.permission --indent 2 > data.json`` + +This will export all data (including user information) to a json data file. + +Initialize Database +------------------- + +Configure the new database using the normal processes (see `Getting Started `_): + +``python3 manage.py makemigrations`` + +``python3 manage.py migrate --run-syncdb`` + +Import Data +----------- + +The new database should now be correctly initialized with the correct table structures requried to import the data. + +``python3 manage.py loaddata data.json`` \ No newline at end of file From e9efac403c7fe9865c6cca57a6b89acaf9b08ba1 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 22:55:18 +1000 Subject: [PATCH 08/13] Tweak install docs --- docs/start.rst | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/start.rst b/docs/start.rst index b6853ffc23..5e08bf8634 100644 --- a/docs/start.rst +++ b/docs/start.rst @@ -54,15 +54,19 @@ Initialize Database Once install settings are correctly configured (in *config.yaml*) run the initial setup script: -``make setup`` +``make migrate`` -which performs the following functions: - -* Run initial database migrations, creating the required tables, etc -* Create initial administrator account +which performs the initial database migrations, creating the required tables, etc The database should now be installed! +Create Admin Account +-------------------- + +Create an initial superuser (administrator) account for the InvenTree instance: + +``make superuser`` + Run Development Server ---------------------- From 90a342fad8c4dab9bf2e8d4d393502a62eaaf9a2 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 23:09:40 +1000 Subject: [PATCH 09/13] Add a reference to a build for a stock item --- .../stock/migrations/0010_stockitem_build.py | 20 +++++++++++++++++++ InvenTree/stock/models.py | 8 ++++++++ 2 files changed, 28 insertions(+) create mode 100644 InvenTree/stock/migrations/0010_stockitem_build.py diff --git a/InvenTree/stock/migrations/0010_stockitem_build.py b/InvenTree/stock/migrations/0010_stockitem_build.py new file mode 100644 index 0000000000..4445d27b2e --- /dev/null +++ b/InvenTree/stock/migrations/0010_stockitem_build.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.4 on 2019-09-01 13:08 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('build', '0005_auto_20190604_2217'), + ('stock', '0009_auto_20190715_2351'), + ] + + operations = [ + migrations.AddField( + model_name='stockitem', + name='build', + field=models.ForeignKey(blank=True, help_text='Build for this stock item', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='build_outputs', to='build.Build'), + ), + ] diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 9aa8595c49..37a2323992 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -101,6 +101,7 @@ class StockItem(models.Model): delete_on_deplete: If True, StockItem will be deleted when the stock level gets to zero status: Status of this StockItem (ref: InvenTree.status_codes.StockStatus) notes: Extra notes field + build: Link to a Build (if this stock item was created from a build) purchase_order: Link to a PurchaseOrder (if this stock item was created from a PurchaseOrder) infinite: If True this StockItem can never be exhausted """ @@ -300,6 +301,13 @@ class StockItem(models.Model): updated = models.DateField(auto_now=True, null=True) + build = models.ForeignKey( + 'build.Build', on_delete=models.SET_NULL, + blank=True, null=True, + help_text='Build for this stock item', + related_name='build_outputs', + ) + purchase_order = models.ForeignKey( 'order.PurchaseOrder', on_delete=models.SET_NULL, From 3cef5c93ce8a8d04d9233a478cc78f5a46d87200 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 23:18:08 +1000 Subject: [PATCH 10/13] Improve stock item splitting --- InvenTree/stock/models.py | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 37a2323992..6ae7803d10 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -492,20 +492,12 @@ class StockItem(models.Model): return # Create a new StockItem object, duplicating relevant fields - new_stock = StockItem.objects.create( - part=self.part, - quantity=quantity, - supplier_part=self.supplier_part, - location=self.location, - notes=self.notes, - URL=self.URL, - batch=self.batch, - delete_on_deplete=self.delete_on_deplete - ) - + # Nullify the PK so a new record is created + new_stock = StockItem.objects.get(pk=self.pk) + new_stock.quantity = quantity new_stock.save() - # Copy the transaction history + # Copy the transaction history of this part into the new one new_stock.copyHistoryFrom(self) # Add a new tracking item for the new stock item From c45c4e236efc45bcb709c62e8caef78cbf68a8cb Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 23:18:28 +1000 Subject: [PATCH 11/13] Point new stockitem to the correct build --- InvenTree/build/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 1ceedf63e2..2ae3f0c5a7 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -237,6 +237,7 @@ class Build(models.Model): for serial in serial_numbers: item = StockItem.objects.create( part=self.part, + build=self, location=location, quantity=1, serial=serial, @@ -250,6 +251,7 @@ class Build(models.Model): # Add stock of the newly created item item = StockItem.objects.create( part=self.part, + build=self, location=location, quantity=self.quantity, batch=str(self.batch) if self.batch else '', From 7db938eda032ce428a33f9ff895f0105806e983e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 23:24:27 +1000 Subject: [PATCH 12/13] Show the build item on the stock-item page (if applicable) --- InvenTree/stock/templates/stock/item.html | 6 ++++++ Makefile | 1 + 2 files changed, 7 insertions(+) diff --git a/InvenTree/stock/templates/stock/item.html b/InvenTree/stock/templates/stock/item.html index 1e7e44046c..87abe0adfe 100644 --- a/InvenTree/stock/templates/stock/item.html +++ b/InvenTree/stock/templates/stock/item.html @@ -90,6 +90,12 @@ {{ item.batch }} {% endif %} + {% if item.build %} + + Build + {{ item.build }} + + {% endif %} {% if item.purchase_order %} Purchase Order diff --git a/Makefile b/Makefile index d997c76344..c898af195d 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,7 @@ migrate: python3 InvenTree/manage.py makemigrations stock python3 InvenTree/manage.py makemigrations build python3 InvenTree/manage.py makemigrations order + python3 InvenTree/manage.py migrate python3 InvenTree/manage.py migrate --run-syncdb python3 InvenTree/manage.py check From 906766cc0e0dd6fa0f808eb6c8fa16886611db81 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 1 Sep 2019 23:28:28 +1000 Subject: [PATCH 13/13] Bug fix - ensure pk is set to None --- InvenTree/stock/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 6ae7803d10..78cef49371 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -494,6 +494,7 @@ class StockItem(models.Model): # Create a new StockItem object, duplicating relevant fields # Nullify the PK so a new record is created new_stock = StockItem.objects.get(pk=self.pk) + new_stock.pk = None new_stock.quantity = quantity new_stock.save()