1. 程式人生 > >odoo自動更新表中數據

odoo自動更新表中數據

too data font .sql info 復數 del 頁面 cti


這是追蹤信息用的查詢語句,__init__方法初始化作用

_order ="hpartner_id desc"
def init(self,cr):
tools.sql.drop_view_if_exists(cr, ‘cust_product_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_tmpl_id as productn, t3.cust_spec as cust_spec,t3.material as material ,
t4.id as name_uom, t0.custo_price as custo_price,t0.product_meno as product_meno ,t0.meno as meno
from product_custo_info t0
LEFT JOIN product_product t1 on t0.product_tmpl_id=t1.product_tmpl_id
LEFT JOIN product_template t3 on t3.id=t1.product_tmpl_id
LEFT JOIN res_partner t2 on t2.id=t0.hpartner_id
LEFT JOIN product_uom t4 on t3.uom_id=t4.id
)
""")



判斷是否有重復數據

def create(self, cr, uid, vals, context=None):
if context is None:
context = {}
code= vals.get(‘code‘,‘‘)
cr.execute("select id from res_partner where code=‘%s‘" %(code))
if cr.rowcount>0:
raise osv.except_osv(u‘提示‘,u"[客戶/供應商]此簡稱已經存在!")
xh=1
requirement_ids=vals.get(
‘requirement_ids‘)
if requirement_ids:
for rline in requirement_ids:
rline[2][‘sequence‘]=xh
xh=xh+1
ctx = dict(context or {}, mail_create_nolog=True)
new_id = super(product_template, self).create(cr, uid, vals, context=ctx)
return new_id

 

# 新加地方,執行動作找到對應頁面
def action_custorm_state(self, cr, uid, ids, context=None):
name=self.browse(cr,uid,ids[0],context=context).name
act_obj = self.pool.get(‘ir.actions.act_window‘)
mod_obj = self.pool.get(‘ir.model.data‘)
result = mod_obj.xmlid_to_res_id(cr, uid, ‘ks_sale.action_view_cust_product_info_tree‘,raise_if_not_found=True)
result = act_obj.read(cr, uid, [result], context=context)[0]
result[‘domain‘] = "[(‘hpartner_id‘,‘=‘,"+ str(ids[0]) +")]"
return result


odoo自動更新表中數據