Rev 20025 | Blame | Compare with Previous | Last modification | View Log | RSS feed
'''Created on 29-Jul-2011@author: Chandranshu'''from elixir.entity import Entityfrom elixir.fields import Fieldfrom elixir.options import using_options, using_table_optionsfrom elixir.relationships import OneToManyfrom shop2020.purchase.main.model.LineItem import LineItemfrom shop2020.thriftpy.purchase.ttypes import PurchaseOrder as TPurchaseOrder, \POStatusfrom shop2020.utils.Utils import to_java_datefrom sqlalchemy.types import Integer, String, Float, DateTime, Enumimport datetimeimport timeclass PurchaseOrder(Entity):'''classdocs'''id = Field(Integer, primary_key=True, autoincrement=True)poNumber = Field(String(20))supplierId = Field(Integer)buyerId = Field(Integer)warehouseId = Field(Integer)warehouseAddressId = Field(Integer)shippingWarehouseId = Field(Integer)shippingWarehouseAddressId = Field(Integer)status = Field(Integer)createdAt = Field(DateTime)updatedAt = Field(DateTime)totalCost = Field(Float)freightCharges = Field(Float)realizedCost = Field(Float)realizedFreightCharges = Field(Float)type = Field(Enum('REAL', 'VIRTUAL'), default = 'REAL', server_default='REAL')taxType = Field(Integer)lineitems = OneToMany("LineItem")purchases = OneToMany("Purchase")using_options(shortnames=True)using_table_options(mysql_engine="InnoDB")def __init__(self, t_purchase_order):'''Constructor'''#Generate the poNumberself.supplierId = t_purchase_order.supplierIdself.warehouseId = t_purchase_order.warehouseIdif t_purchase_order.shippingWarehouseId:self.shippingWarehouseId = t_purchase_order.shippingWarehouseIdelse:self.shippingWarehouseId = t_purchase_order.warehouseId#TODO: This should be INIT. Category manager should review and mark it as ready.self.status = POStatus.READYself.createdAt = datetime.datetime.now()self.totalCost = t_purchase_order.totalCostself.freightCharges = t_purchase_order.freightCharges or 0self.realizedCost = 0self.realizedFreightCharges = 0if t_purchase_order.lineitems:for t_lineitem in t_purchase_order.lineitems:if t_lineitem.quantity == 0:t_purchase_order.lineitems.pop(t_purchase_order.lineitems.index(t_lineitem))self.lineitems = [LineItem(self, t_lineitem) for t_lineitem in t_purchase_order.lineitems]self.totalCost = sum([t_lineitem.quantity * t_lineitem.unitPrice for t_lineitem in t_purchase_order.lineitems])self.type = t_purchase_order.typeself.poNumber = t_purchase_order.poNumberself.taxType = t_purchase_order.taxTypeself.buyerId = t_purchase_order.buyerIdself.warehouseAddressId = t_purchase_order.warehouseAddressIdself.shippingWarehouseAddressId = t_purchase_order.shippingWarehouseAddressIddef to_thrift_object(self):t_purchase_order = TPurchaseOrder()t_purchase_order.id = self.idt_purchase_order.poNumber = self.poNumbert_purchase_order.supplierId = self.supplierIdt_purchase_order.warehouseId = self.warehouseIdt_purchase_order.warehouseAddressId = self.warehouseAddressIdt_purchase_order.shippingWarehouseId = self.shippingWarehouseIdt_purchase_order.shippingWarehouseAddressId = self.shippingWarehouseAddressIdt_purchase_order.status = self.statust_purchase_order.createdAt = to_java_date(self.createdAt)if self.updatedAt:t_purchase_order.updatedAt = to_java_date(self.updatedAt)t_purchase_order.totalCost = self.totalCostt_purchase_order.freightCharges = self.freightChargest_purchase_order.realizedCost = self.realizedCostt_purchase_order.realizedFreightCharges = self.realizedFreightChargest_purchase_order.lineitems = [lineitem.to_thrift_object() for lineitem in self.lineitems]t_purchase_order.taxType = self.taxTypet_purchase_order.buyerId = self.buyerIdreturn t_purchase_orderdef set_po_number(self):#Changed from SORL to PO after discussion from Rajneeshself.poNumber = "PO/" + time.strftime("%m-%y") + "/" + str(self.id)