Beispiel #1
0
 def is_po_line_exists(self, po_num, po_line_num):
     existing_order = get_by_external_id(SalesOrder, po_num)
     if existing_order is not None:
         for line in existing_order.lines:
             if line.external_id == po_line_num:
                 return True
     return False
Beispiel #2
0
def create_or_update_product(prd_num, prd_name, prd_mem, pur_price, ret_price, supplier):
    prd = get_by_external_id(Product, prd_num)
    if prd is None:
        prd = get_by_name(Product, prd_name)
        if prd is None:
            prd = Product()
            prd.external_id = prd_num
            prd.deliver_day = current_app.config.get('DEFAULT_DELIVER_DAY')
            prd.lead_day = current_app.config.get('DEFAULT_LEAD_DAY')
            prd.category_id = current_app.config.get('DEFAULT_CATEGORY_ID')
            prd.organization_id = current_user.organization_id
            prd.name = prd_name
            prd.mnemonic = prd_mem
            prd.purchase_price = pur_price
            prd.retail_price = ret_price
            prd.supplier = supplier
            db.session.add(prd)
    return prd
Beispiel #3
0
def create_or_update_supplier(sup_num, sup_name, mem, contact, address,
                              email, phone, mobile,
                              remark, mobile2,
                              acct_name, acct_no):

    def concat(current_val, format_str, new_val):
        if new_val != '':
            val = format_str.format(new_val)
            if current_val == '':
                current_val += val
            else:
                current_val += ", " + val
        return current_val

    supplier = get_by_external_id(Supplier, sup_num)
    if supplier is None:
        supplier = get_by_name(Supplier, sup_name)
        if supplier is None:
            supplier = Supplier()
            supplier.organization_id = current_user.organization_id
            supplier.external_id = sup_num
            supplier.name = sup_name
            # TODO.xqliu Change this remark calculate to a reduce
            supplier.remark = concat('', "手机: {0}", mobile)
            supplier.remark = concat(supplier.remark, "手机2: {0}", mobile2)
            supplier.remark = concat(supplier.remark, "地址: {0}", address)
            supplier.remark = concat(supplier.remark, "备注: {0}", remark)
            supplier.contact = contact
            supplier.email = email
            supplier.phone = phone
            supplier.mnemonic = mem
            if acct_name is not None and acct_no is not None:
                pm = PaymentMethod()
                pm.account_name = acct_name
                pm.account_number = acct_no
                pm.bank_name = '-'
                pm.supplier = supplier
            db.session.add(supplier)
    return supplier
Beispiel #4
0
def create_or_update_sales_order(po_num, po_line_num, product, act_price, qty, sale_date):
    order = get_by_external_id(SalesOrder, po_num)
    if order is None:
        order = SalesOrder()
        order.external_id = po_num
        order.logistic_amount = 0
        order.organization_id = current_user.organization_id
    order.order_date = sale_date
    order.type = EnumValues.get(const.DIRECT_SO_TYPE_KEY)
    order.status = EnumValues.get(const.SO_DELIVERED_STATUS_KEY)
    existing = False
    line = None
    for line in order.lines:
        if line.external_id == po_line_num:
            existing = True
            break
    if not existing:
        line = SalesOrderLine()
        line.sales_order = order
        line.external_id = po_line_num
    line.unit_price = act_price
    line.quantity = qty
    line.product = product
    return order, line