odoo之带出历史订单产品


这是在sale_origin中
下由两张单子{sale_origin_line和history_order}
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'客户单号'),
'hmemo':fields.char(u'备注'),
'hpacking_type1':fields.selection([(1,u'隔板'),(2,u'泡沫')],string=u'包装方式',),
'choice':fields.boolean(u'请选择'),
}




在sale_origin中写:
'history_order_line':fields.one2many('history.order','hpartner_id',  copy=True),



在.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>




# 输入客户带出它默认的发运方式和包装方式
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,t4.name 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 where t1.partner_id is not null and t0.name='%s'"%(khmc)

print 555555555555555555555
history_line=[]

遍历将数据打印到前端
for i in range(len(dict)):
print dict[i]
# history_line=[]
history_line.append({'hproduct_id':dict[i]['product_id'] ,
'hmaterial':dict[i]['material'],
'hspec':dict[i]['cust_spec'],
'hproduct_uom':dict[i]['uom'],
'hprice':dict[i]['price'],
'hpacking_type1':dict[i]['pick_type']
})
result['history_order_line']=history_line
print 1111111111111111111111111111111111111111
print history_line
return {'value':result}










如图中 根据客户名称带出历史订单产品
posted @ 2017-05-18 21:03  何双新  阅读(859)  评论(0编辑  收藏  举报