コード例 #1
0
ファイル: shipping.py プロジェクト: witchawat/psi
 def create_or_update_inventory_transaction(self):
     from psi.app.models.inventory_transaction import InventoryTransactionLine, InventoryTransaction
     from psi.app.models.enum_values import EnumValues
     if self.type.code == const.DIRECT_SHIPPING_TYPE_KEY:
         it_type = EnumValues.get(const.SALES_OUT_INV_TRANS_TYPE_KEY)
     else:
         it_type = EnumValues.get(
             const.FRANCHISE_SALES_OUT_INV_TRANS_TYPE_KEY)
     it = self.inventory_transaction
     if it is None:
         it = InventoryTransaction()
         it.type = it_type
         self.inventory_transaction = it
     it.date = self.date
     it.organization = self.organization
     for line in self.lines:
         itl = line.inventory_transaction_line
         if itl is None:
             itl = InventoryTransactionLine()
         itl.quantity = -line.quantity
         itl.product = line.product
         itl.price = line.price
         itl.in_transit_quantity = 0
         itl.inventory_transaction = it
         line.inventory_transaction_line = itl
         self.update_saleable_qty_in_purchase_inv_lines(line)
     Info.get_db().session.add(it)
コード例 #2
0
ファイル: receiving.py プロジェクト: betterlife/psi
 def update_purchase_order_status(self):
     """
     Update related purchase order's status based on received qty status
     For each line, if received >= line quantity, assume this line is finish
      If all lines are finished, set status of the purchase order to received
      Otherwise set the status to partially received.
     """
     from psi.app.models import EnumValues
     if self.status.code == const.RECEIVING_COMPLETE_STATUS_KEY:
         po = self.purchase_order
         not_finished,started = False, False
         for line in po.lines:
             receiving_lines = line.pol_receiving_lines
             rd_qty = 0
             for rl in receiving_lines:
                 rd_qty += rl.quantity
             if rd_qty > 0:
                 started = True
             if rd_qty < line.quantity:
                 not_finished = True
         if not_finished is False:
             po.status = EnumValues.get(const.PO_RECEIVED_STATUS_KEY)
         elif started is True:
             po.status = EnumValues.get(const.PO_PART_RECEIVED_STATUS_KEY)
         db.session.add(po)
         return po
コード例 #3
0
ファイル: shipping.py プロジェクト: betterlife/psi
 def create_or_update_inventory_transaction(self):
     from psi.app.models.inventory_transaction import InventoryTransactionLine, InventoryTransaction
     from psi.app.models.enum_values import EnumValues
     if self.type.code == const.DIRECT_SHIPPING_TYPE_KEY:
         it_type = EnumValues.get(const.SALES_OUT_INV_TRANS_TYPE_KEY)
     else:
         it_type = EnumValues.get(const.FRANCHISE_SALES_OUT_INV_TRANS_TYPE_KEY)
     it = self.inventory_transaction
     if it is None:
         it = InventoryTransaction()
         it.type = it_type
         self.inventory_transaction = it
     it.date = self.date
     it.organization = self.organization
     for line in self.lines:
         itl = line.inventory_transaction_line
         if itl is None:
             itl = InventoryTransactionLine()
         itl.quantity = -line.quantity
         itl.product = line.product
         itl.price = line.price
         itl.in_transit_quantity = 0
         itl.inventory_transaction = it
         line.inventory_transaction_line = itl
         self.update_saleable_qty_in_purchase_inv_lines(line)
     Info.get_db().session.add(it)
コード例 #4
0
ファイル: receiving.py プロジェクト: betterlife/psi
 def create_draft_recv_from_po(po):
     from psi.app.models.enum_values import EnumValues
     recv_draft_status = EnumValues.get(const.RECEIVING_DRAFT_STATUS_KEY)
     purchase_in_trans_type = EnumValues.get(const.PURCHASE_IN_INV_TRANS_KEY)
     recv = Receiving()
     recv.purchase_order = po
     recv.date = po.order_date
     recv.organization = po.organization
     recv.status = recv_draft_status
     recv.supplier = po.supplier
     from psi.app.models import InventoryTransaction
     trans = InventoryTransaction()
     trans.date = recv.date
     trans.type = purchase_in_trans_type
     trans.organization = po.organization
     recv.inventory_transaction = trans
     for line in po.lines:
         recv_l = ReceivingLine()
         recv_l.receiving = recv
         recv_l.price = line.unit_price
         recv_l.product = line.product
         recv_l.quantity = line.quantity
         recv_l.purchase_order_line = line
         from psi.app.models import InventoryTransactionLine
         trans_l = InventoryTransactionLine()
         trans_l.price = recv_l.price
         trans_l.in_transit_quantity = recv_l.quantity
         trans_l.product = recv_l.product
         trans_l.quantity = 0
         trans_l.inventory_transaction = trans
         recv_l.inventory_transaction_line = trans_l
     return recv
