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
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
def adjust_product_quantity(product, date, quantity, price, type_code): from psi.app.models import InventoryTransactionLine, InventoryTransaction, EnumValues it = InventoryTransaction() it.date = date it.type = EnumValues.get(type_code) itl = InventoryTransactionLine() itl.quantity = quantity itl.product_id = product.id itl.inventory_transaction = it itl.price = price if product.inventory_transaction_lines is None: product.inventory_transaction_lines = [itl] else: product.inventory_transaction_lines.append(itl)
def create_or_update_inventory_transaction(shipping, shipping_line, it_type): if shipping.inventory_transaction is not None: it = shipping.inventory_transaction else: it = InventoryTransaction() it.organization_id = current_user.organization_id it.date = shipping.date shipping.inventory_transaction = it it.type = it_type it_line = None existing = False for it_line in it.lines: if it_line.itl_shipping_line.sales_order_line.external_id == shipping_line.sales_order_line.external_id: existing = True break if not existing: it_line = InventoryTransactionLine() it_line.inventory_transaction = it shipping_line.inventory_transaction_line = it_line it_line.quantity = -shipping_line.quantity it_line.product = shipping_line.product it_line.price = shipping_line.price return it, it_line
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