博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
(54) 记录销售单修改详细
阅读量:6678 次
发布时间:2019-06-25

本文共 9088 字,大约阅读时间需要 30 分钟。

这个功能主要用于销售订单的反流程,比如采购、销售审核了订单,但这时你要申请修改,

修改的详细就要记录,提交去审核,采购、销售经理才知道你改了什么地方。

难点:

1. 你设置了一个字段记录销售单申请前核心字段的信息,用什么方式存

2. 当销售员在改单后,保存时,同时要对比改动了什么地方做记录,这里人强制刷缓存

否则在删除了销售明细时,你做记录时就报错,One of the documents you are trying to access has been deleted … 这是缓存引起的,若不记录,修改保存记录时,系统会自动刷新,可是保存的同时,你还要做记录修改详细,此时一个动作还没有完成,就无法自动刷新缓存

效果图:

基于反流程比较复杂,这里只讲如何保存修改记录

设置字段

class SaleOrder(models.Model):     _inherit = 'sale.order'

apply_modify_old = fields.Text(string='Apply Modify Old', readonly=True)

apply_modify_detail = fields.Text(string='Apply Modify Detail',readonly=True)

写提出申请时记录初始记录

@api.one def action_apply_modify_cancel(self):      self.is_apply_modify = True      if self.apply_type =='modify' and self.apply_is_refused == False:          apply_modify_old ={
             'name':self.name,              'partner_id': self.partner_id.id,              'partner_shipping_id':self.partner_shipping_id.id,              'date_order':self.date_order,              'pricelist_id':self.pricelist_id.id,              'order_policy':self.order_policy,              'picking_policy': self.picking_policy,          }          if self.order_line:              line_dict={}              for line in self.order_line:                  line_dict[line.id] = {
                         'product_id': line.product_id.id,                          'price_unit':line.price_unit,                          'product_uom':line.product_uom.id,                          'product_uom_qty':line.product_uom_qty,                          'lot_id':line.lot_id.id,                          'unlimited_dis':line.unlimited_dis,                          'special_dis':line.special_dis,                          'th_weight':line.th_weight                          }              apply_modify_old['order_line'] = line_dict          self.apply_modify_old =json.dumps(apply_modify_old)
