函数中应用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.execute
cr.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)) )
""")

 

python中的 sql语句用法的更多相关文章

  1. Mybatis中动态SQL语句中的parameterType不同数据类型的用法

    Mybatis中动态SQL语句中的parameterType不同数据类型的用法1. 简单数据类型,    此时#{id,jdbcType=INTEGER}中id可以取任意名字如#{a,jdbcType ...

  2. 详解Python中的循环语句的用法

    一.简介 Python的条件和循环语句,决定了程序的控制流程,体现结构的多样性.须重要理解,if.while.for以及与它们相搭配的 else. elif.break.continue和pass语句 ...

  3. Python中防止sql注入的方法详解

    SQL注入是比较常见的网络攻击方式之一,它不是利用操作系统的BUG来实现攻击,而是针对程序员编程时的疏忽,通过SQL语句,实现无帐号登录,甚至篡改数据库.下面这篇文章主要给大家介绍了关于Python中 ...

  4. 在mybatis中写sql语句的一些体会

    本文会使用一个案例,就mybatis的一些基础语法进行讲解.案例中使用到的数据库表和对象如下: article表:这个表存放的是文章的基础信息 -- ------------------------- ...

  5. 在Excel中使用SQL语句查询和筛选

    本文转自:http://blog.sina.com.cn/s/blog_5fc375650102e1g5.html 今天在微博上看到@数据分析精选 分享的一篇文章,是关于<在Excel中使用SQ ...

  6. EF中执行sql语句,以及事务

    EF to sql string sql = "select T_Task.BSID,T_Task.CloseDate,T_Task.CompleteDate,T_Task.CloseUse ...

  7. [转]在EntityFramework6中执行SQL语句

    本文转自:http://www.cnblogs.com/wujingtao/p/5412329.html 在上一节中我介绍了如何使用EF6对数据库实现CRDU以及事务,我们没有写一句SQL就完成了所有 ...

  8. 在EntityFramework6中执行SQL语句

    在EntityFramework6中执行SQL语句 在上一节中我介绍了如何使用EF6对数据库实现CRDU以及事务,我们没有写一句SQL就完成了所有操作.这一节我来介绍一下如何使用在EF6中执行SQL语 ...

  9. 在phpmyadmin中执行sql语句出现的错误:Unknown storage engine 'InnoDB'

    在phpmyadmin中执行sql语句出现的错误:Unknown storage engine 'InnoDB' 解决方法:解决方法:             1.关闭MySQL数据库       2 ...

随机推荐

  1. BZOJ4259: 残缺的字符串(FFT 字符串匹配)

    题意 题目链接 Sol 知道FFT能做字符串匹配的话这就是个裸题了吧.. 考虑把B翻转过来,如果\(\sum_{k = 0}^M (B_{i - k} - A_k)^2 * B_{i-k}*A_k = ...

  2. 03--css形状--css揭秘

    形状 一 自适应的椭圆 1.难题 1> 圆 你可能注意到过, 给任何正方形元素设置一个足够大的border-radius, 就可以把它变成一个圆形.所用到的CSS 代码如下所示: #bd { w ...

  3. Android滑动菜单使用(MenuDrawer和SlidingMenu)

    项目地址: https://github.com/gokhanakkurt/android-menudrawer   https://github.com/jfeinstein10/SlidingMe ...

  4. Kotlin入门(17)等式判断的情况

    话说等式可是编程语言最基本的表达式之一,不管哪种高级语言,无一例外都采用双等号“==”判断两个变量是否相等:就算是复杂的对象,在Java中也可通过equals函数判断两个实例是否相等.按理说这些能够满 ...

  5. [20170825]11G备库启用DRCP连接3.txt

    [20170825]11G备库启用DRCP连接3.txt --//昨天测试了11G备库启用DRCP连接,要设置alter system set audit_trail=none scope=spfil ...

  6. javascript避免dom事件重复触发

    /** * 为指定控件添加限制性事件, 该事件在触发之后, 会被移除, 并在指定的时间间隔后, 重新绑定, 适用于避免控件事件被误操作重复触发的场景 * @param {String} domID 要 ...

  7. CSS| 框模型-輪廓

    轮廓(outline)是绘制于元素周围的一条线,位于边框边缘的外围,可起到突出元素的作用.CSS outline 属性规定元素轮廓的样式.颜色和宽度. 相關屬性 outline-color 属性 ou ...

  8. 深度学习word embedding猜测性别初探

    根据用户的一些特征数据,如果能推测出用户的性别借此提高产品的服务质量.广告的精准性等都是极好的. 机器学习方法有很多,而且一般都可以达到不错的效果,比如svm或神经网络等. 本文使用的代码参考——&l ...

  9. 最大公约数&&最小公倍数

    //最大公约数(greatest common divisor),运用递归 int gcd(int a,int b){//注意a要求大于b return !b?a:gcd(b,a%b); } //最小 ...

  10. java 封装及this 用法

    封装:主要用于将类中的成员名(类变量)通过 private关键字进行访问权限的设定,使用 private后,成员变量只能在当前类中进行访问,超过该类时访问提示不存在,当然也可以用于方法中,但较少.如果 ...