コード例 #5
0
ファイル: receiving.py プロジェクト: witchawat/psi
 def update_purchase_order_status(self):
     """
     Update related purchase order's status based on received qty status
     For each line, if received >= line quantity, assume this line is finish
      If all lines are finished, set status of the purchase order to received
      Otherwise set the status to partially received.
     """
     from psi.app.models import EnumValues
     if self.status.code == const.RECEIVING_COMPLETE_STATUS_KEY:
         po = self.purchase_order
         not_finished, started = False, False
         for line in po.lines:
             receiving_lines = line.pol_receiving_lines
             rd_qty = 0
             for rl in receiving_lines:
                 rd_qty += rl.quantity
             if rd_qty > 0:
                 started = True
             if rd_qty < line.quantity:
                 not_finished = True
         if not_finished is False:
             po.status = EnumValues.get(const.PO_RECEIVED_STATUS_KEY)
         elif started is True:
             po.status = EnumValues.get(const.PO_PART_RECEIVED_STATUS_KEY)
         db.session.add(po)
         return po
コード例 #6
0
ファイル: receiving.py プロジェクト: witchawat/psi
 def create_draft_recv_from_po(po):
     from psi.app.models.enum_values import EnumValues
     recv_draft_status = EnumValues.get(const.RECEIVING_DRAFT_STATUS_KEY)
     purchase_in_trans_type = EnumValues.get(
         const.PURCHASE_IN_INV_TRANS_KEY)
     recv = Receiving()
     recv.purchase_order = po
     recv.date = po.order_date
     recv.organization = po.organization
     recv.status = recv_draft_status
     recv.supplier = po.supplier
     from psi.app.models import InventoryTransaction
     trans = InventoryTransaction()
     trans.date = recv.date
     trans.type = purchase_in_trans_type
     trans.organization = po.organization
     recv.inventory_transaction = trans
     for line in po.lines:
         recv_l = ReceivingLine()
         recv_l.receiving = recv
         recv_l.price = line.unit_price
         recv_l.product = line.product
         recv_l.quantity = line.quantity
         recv_l.purchase_order_line = line
         from psi.app.models import InventoryTransactionLine
         trans_l = InventoryTransactionLine()
         trans_l.price = recv_l.price
         trans_l.in_transit_quantity = recv_l.quantity
         trans_l.product = recv_l.product
         trans_l.quantity = 0
         trans_l.inventory_transaction = trans
         recv_l.inventory_transaction_line = trans_l
     return recv
コード例 #7
0
ファイル: receiving_test.py プロジェクト: witchawat/psi
        def test_logic():
            po = object_faker.purchase_order()
            po.status = EnumValues.get(const.PO_RECEIVED_STATUS_KEY)
            receiving = Receiving()
            receiving.purchase_order = po
            receiving.date = datetime.now()
            receiving.status = EnumValues.get(const.RECEIVING_DRAFT_STATUS_KEY)
            db = Info.get_db()

            db.session.add(po)
            db.session.add(receiving)
            db.session.commit()
            receiving_returned = receiving.filter_by_po_id(1)[0]
            self.assertEqual(receiving, receiving_returned)
コード例 #8
0
ファイル: receiving.py プロジェクト: betterlife/psi
    def save_inv_trans(self, inv_trans):
        from psi.app.models import EnumValues, InventoryTransaction, InventoryTransactionLine

        inv_type = EnumValues.get(const.PURCHASE_IN_INV_TRANS_KEY)
        if inv_trans is None:
            inv_trans = InventoryTransaction()
            inv_trans.type = inv_type
        inv_trans.date = self.date
        for line in self.lines:
            inv_line = line.inventory_transaction_line
            if inv_line is None:
                inv_line = InventoryTransactionLine()
                inv_line.product = line.product
                inv_line.inventory_transaction = inv_trans
                inv_line.inventory_transaction_id = inv_trans.id
                line.inventory_transaction_line = inv_line
            inv_line.price = line.price
            if self.status.code == const.RECEIVING_COMPLETE_STATUS_KEY:
                inv_line.quantity = line.quantity
                inv_line.in_transit_quantity = 0
                inv_line.saleable_quantity = line.quantity
            elif self.status.code == const.RECEIVING_DRAFT_STATUS_KEY:
                inv_line.quantity = 0
                inv_line.saleable_quantity = 0
                inv_line.in_transit_quantity = line.quantity
            line.inventory_transaction_line = inv_line
        for line in inv_trans.lines:
            if line.itl_receiving_line is None:
                db.session.delete(line)
        return inv_trans