我这里把字典转为json放在数据中
下面给出销售员修改订单时方法记录:
def update_apply_modify_detail(self):      values = {}      apply_modify_detail = ''      order_policy_zh={
'prepaid':u'基于发货前','manual':u'基于销售订单'}      picking_policy_zh = {
'one': u'整批发货', 'direct': u'分批发货'}      old= self.apply_modify_old and json.loads(self.apply_modify_old) or None      if old:          if old.get('name') and old.get('name') !=self.name:              apply_modify_detail += '销售订单:' + old.get('name') + ' -> ' + self.name + '\r\n'          if old.get('partner_id') and old.get('partner_id') !=self.partner_id.id:              apply_modify_detail += '客户:' + self.env['res.partner'].browse(                  old.get('partner_id')).name_get()[0][1] + ' -> ' + self.partner_id.name_get()[0][1]+ '\r\n'          if old.get('partner_shipping_id') and old.get('partner_shipping_id') !=self.partner_shipping_id.id:              apply_modify_detail += '发货地址:' + self.env['res.partner'].browse(                  old.get('partner_shipping_id')).name_get()[0][1] + ' -> ' + self.partner_shipping_id.name_get()[0][1]+ '\r\n'          if old.get('date_order') and old.get('date_order') !=self.date_order:              apply_modify_detail += '订单日期:' + old.get('date_order')+ ' -> ' + self.date_order + '\r\n'          if old.get('pricelist_id') and old.get('pricelist_id') !=self.pricelist_id.id:              apply_modify_detail += '价格表:' + self.env['product.pricelist'].browse(                  old.get('pricelist_id')).name_get()[0][1] + ' -> ' + self.pricelist_id.name_get()[0][1] + '\r\n'          if old.get('order_policy') and old.get('order_policy') !=self.order_policy:              apply_modify_detail += '开票策略:' + order_policy_zh.get(                  old.get('order_policy'))+ ' -> ' + order_policy_zh.get(self.order_policy) + '\r\n'          if old.get('picking_policy') and old.get('picking_policy') !=self.picking_policy:              apply_modify_detail += '发货策略:' + picking_policy_zh.get(                  old.get('picking_policy'))+ ' -> ' + picking_policy_zh.get(self.picking_policy) + '\r\n'          order_line_old = old.get('order_line') and  old.get('order_line') or {}          line_modify = ''          if self.order_line:              for line in self.order_line:                  if order_line_old.get(str(line.id)):                      modify=False                      old_line = order_line_old.get(str(line.id))                      if line.product_id.id != old_line.get('product_id'):                          line_modify += "修改明细:" +str(line.id) +'[' + line.product_id.name_get()[0][1] + ']:'                          line_modify += " | 产品:"+ self.env['product.product'].browse(old_line.get('product_id')).name_get()[0][1]+' -> '+line.product_id.name_get()[0][1]                          modify = True                      if line.price_unit != old_line.get('price_unit'):                          if not modify:                              line_modify += "修改明细:" + str(line.id) + '[' + line.product_id.name_get()[0][1] + ']:'                          line_modify += " | 单价:" + str(old_line.get('price_unit')) + ' -> ' + str(line.price_unit)                          modify = True                      if line.product_uom.id != old_line.get('product_uom'):                          if not modify:                              line_modify += "修改明细:" + str(line.id) + '[' + line.product_id.name_get()[0][1] + ']:'                          line_modify += " | 计量单位:" + self.env['product.uom'].browse(old_line.get(                              'product_uom')).name_get()[0][1] + ' -> ' + line.product_uom.name_get()[0][1]                          modify = True                      if line.product_uom_qty != old_line.get('product_uom_qty'):                          if not modify:                              line_modify += "修改明细:" + str(line.id) + '[' + line.product_id.name_get()[0][1] + ']:'                          line_modify += " | 数量:" + str(old_line.get('product_uom_qty')) + ' -> ' + str(line.product_uom_qty)                          modify = True                      if line.lot_id.id != old_line.get('lot_id'):                          if not modify:                              line_modify += "修改明细:" + str(line.id) + '[' + line.product_id.name_get()[0][1] + ']:'                          line_modify += " | 序列号:" + self.env['stock.production.lot'].browse(old_line.get(                              'lot_id')).name_get()[0][1] + ' -> ' + line.lot_id.name_get()[0][1]                          modify = True                      if line.unlimited_dis != old_line.get('unlimited_dis'):                          if not modify:                              line_modify += "修改明细:" + str(line.id) + '[' + line.product_id.name_get()[0][1] + ']:'                          line_modify += " | 突破限价:" + str(old_line.get('unlimited_dis')) + ' -> ' + str(line.unlimited_dis)                          modify = True                      if line.special_dis != old_line.get('special_dis'):                          if not modify:                              line_modify += "修改明细:" + str(line.id) + '[' + line.product_id.name_get()[0][1] + ']:'                          line_modify += " | 特殊折扣:" + str(old_line.get('special_dis')) + ' -> ' + str(line.special_dis)                          modify = True                      if line.th_weight != old_line.get('th_weight'):                          if not modify:                              line_modify += "修改明细:" + str(line.id) + '[' + line.product_id.name_get()[0][1] + ']:'                          line_modify += " | 重量:" + str(old_line.get('th_weight')) + ' -> ' + str(line.th_weight)                      if modify:                          line_modify += '\r\n'                      order_line_old.pop(str(line.id))                  else:                      line_modify += "增加明细:" + str(line.id) + '[' + line.product_id.name_get()[0][1] + ']:' + \                                     " 单价:"+str(line.price_unit)+" 数量:" +str(line.product_uom_qty)+'\r\n'          if order_line_old:              for key,val in order_line_old.items():                  product=self.env['product.product'].browse(val.get('product_id'))                  line_modify += "删除明细:" + str(key)+'[' + product.name_get()[0][1] +']:'+ " 单价:"+str(val.get('price_unit'))+" 数量:" +str(val.get('product_uom_qty'))+'\r\n'          if line_modify:              apply_modify_detail += line_modify      values['apply_modify_detail_flag']=1      values['apply_modify_detail'] = apply_modify_detail      if values:          self.write(values) @api.one def write(self, vals):      if vals.get('apply_modify_detail_flag') ==1:          apply_modify_detail_flag=1          vals.pop('apply_modify_detail_flag')      else:          apply_modify_detail_flag=0      res = super(SaleOrder, self).write(vals)      self.refresh()      if not apply_modify_detail_flag and self.is_apply_modify and  self.apply_type == 'modify':          self.update_apply_modify_detail()      return res

重点要说明

1. self.refresh() 这个一定要加,否则删除销售订单明细,做记录报错,但你增加或修改时不报错,会让你摸不着头脑。它的功能是刷出缓存。让res = super(SaleOrder, self).write(vals) 这一句彻底完成,否则要等 write 方法全部完成,才完成,

2. res = super(SaleOrder, self).write(vals) 前面的那几句判断也很重要,若不设定,会让write方法进入死循环。

转载于:https://www.cnblogs.com/toby2chen/p/7574069.html

你可能感兴趣的文章
服务器部署十大问题系列三:创建文档与旧设备处理
查看>>
零基础学习SVN之(三):可视化SVN的使用
查看>>
IOS开发之显示微博表情
查看>>
Snap首份季度财报或让投资人失望 股价被指偏高
查看>>
新来的NB-IoT为什么这么NB?
查看>>
DoCoMo跳过HSPA+ 力争全球首家推出LTE商用服务
查看>>
Mozilla火狐发布最新计划:用户隐私和安全为发展核心
查看>>
金融行业解决方案
查看>>
[原创]分析解决lvs fullnat模式下后端服务器获取真实IP地址异常问题
查看>>
《Arduino开发实战指南:LabVIEW卷》——3.3 LabVIEW的常用工具及调试工具
查看>>
中国正式启动5G技术研发试验:力争2020年商用
查看>>
《精解 Windows 10》——第2章 Modern 2.0界面体验 2.1Modern 2.0界面
查看>>
《Android深度探索(卷1):HAL与驱动开发》——1.5节如何学习Linux驱动开发
查看>>
《Photoshop七大核心技术》—第2课Photoshop七大核心技术
查看>>
《动手玩转Arduino》——10.5 展望
查看>>
大数据开发套件-数据集成-云mongo跨区域如何同步到Maxcompute
查看>>
人工智能第三次黄金时代,藏在全球数亿摄像头里?
查看>>
RegularJS 0.2.12 发布,JavaScript MVC 框架
查看>>
根据《网络安全法》要求全面提升企业安全能力
查看>>
最新 Win10 测试版提供 Ubuntu 16.04 镜像
查看>>