adding weight to trade documents

This commit is contained in:
Cayo Puigdefabregas 2021-08-03 16:40:17 +02:00
parent 6cb9af57a9
commit 9b2936c795
4 changed files with 65 additions and 3 deletions

View File

@ -0,0 +1,31 @@
"""adding weight to tradedocuments
Revision ID: 3ac2bc1897ce
Revises: 3a3601ac8224
Create Date: 2021-08-03 16:28:38.719686
"""
from alembic import op
import sqlalchemy as sa
from alembic import context
# revision identifiers, used by Alembic.
revision = '3ac2bc1897ce'
down_revision = '0103a9c96b2d'
branch_labels = None
depends_on = None
def get_inv():
INV = context.get_x_argument(as_dictionary=True).get('inventory')
if not INV:
raise ValueError("Inventory value is not specified")
return INV
def upgrade():
op.add_column("trade_document", sa.Column("weight", sa.Float(decimal_return_scale=2), nullable=True), schema=f'{get_inv()}')
def downgrade():
op.drop_column('trade_document', 'weight', schema=f'{get_inv()}')

View File

@ -71,6 +71,8 @@ class TradeDocument(Thing):
file_hash.comment = """This is the hash of the file produced from frontend.""" file_hash.comment = """This is the hash of the file produced from frontend."""
url = db.Column(URL()) url = db.Column(URL())
url.comment = """This is the url where resides the document.""" url.comment = """This is the url where resides the document."""
weight = db.Column(db.Float(nullable=True))
weight.comment = """This is the weight of one container than this document express."""
__table_args__ = ( __table_args__ = (
db.Index('document_id', id, postgresql_using='hash'), db.Index('document_id', id, postgresql_using='hash'),

View File

@ -1,4 +1,4 @@
from marshmallow.fields import DateTime, Integer, validate from marshmallow.fields import DateTime, Integer, Float, validate
from teal.marshmallow import SanitizedStr, URL from teal.marshmallow import SanitizedStr, URL
# from marshmallow import ValidationError, validates_schema # from marshmallow import ValidationError, validates_schema
@ -29,3 +29,4 @@ class TradeDocument(Thing):
url = URL(description=m.TradeDocument.url.comment) url = URL(description=m.TradeDocument.url.comment)
lot = NestedOn('Lot', only_query='id', description=m.TradeDocument.lot.__doc__) lot = NestedOn('Lot', only_query='id', description=m.TradeDocument.lot.__doc__)
trading = SanitizedStr(dump_only=True, description='') trading = SanitizedStr(dump_only=True, description='')
weight = Float(required=False, description=m.TradeDocument.weight.comment)

View File

@ -16,7 +16,7 @@ from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.user.models import Session from ereuse_devicehub.resources.user.models import Session
from ereuse_devicehub.resources.action.models import Snapshot, Allocate, Live from ereuse_devicehub.resources.action.models import Snapshot, Allocate, Live
from ereuse_devicehub.resources.documents import documents from ereuse_devicehub.resources.documents import documents
from ereuse_devicehub.resources.tradedocument.definitions import TradeDocumentDef from ereuse_devicehub.resources.tradedocument.models import TradeDocument
from ereuse_devicehub.resources.device import models as d from ereuse_devicehub.resources.device import models as d
from ereuse_devicehub.resources.lot.models import Lot from ereuse_devicehub.resources.lot.models import Lot
from ereuse_devicehub.resources.tag.model import Tag from ereuse_devicehub.resources.tag.model import Tag
@ -682,4 +682,32 @@ def test_get_wbconf(user: UserClient):
def test_trade_documents(user: UserClient): def test_trade_documents(user: UserClient):
"""Tests upload one document""" """Tests upload one document"""
doc, _ = user.post(res=TradeDocumentDef.t, item='wbconf/usodyrate', accept=ANY) lot, _ = user.post({'name': 'MyLot'}, res=Lot)
request_post = {
'filename': 'test.pdf',
'hash': 'bbbbbbbb',
'url': 'http://www.ereuse.org/',
'lot': lot['id']
}
doc, _ = user.post(res=TradeDocument, data=request_post)
assert doc['filename'] == request_post['filename']
assert doc['url'] == request_post['url']
assert doc['hash'] == request_post['hash']
assert doc['lot']['name'] == lot['name']
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_trade_documents_with_weight(user: UserClient):
"""Tests upload one document"""
lot, _ = user.post({'name': 'MyLot'}, res=Lot)
request_post = {
'filename': 'test.pdf',
'hash': 'bbbbbbbb',
'url': 'http://www.ereuse.org/',
'weight': 15,
'lot': lot['id']
}
doc, _ = user.post(res=TradeDocument, data=request_post)
assert doc['weight'] == request_post['weight']