コード例 #9
0
ファイル: receiving.py プロジェクト: witchawat/psi
    def save_inv_trans(self, inv_trans):
        from psi.app.models import EnumValues, InventoryTransaction, InventoryTransactionLine

        inv_type = EnumValues.get(const.PURCHASE_IN_INV_TRANS_KEY)
        if inv_trans is None:
            inv_trans = InventoryTransaction()
            inv_trans.type = inv_type
        inv_trans.date = self.date
        for line in self.lines:
            inv_line = line.inventory_transaction_line
            if inv_line is None:
                inv_line = InventoryTransactionLine()
                inv_line.product = line.product
                inv_line.inventory_transaction = inv_trans
                inv_line.inventory_transaction_id = inv_trans.id
                line.inventory_transaction_line = inv_line
            inv_line.price = line.price
            if self.status.code == const.RECEIVING_COMPLETE_STATUS_KEY:
                inv_line.quantity = line.quantity
                inv_line.in_transit_quantity = 0
                inv_line.saleable_quantity = line.quantity
            elif self.status.code == const.RECEIVING_DRAFT_STATUS_KEY:
                inv_line.quantity = 0
                inv_line.saleable_quantity = 0
                inv_line.in_transit_quantity = line.quantity
            line.inventory_transaction_line = inv_line
        for line in inv_trans.lines:
            if line.itl_receiving_line is None:
                db.session.delete(line)
        return inv_trans
コード例 #10
0
        def test_logic():
            supplier = object_faker.supplier()
            db_util.save_objects_commit(supplier)
            self.assertPageRendered(endpoint=url_for('dpo.index_view'))
            self.assertPageRendered(endpoint=url_for('dpo.create_view'))
            draft_status = EnumValues.get(const.PO_DRAFT_STATUS_KEY)
            order_date = object_faker.faker.date_time_this_year()
            logistic_amount = random.randint(0, 100)
            remark = object_faker.faker.text(max_nb_chars=50)

            expect_content = [
                supplier.name, draft_status.display,
                str(logistic_amount),
                order_date.strftime("%Y-%m-%d"), remark
            ]
            self.assertPageRendered(
                method=self.test_client.post,
                data=dict(
                    supplier=supplier.id,
                    status=draft_status.id,
                    order_date=order_date,
                    logistic_amount=logistic_amount,
                    remark=remark),
                endpoint=self.create_endpoint(view='dpo'),
                expect_contents=expect_content)

            self.assertPageRendered(
                expect_contents=expect_content,
                endpoint=self.edit_endpoint(view='dpo'))

            new_remark = object_faker.faker.text(max_nb_chars=50)
            new_logistic_amount = random.randint(0, 100)
            new_order_date = object_faker.faker.date_time_this_year()
            new_expect_content = [
                supplier.name, draft_status.display,
                str(new_logistic_amount),
                new_order_date.strftime("%Y-%m-%d"), new_remark
            ]
            self.assertPageRendered(
                method=self.test_client.post,
                endpoint=self.edit_endpoint(view='dpo'),
                data=dict(
                    supplier=supplier.id,
                    status=draft_status.id,
                    order_date=new_order_date,
                    logistic_amount=new_logistic_amount,
                    remark=new_remark),
                expect_contents=new_expect_content)

            rv = self.assertPageRendered(
                method=self.test_client.post,
                endpoint=url_for('dpo.delete_view'),
                data=dict(url=url_for('dpo.index_view'), id='1'))
            self.assertNotIn(supplier.name.encode('utf-8'), rv.data)
            self.assertNotIn(draft_status.display.encode('utf-8'), rv.data)
            self.assertNotIn(new_order_date.strftime("%Y-%m-%d").encode('utf-8'), rv.data)
            self.assertNotIn(new_remark.encode('utf-8'), rv.data)
コード例 #11
0
        def test_logic():
            supplier = object_faker.supplier()
            db_util.save_objects_commit(supplier)
            self.assertPageRendered(endpoint=url_for('dpo.index_view'))
            self.assertPageRendered(endpoint=url_for('dpo.create_view'))
            draft_status = EnumValues.get(const.PO_DRAFT_STATUS_KEY)
            order_date = object_faker.faker.date_time_this_year()
            logistic_amount = random.randint(0, 100)
            remark = object_faker.faker.text(max_nb_chars=50)

            expect_content = [
                supplier.name, draft_status.display,
                str(logistic_amount),
                order_date.strftime("%Y-%m-%d"), remark
            ]
            self.assertPageRendered(method=self.test_client.post,
                                    data=dict(supplier=supplier.id,
                                              status=draft_status.id,
                                              order_date=order_date,
                                              logistic_amount=logistic_amount,
                                              remark=remark),
                                    endpoint=self.create_endpoint(view='dpo'),
                                    expect_contents=expect_content)

            self.assertPageRendered(expect_contents=expect_content,
                                    endpoint=self.edit_endpoint(view='dpo'))

            new_remark = object_faker.faker.text(max_nb_chars=50)
            new_logistic_amount = random.randint(0, 100)
            new_order_date = object_faker.faker.date_time_this_year()
            new_expect_content = [
                supplier.name, draft_status.display,
                str(new_logistic_amount),
                new_order_date.strftime("%Y-%m-%d"), new_remark
            ]
            self.assertPageRendered(method=self.test_client.post,
                                    endpoint=self.edit_endpoint(view='dpo'),
                                    data=dict(
                                        supplier=supplier.id,
                                        status=draft_status.id,
                                        order_date=new_order_date,
                                        logistic_amount=new_logistic_amount,
                                        remark=new_remark),
                                    expect_contents=new_expect_content)

            rv = self.assertPageRendered(method=self.test_client.post,
                                         endpoint=url_for('dpo.delete_view'),
                                         data=dict(
                                             url=url_for('dpo.index_view'),
                                             id='1'))
            self.assertNotIn(supplier.name.encode('utf-8'), rv.data)
            self.assertNotIn(draft_status.display.encode('utf-8'), rv.data)
            self.assertNotIn(
                new_order_date.strftime("%Y-%m-%d").encode('utf-8'), rv.data)
            self.assertNotIn(new_remark.encode('utf-8'), rv.data)
