zoukankan      html  css  js  c++  java
  • sql语句

    # 取单价为最近时间的单价
    sql="select price_unit from sale_price_list where partner_id=%d and product_id=%d order by write_date desc limit 1"%(partner_id,product_id)
    cr.execute(sql)

    delete from    stock_picking   where   picking_type_id='40' and state='done' ;
    #查询出销售订单的源单据是本外部订单的所有单据
    sql2=" UPDATE stock_picking SET state='cancel' where state='draft' and order_name='%s'"%(str(a))
    cr.execute(sql2)


     select t0.partner_id id,t0.partner_id,sum(t0.subtotal) alltotal,coalesce(t2.subtotal,0) dlvtotal,intotal,coalesce(t2.subtotal,0)-coalesce(intotal) uintotal from sale_origin t0
    left join (select partner_id,coalesce(sum(type*pay_total),0) intotal from partner_for_payment group by partner_id) t1 on t0.partner_id=t1.partner_id
    left join ( select t5.partner_id,sum(t4.total) as subtotal from (
    select t0.product_id,t1.order_name,sum((COALESCE(case when t0.location_id=get_warehouse_id('成品仓') then product_qty else -1*product_qty end,0))*t0.pprice) as total
    from stock_move t0
    left join stock_picking t1 on t0.picking_id=t1.id
    where t0.state='done'
    and ((t0.location_id=get_warehouse_id('成品仓') and t0.location_dest_id=get_warehouse_id('Customers'))
    or (t0.location_id=get_warehouse_id('Customers') and t0.location_dest_id=get_warehouse_id('成品仓')))
    group by t0.product_id,t1.order_name,t0.pprice
    ) as t4
    LEFT JOIN sale_origin t5 on t5.name=t4.order_name
    GROUP BY t5.partner_id )t2 on t2.partner_id=t0.partner_id
    where t0.state='confirm' group by t0.partner_id,t2.subtotal,t1.intotal
     
     
  • 相关阅读:
    keepalived安装
    Nginx学习笔记
    使用xhprof分析php性能
    使用 .bash_profile与.bashrc修改字符集
    Mysql分区简述
    c语言多线程队列读写
    setsockopt 设置 SO_LINGER 选项
    nginx配置rewrite
    使用PHP+ajax打造聊天室应用
    UDP/TCP通信小记
  • 原文地址:https://www.cnblogs.com/1314520xh/p/7150672.html
Copyright © 2011-2022 走看看