change_number_helper.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # -*- coding: utf-8 -*-
  2. from odoo.exceptions import ValidationError
  3. class NumberHelper(object):
  4. def __init__(self):
  5. self.dic = {}
  6. def add(self, goods_id, second, main, can_not_change):
  7. data = [second, main, second, main] if can_not_change else [second, main, 0, 0] # 前2个:总数量;后2个:来自来源单据
  8. if goods_id in self.dic:
  9. value = self.dic[goods_id]
  10. value[0] += data[0]
  11. value[1] += data[1]
  12. value[2] += data[2]
  13. value[3] += data[3]
  14. else:
  15. self.dic[goods_id] = data
  16. def get(self):
  17. return self.dic
  18. class DifferentHelper(object): # 来自来源单据的数据,不可修改
  19. def __init__(self, not_change_helper, need_change_helper):
  20. self.not_change_dic = not_change_helper.get()
  21. self.need_change_dic = need_change_helper.get()
  22. self.new = {}
  23. self.add = {}
  24. self.sub = {}
  25. return
  26. def get(self):
  27. for goods_id, data in self.not_change_dic.items():
  28. if goods_id not in self.need_change_dic:
  29. self.new[goods_id] = [data[0] - data[2], data[1] - data[3]] # 当前单据新添加的明细,才需要新建
  30. continue
  31. change_data = self.need_change_dic[goods_id]
  32. # 以数量为准进行判断
  33. if data[1] == change_data[1]:
  34. continue
  35. if data[1] > change_data[1]:
  36. if change_data[1] == change_data[3]: # 全部来自来源单据
  37. self.new[goods_id] = [data[0] - change_data[0], data[1] - change_data[1]]
  38. else: # 说明有添加的数据。此时,只需要修改该数据即可
  39. self.add[goods_id] = [data[0] - change_data[0], data[1] - change_data[1]]
  40. continue
  41. if change_data[1] == change_data[3]: # 全部来自来源单据
  42. self.new[goods_id] = [change_data[0] - data[0], change_data[1] - data[1]]
  43. else: # 说明有添加的数据。此时,只需要修改该数据即可
  44. self.sub[goods_id] = [change_data[0] - data[0], change_data[1] - data[1]]
  45. return self.new, self.add, self.sub