コード例 #12
0
 def type_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.INVENTORY_TRANSACTION_TYPE_KEY)
コード例 #13
0
ファイル: incoming.py プロジェクト: witchawat/psi
 def type_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.INCOMING_TYPE_KEY)
コード例 #14
0
ファイル: organization.py プロジェクト: vingodu/betterlifepsi
 def type_filter():
     from psi.app.models.enum_values import EnumValues
     from psi.app.const import ORGANIZATION_TYPE_KEY
     return EnumValues.type_filter(ORGANIZATION_TYPE_KEY)
コード例 #15
0
ファイル: receiving.py プロジェクト: witchawat/psi
 def status_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.RECEIVING_STATUS_KEY)
コード例 #16
0
ファイル: incoming.py プロジェクト: betterlife/psi
 def type_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.INCOMING_TYPE_KEY)
コード例 #17
0
 def can_edit(self, user=current_user):
     from psi.app.models import EnumValues
     draft_status = EnumValues.get(const.PO_DRAFT_STATUS_KEY)
     return self.status_id == draft_status.id
コード例 #18
0
 def type_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.INVENTORY_TRANSACTION_TYPE_KEY)
コード例 #19
0
ファイル: receiving.py プロジェクト: betterlife/psi
 def receiving_in_draft(self):
     from psi.app.models import EnumValues
     draft_status = EnumValues.get(const.RECEIVING_DRAFT_STATUS_KEY)
     return self.status_id == draft_status.id
コード例 #20
0
ファイル: purchase_order.py プロジェクト: betterlife/psi
 def status_option_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.PO_STATUS_KEY)
コード例 #21
0
ファイル: purchase_order.py プロジェクト: betterlife/psi
 def can_edit(self, user=current_user):
     from psi.app.models import EnumValues
     draft_status = EnumValues.get(const.PO_DRAFT_STATUS_KEY)
     return self.status_id == draft_status.id
コード例 #22
0
ファイル: purchase_order.py プロジェクト: betterlife/psi
 def can_delete(self):
     from psi.app.models import EnumValues
     draft_status = EnumValues.get(const.PO_DRAFT_STATUS_KEY)
     return self.status_id == draft_status.id
コード例 #23
0
ファイル: customer.py プロジェクト: betterlife/psi
 def level_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.CUSTOMER_LEVEL_KEY)
コード例 #24
0
ファイル: customer.py プロジェクト: betterlife/psi
 def join_channel_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.CUSTOMER_JOIN_CHANNEL_KEY)
コード例 #25
0
ファイル: receiving.py プロジェクト: betterlife/psi
 def status_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.RECEIVING_STATUS_KEY)
コード例 #26
0
ファイル: customer.py プロジェクト: witchawat/psi
 def join_channel_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.CUSTOMER_JOIN_CHANNEL_KEY)
コード例 #27
0
 def can_delete(self):
     from psi.app.models import EnumValues
     draft_status = EnumValues.get(const.PO_DRAFT_STATUS_KEY)
     return self.status_id == draft_status.id
コード例 #28
0
ファイル: receiving.py プロジェクト: witchawat/psi
 def receiving_in_draft(self):
     from psi.app.models import EnumValues
     draft_status = EnumValues.get(const.RECEIVING_DRAFT_STATUS_KEY)
     return self.status_id == draft_status.id
コード例 #29
0
 def status_option_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.PO_STATUS_KEY)
コード例 #30
0
ファイル: customer.py プロジェクト: witchawat/psi
 def level_filter():
     from psi.app.models.enum_values import EnumValues
     return EnumValues.type_filter(const.CUSTOMER_LEVEL_KEY)