python中的 sql语句用法(python中的数据类型有哪些)

网友投稿 261 2022-08-29


python中的 sql语句用法(python中的数据类型有哪些)

函数中应用sql语句def _get_cust_number(self,cr,uid,ids,field_name,args,context=None): res={} for order in self.browse(cr, uid, ids, context=context): #获取单据信息 aa=order.origin if aa: sql="select t1.cust_numr_no from stock_fah t0 left join sale_orde t1 on t0.origin=t1.name where t0.origin='%s'"%(aa) cr.execute(sql) dict4=cr.dictfetchall() if dict4: dd=dict4[0]['cust_numr_no'] res[order.id]=dd else: res[order.id]='' else: res[order.id]='' return res

或者着一种

函数中另外一种写法cr.executecr.execute('''select ref_line_id,nolqty from( select ref_line_id,sum(COALESCE(case when t0.location_id=get_warehouse_id('成仓') then product_qty when t0.location_id=get_warehouse_id('原仓') then product_qty else -1*product_qty end,0) ) dlvqty from stock_ynum t0 left join stock_fah 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('成仓'))) or ((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,ref_num,ref_line_id)t where ref_line_id in %s''',(tuple(ids),)) jhqty = dict(cr.fetchall())

或者创建views

初始化执行的函数:创建一个视图,用sql语句 ,紫色为sql语句def init(self,cr): tools.sql.drop_view_if_exists(cr, 'cust_cp_info_report') cr.execute(""" create or replace view cust_product_info_report as ( select t0.id,t0.hpartner_id as hpartner_id, t0.khwl_code as khwl_code,t1.product_mp_id as productn, t3.pname,t3.mmar,t3.spec, t4.id as name_uom, t5.price as custo_price,t0.product_meno as product_meno ,t0.meno as meno,t5.date_from,t5.date_to from product_custo_info t0 LEFT JOIN product_order t1 on t0.product_tmpl_id=t1.product_tmpl_id LEFT JOIN product_model t3 on t3.id=t1.product_tmpl_id LEFT JOIN ke_partner t2 on t2.id=t0.hpartner_id LEFT JOIN product_dan t4 on t3.uom_id=t4.id left join partner_cp_price t5 on t5.ppp_line_id=t0.id where (now()>=t5.date_from and now()<=t5.date_to) or (t5.date_from is null and t5.date_to is null ) or (t5.date_from is null and (now()<=t5.date_to)) or (t5.date_to is null and (now()>=t5.date_from)) ) """)

心有猛虎,细嗅蔷薇


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Java实现为Word每一页设置不同图片水印的效果
下一篇:python中的abstractmethod(python中的//是什么意思)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~