mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
7b8d7c9fe0
@ -10,8 +10,7 @@ addons:
|
|||||||
-sqlite3
|
-sqlite3
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- make requirements
|
- make install
|
||||||
- make setup
|
|
||||||
- make migrate
|
- make migrate
|
||||||
|
|
||||||
script:
|
script:
|
||||||
|
@ -237,6 +237,7 @@ class Build(models.Model):
|
|||||||
for serial in serial_numbers:
|
for serial in serial_numbers:
|
||||||
item = StockItem.objects.create(
|
item = StockItem.objects.create(
|
||||||
part=self.part,
|
part=self.part,
|
||||||
|
build=self,
|
||||||
location=location,
|
location=location,
|
||||||
quantity=1,
|
quantity=1,
|
||||||
serial=serial,
|
serial=serial,
|
||||||
@ -250,6 +251,7 @@ class Build(models.Model):
|
|||||||
# Add stock of the newly created item
|
# Add stock of the newly created item
|
||||||
item = StockItem.objects.create(
|
item = StockItem.objects.create(
|
||||||
part=self.part,
|
part=self.part,
|
||||||
|
build=self,
|
||||||
location=location,
|
location=location,
|
||||||
quantity=self.quantity,
|
quantity=self.quantity,
|
||||||
batch=str(self.batch) if self.batch else '',
|
batch=str(self.batch) if self.batch else '',
|
||||||
|
@ -13,8 +13,8 @@ database:
|
|||||||
# Example Configuration - MySQL
|
# Example Configuration - MySQL
|
||||||
#ENGINE: django.db.backends.mysql
|
#ENGINE: django.db.backends.mysql
|
||||||
#NAME: inventree
|
#NAME: inventree
|
||||||
#USER: inventree
|
#USER: inventree_username
|
||||||
#PASSWORD: password
|
#PASSWORD: inventree_password
|
||||||
#HOST: ''
|
#HOST: ''
|
||||||
#PORT: ''
|
#PORT: ''
|
||||||
|
|
||||||
@ -52,4 +52,5 @@ log_queries: False
|
|||||||
|
|
||||||
# Backup options
|
# Backup options
|
||||||
# Set the backup_dir parameter to store backup files in a specific location
|
# 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/'
|
#backup_dir: '/home/inventree/backup/'
|
20
InvenTree/stock/migrations/0010_stockitem_build.py
Normal file
20
InvenTree/stock/migrations/0010_stockitem_build.py
Normal file
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
@ -101,6 +101,7 @@ class StockItem(models.Model):
|
|||||||
delete_on_deplete: If True, StockItem will be deleted when the stock level gets to zero
|
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)
|
status: Status of this StockItem (ref: InvenTree.status_codes.StockStatus)
|
||||||
notes: Extra notes field
|
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)
|
purchase_order: Link to a PurchaseOrder (if this stock item was created from a PurchaseOrder)
|
||||||
infinite: If True this StockItem can never be exhausted
|
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)
|
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(
|
purchase_order = models.ForeignKey(
|
||||||
'order.PurchaseOrder',
|
'order.PurchaseOrder',
|
||||||
on_delete=models.SET_NULL,
|
on_delete=models.SET_NULL,
|
||||||
@ -484,20 +492,13 @@ class StockItem(models.Model):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Create a new StockItem object, duplicating relevant fields
|
# Create a new StockItem object, duplicating relevant fields
|
||||||
new_stock = StockItem.objects.create(
|
# Nullify the PK so a new record is created
|
||||||
part=self.part,
|
new_stock = StockItem.objects.get(pk=self.pk)
|
||||||
quantity=quantity,
|
new_stock.pk = None
|
||||||
supplier_part=self.supplier_part,
|
new_stock.quantity = quantity
|
||||||
location=self.location,
|
|
||||||
notes=self.notes,
|
|
||||||
URL=self.URL,
|
|
||||||
batch=self.batch,
|
|
||||||
delete_on_deplete=self.delete_on_deplete
|
|
||||||
)
|
|
||||||
|
|
||||||
new_stock.save()
|
new_stock.save()
|
||||||
|
|
||||||
# Copy the transaction history
|
# Copy the transaction history of this part into the new one
|
||||||
new_stock.copyHistoryFrom(self)
|
new_stock.copyHistoryFrom(self)
|
||||||
|
|
||||||
# Add a new tracking item for the new stock item
|
# Add a new tracking item for the new stock item
|
||||||
|
@ -90,6 +90,12 @@
|
|||||||
<td>{{ item.batch }}</td>
|
<td>{{ item.batch }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if item.build %}
|
||||||
|
<tr>
|
||||||
|
<td>Build</td>
|
||||||
|
<td><a href="{% url 'build-detail' item.build.id %}">{{ item.build }}</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endif %}
|
||||||
{% if item.purchase_order %}
|
{% if item.purchase_order %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>Purchase Order</td>
|
<td>Purchase Order</td>
|
||||||
|
25
Makefile
25
Makefile
@ -7,49 +7,58 @@ clean:
|
|||||||
rm -rf .tox
|
rm -rf .tox
|
||||||
rm -f .coverage
|
rm -f .coverage
|
||||||
|
|
||||||
|
# Perform database migrations (after schema changes are made)
|
||||||
migrate:
|
migrate:
|
||||||
python3 InvenTree/manage.py makemigrations company
|
python3 InvenTree/manage.py makemigrations company
|
||||||
python3 InvenTree/manage.py makemigrations part
|
python3 InvenTree/manage.py makemigrations part
|
||||||
python3 InvenTree/manage.py makemigrations stock
|
python3 InvenTree/manage.py makemigrations stock
|
||||||
python3 InvenTree/manage.py makemigrations build
|
python3 InvenTree/manage.py makemigrations build
|
||||||
python3 InvenTree/manage.py makemigrations order
|
python3 InvenTree/manage.py makemigrations order
|
||||||
|
python3 InvenTree/manage.py migrate
|
||||||
python3 InvenTree/manage.py migrate --run-syncdb
|
python3 InvenTree/manage.py migrate --run-syncdb
|
||||||
python3 InvenTree/manage.py check
|
python3 InvenTree/manage.py check
|
||||||
|
|
||||||
requirements:
|
# Install all required packages
|
||||||
|
install:
|
||||||
pip3 install -U -r requirements.txt
|
pip3 install -U -r requirements.txt
|
||||||
|
|
||||||
setup:
|
|
||||||
python3 InvenTree/setup.py
|
python3 InvenTree/setup.py
|
||||||
|
|
||||||
|
# Create a superuser account
|
||||||
superuser:
|
superuser:
|
||||||
python3 InvenTree/manage.py createsuperuser
|
python3 InvenTree/manage.py createsuperuser
|
||||||
|
|
||||||
install: requirements setup migrate superuser
|
# Install pre-requisites for mysql setup
|
||||||
|
|
||||||
mysql:
|
mysql:
|
||||||
apt-get install mysql-server
|
apt-get install mysql-server
|
||||||
apt-get install libmysqlclient-dev
|
apt-get install libmysqlclient-dev
|
||||||
pip3 install mysqlclient
|
pip3 install mysqlclient
|
||||||
|
|
||||||
|
# Run PEP style checks against source code
|
||||||
style:
|
style:
|
||||||
flake8 InvenTree
|
flake8 InvenTree
|
||||||
|
|
||||||
|
# Run unit tests
|
||||||
test:
|
test:
|
||||||
python3 InvenTree/manage.py check
|
python3 InvenTree/manage.py check
|
||||||
python3 InvenTree/manage.py test build company part stock order
|
python3 InvenTree/manage.py test build company part stock order
|
||||||
|
|
||||||
|
# Run code coverage
|
||||||
coverage:
|
coverage:
|
||||||
python3 InvenTree/manage.py check
|
python3 InvenTree/manage.py check
|
||||||
coverage run InvenTree/manage.py test build company part stock order InvenTree
|
coverage run InvenTree/manage.py test build company part stock order InvenTree
|
||||||
coverage html
|
coverage html
|
||||||
|
|
||||||
documentation:
|
# Install packages required to generate code docs
|
||||||
|
docreqs:
|
||||||
pip3 install -U -r docs/requirements.txt
|
pip3 install -U -r docs/requirements.txt
|
||||||
cd docs & make html
|
|
||||||
|
|
||||||
|
# Build code docs
|
||||||
|
docs:
|
||||||
|
cd docs && make html
|
||||||
|
|
||||||
|
# Make database backup
|
||||||
backup:
|
backup:
|
||||||
python3 InvenTree/manage.py dbbackup
|
python3 InvenTree/manage.py dbbackup
|
||||||
python3 InvenTree/manage.py mediabackup
|
python3 InvenTree/manage.py mediabackup
|
||||||
|
|
||||||
.PHONY: clean migrate requirements setup superuser install mysql style test coverage documentation backup
|
.PHONY: clean migrate superuser install mysql style test coverage docreqs docs backup
|
@ -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.
|
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:
|
.. 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 <https://docs.djangoproject.com/en/dev/ref/databases/>`_ for further information.
|
The database options then need to be adjusted to communicate the MySQL backend. Refer to the `Django docs <https://docs.djangoproject.com/en/dev/ref/databases/>`_ for further information.
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ InvenTree Source Documentation
|
|||||||
Tables<tables>
|
Tables<tables>
|
||||||
REST API<rest>
|
REST API<rest>
|
||||||
Backup and Restore<backup>
|
Backup and Restore<backup>
|
||||||
|
Migrate Data<migrate>
|
||||||
InvenTree Modules <modules>
|
InvenTree Modules <modules>
|
||||||
Module Reference<reference>
|
Module Reference<reference>
|
||||||
|
|
||||||
|
33
docs/migrate.rst
Normal file
33
docs/migrate.rst
Normal file
@ -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 <start.html>`_):
|
||||||
|
|
||||||
|
``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``
|
@ -11,31 +11,62 @@ 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.
|
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
|
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``.
|
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``
|
``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
|
Additionally, this step creates a *SECREY_KEY* file which is used for the django authentication framework.
|
||||||
* Generates a SECREY_KEY file required for the django authentication framework
|
|
||||||
* Performs initial database installation and migrations
|
|
||||||
* Prompts user to create a superuser account
|
|
||||||
|
|
||||||
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 <config.html>`_ section.
|
For further information on installation configuration, refer to the `Configuration <config.html>`_ section.
|
||||||
|
|
||||||
|
Initialize Database
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
Once install settings are correctly configured (in *config.yaml*) run the initial setup script:
|
||||||
|
|
||||||
|
``make migrate``
|
||||||
|
|
||||||
|
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
|
Run Development Server
|
||||||
----------------------
|
----------------------
|
||||||
|
|
||||||
@ -58,4 +89,5 @@ Other shorthand functions are provided for the development and testing process:
|
|||||||
* ``make test`` - Run all unit tests
|
* ``make test`` - Run all unit tests
|
||||||
* ``make coverage`` - Run all unit tests and generate code coverage report
|
* ``make coverage`` - Run all unit tests and generate code coverage report
|
||||||
* ``make style`` - Check Python codebase against PEP coding standards (using Flake)
|
* ``make style`` - Check Python codebase against PEP coding standards (using Flake)
|
||||||
* ``make documentation`` - Generate this documentation
|
* ``make docreqs`` - Install the packages required to generate documentation
|
||||||
|
* ``make docs`` - Generate this documentation
|
Loading…
Reference in New Issue
Block a user