第一步:找到客户对应页面,并找到他所下过的销售订单,用数据库语句查出所有数据,并去除重复数据,显示在前端,
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)
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
当我们不能直接遍历,删除数据,我们可以换一个思路.就是
将数据保存到数组,直接把结果保存下来,不会时可以将数据打印出来,然后进行下一步操作
这就是整体思路
心有猛虎,细嗅蔷薇