1.  
  1. 函数中应用sql语句
    def _get_cust_number(self,cr,uid,ids,field_name,args,context=None):
  2. res={}
  3. for order in self.browse(cr, uid, ids, context=context):
  4. #获取单据信息
    aa=order.origin
  5. if aa:
  6. 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)
  7. cr.execute(sql)
  8. dict4=cr.dictfetchall()
  9. if dict4:
  10. dd=dict4[0]['cust_numr_no']
  11. res[order.id]=dd
  12. else:
  13. res[order.id]=''
  14. else:
  15. res[order.id]=''
  16. return res
  1.  

或者着一种

  1. 函数中另外一种写法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
  2. stock_ynum t0 left join stock_fah t1 on t0.picking_id=t1.id
  3. 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')
  4. and t0.location_dest_id=get_warehouse_id('成仓')))
  5. or ((t0.location_id=get_warehouse_id('原仓')
  6. 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('原仓')))
  7. group by t0.product_id,ref_num,ref_line_id)t where ref_line_id in %s''',(tuple(ids),))
  8. jhqty = dict(cr.fetchall())

或者创建views

  1.  
  1. 初始化执行的函数:创建一个视图,用sql语句 ,紫色为sql语句
  2.  
  3. def init(self,cr):
  4. tools.sql.drop_view_if_exists(cr, 'cust_cp_info_report')
  5. cr.execute("""
  6. create or replace view cust_product_info_report as (
  7. select t0.id,t0.hpartner_id as hpartner_id, t0.khwl_code as khwl_code,t1.product_mp_id as productn,
  8. t3.pname,t3.mmar,t3.spec,
  9. 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
  10. from product_custo_info t0
  11. LEFT JOIN product_order t1 on t0.product_tmpl_id=t1.product_tmpl_id
  12. LEFT JOIN product_model t3 on t3.id=t1.product_tmpl_id
  13. LEFT JOIN ke_partner t2 on t2.id=t0.hpartner_id
  14. LEFT JOIN product_dan t4 on t3.uom_id=t4.id
  15. left join partner_cp_price t5 on t5.ppp_line_id=t0.id
  16. where (now()>=t5.date_from and now()<=t5.date_to) or (t5.date_from is null and t5.date_to is null ) or
  17. (t5.date_from is null and (now()<=t5.date_to)) or (t5.date_to is null and (now()>=t5.date_from))
  18. )
  19. """)
  1.  
  1.  

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. 前端周报:前端面试题及答案总结;JavaScript参数传递的深入理解

    1.2017前端面试题及答案总结 |掘金技术征文 "金三银四,金九银十",用来形容求职最好的几个月.但是随着行业的饱和,初中级前端er就业形势不容乐观. 行业状态不可控,我们能做的 ...

  2. Stackoverflow 珠玑:C#封装重试指定次数的功能

    最近写的一个 .NET Core 爬虫里用到了需要多次重试的功能,本着无脑输出的精神,google 了一下,还真给我找到了: public static T Retry<T, TExceptio ...

  3. 【转】巧用DOS tree命令+批处理 实现 指定文件 批量复制!

    转自:http://www.cnblogs.com/looky/archive/2010/01/24/1655292.html 今天一朋友叫我帮忙解决指定文件批量复制的问题,于是找了一大堆批处理命令, ...

  4. NoHttp封装--01

    NoHttpActivity public class NoHttpActivity extends Activity implements View.OnClickListener { privat ...

  5. Redis系列(一):Redis的简介与安装

    原文链接(转载请注明出处):Redis系列(一):Redis的简介与安装 什么是 Redis Redis 是一个使用ANSI C 编写的开源.支持网络协议.基于内存.可选持久性的键值对数据库,它是一个 ...

  6. 洗礼灵魂,修炼python(34)--面向对象编程(4)—继承

    前面已经说到面向对象编程有封装,继承,多态三大特性,那么其中的继承则很重要,可以直接单独的拿出来解析 继承 1.什么是继承: 字面意是子女继承父母的家产或者特性等.而在编程里继承是指子类继承父类(基类 ...

  7. Column Index out of range, 2 > 1 列索引的范围,2 > 1。

    Column Index out of range, 2 > 1  列索引的范围,2 > 1.这个问题是进行数据库查询的时候出现的. 因为查询sql语句时 只查询了 name 然后whil ...

  8. SQL 三范式

    第一范式:无重复的列,一列只能包含一个字段 第二范式:主键约束,一行只能被唯一标识 第三范式:非主键字段要严格依赖于主键字段

  9. Linux 小知识翻译 - 「Linux」怎么读?

    主要讨论日语中的读法,所以没有完全按照原文来翻译. 「linux」的读法有很多(这里指在日语中),代表性的读法有以下几种: A). 李纳苦思 B). 李奴苦思 C). 纳依纳苦思 A和B相同的是将 l ...

  10. hubilder打包+C#服务端个推服务实现

    关于推送鼓捣了好长时间,这里不再写helloworld了,只讲里面遇到的问题. 1.关于苹果开发者平台上的注册 网上很多的教程,只要按照步骤来设置就行了,在 iOS证书(.p12)和描述文件(.mob ...