1. 程式人生 > >odoo開發歷史訂單需求整體思路

odoo開發歷史訂單需求整體思路

any rip clas num chang hist 不能 要求 lis

第一步:找到客戶對應頁面,並找到他所下過的銷售訂單,用數據庫語句查出所有數據,並去除重復數據,顯示在前端,

sql="select DISTINCT t2.product_id as product_id, t6.material as material,t6.cust_spec as cust_spec,t6.list_price as price,
t2.product_uom as uom, t3.packing_type1 as pick_type from res_partner t0 LEFT JOIN sale_order t1
on t0.id=t1.partner_id LEFT JOIN sale_order_line t2 on t2.order_id=t1.id LEFT JOIN sale_origin_line t3 on
t2.order_id=t3.order_id LEFT JOIN product_uom t4 on t4.id=t2.product_uom left join product_product t5 on
t5.id=t2.product_id left join product_template t6 on t6.id=t5.product_tmpl_id LEFT JOIN customer_requirement t7
on t7.partner_id=t0.id where t1.partner_id is not null and t0.name=‘%s‘"%(khmc)
cr.execute(sql)

根據客戶名稱來查:



第二步:新加一個頁簽,用來存放歷史訂單數據,方便人們看到:
sale_origin.py文件
‘history_order_line‘:fields.one2many(‘history.order‘,‘hpartner_id‘, ‘history order‘, copy=True),

#
class history_order(osv.osv):
_name="history.order"
_description="history order line "
_columns={
‘hpartner_id‘:fields.many2one(‘sale.origin‘, u‘客戶‘),
‘hproduct_id‘:fields.many2one(‘product.product‘,u‘產品‘),
‘hmaterial‘: fields.related(‘product_id‘, ‘material‘,relation=‘product.product‘, type="char", string=u‘品名/材質‘,readonly=True,),
‘hspec‘: fields.related(‘product_id‘, ‘cust_spec‘,relation=‘product.product‘, type="char", string=u‘規格‘,readonly=True,),
‘hproduct_uom‘: fields.many2one(‘product.uom‘,u‘單位‘),
‘hprice‘:fields.float(u‘單價‘,digits=(6,3)),
‘hcust_order_no‘:fields.char(u‘客戶單號‘),
‘requirement_text‘:fields.text(string=u"要求"),
‘hmemo‘:fields.char(u‘備註‘),
‘hpacking_type1‘:fields.selection([(1,u‘隔板‘),(2,u‘泡沫‘)],string=u‘包裝方式‘,),
‘choice‘:fields.boolean(u‘請選擇‘),
}
.xml文件
<!--<page string="歷史訂單">-->
<!--<field name="history_order_line">-->
<!--<header>-->
<!--<button name="action_confirm_all_sale_order" string="確認" type="object" />-->
<!--</header>-->
<!--<tree>-->
<!--<field name="hproduct_id" />-->
<!--<field name="hmaterial"/>-->
<!--<field name="hspec"/>-->
<!--<field name="hprice" />-->
<!--<field name="hproduct_uom"/>-->
<!--<field name="hpacking_type1"/>-->
<!--<field name="choice"/>-->
<!--</tree>-->
<!--</field>-->
<!--</page>-->



第三步:
另一種做法,就是直接加到明細表中:可選可刪除

1,這是選擇客戶後,帶出數據
# 輸入客戶帶出它默認的發運方式和包裝方式
def on_change_partner_id_return(self,cr,uid,ids,partner_id,context=None):
result={}
if partner_id:# 如果存在
#找到滿足條件的值
obj=self.pool.get(‘res.partner‘).browse(cr,uid,partner_id,context=context)
#取出數據顯示在前端
fyfs=obj.send_type
zxbzfs=obj.packing_type
khmc=obj.name
# 返回結果
result[‘send_invoice_type‘]=fyfs
result[‘packing_type‘]=zxbzfs
print khmc
# 根據客戶,查詢出所有歷史訂單產品,並去除重復數據.
sql="select DISTINCT t2.product_id as product_id, t6.material as material,t6.cust_spec as cust_spec,t6.list_price as price,t2.product_uom as uom, t3.packing_type1 as pick_type from res_partner t0 LEFT JOIN sale_order t1 on t0.id=t1.partner_id LEFT JOIN sale_order_line t2 on t2.order_id=t1.id LEFT JOIN sale_origin_line t3 on t2.order_id=t3.order_id LEFT JOIN product_uom t4 on t4.id=t2.product_uom left join product_product t5 on t5.id=t2.product_id left join product_template t6 on t6.id=t5.product_tmpl_id LEFT JOIN customer_requirement t7 on t7.partner_id=t0.id where t1.partner_id is not null and t0.name=‘%s‘"%(khmc)
cr.execute(sql)
dict=cr.dictfetchall()
order_line_id=[]
# 遍歷打印出所有訂單記錄
for i in range(len(dict)):
print dict[i]
# 將所有記錄放入到歷史訂單表中
order_line_id.append({‘product_id‘:dict[i][‘product_id‘],
‘pname‘:dict[i][‘material‘],
‘spec‘:dict[i][‘cust_spec‘],
‘product_uom‘:dict[i][‘uom‘],
‘price‘:dict[i][‘price‘],
‘packing_type1‘:dict[i][‘pick_type‘]
})
result[‘line_id‘]=order_line_id
return {‘value‘:result}

2,這是可選擇,可刪除,可新建,
點擊
保存按鈕
後的數據
def create(self,cr,uid,vals,context=None):

if context is None:
context ={}
if vals.get(‘name‘,‘/‘)==‘/‘:
vals[‘name‘]=self.pool.get(‘ir.sequence‘).get(cr,uid,‘sale.origin‘) or ‘/‘
ctx=dict(context or {},mail_create_nolog=True)
#如果存在這個字段 則不處理 反之 刪除本元素
flagline=vals
print vals
print flagline
linenum=len(vals.get(‘line_id‘))
new_line_id=[]
# for 循環遍歷出所有的數據,再將滿足條件數據放到一個新的數組裏,重新賦值給輸出變量,linenum固定長度
for i in range(linenum):
if ‘choice‘ in vals.get(‘line_id‘)[i][2]:
new_line_id.append(vals.get(‘line_id‘)[i])
print new_line_id
vals[‘line_id‘]=new_line_id
print vals.get(‘line_id‘)

new_id=super(sale_origin,self).create(cr,uid,vals,context=ctx)

#########zxs beign 增加關註者 這裏依賴於od-oa模塊
res_model=self._name
obj=self.pool.get(‘od.oa.add.user‘)
obj.add_follower_ids(cr,uid,res_model,new_id)
return new_id
當我們不能直接遍歷,刪除數據,我們可以換一個思路.就是
將數據保存到數組,直接把結果保存下來,不會時可以將數據打印出來,然後進行下一步操作


這就是整體思路




odoo開發歷史訂單需求整體思路