write_value_helper.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # -*- coding: utf-8 -*-
  2. from odoo.exceptions import ValidationError
  3. # 得到write方法的vals。只处理修改字段
  4. # add_detail:明细要修改的数据
  5. # 参数1:明细ID
  6. # 参数2:明细字段
  7. # 参数3:明细字段对应的值
  8. # add_bill:表头要修改的数据
  9. # 参数1:表头字段
  10. # 参数2:表头字段对应的值
  11. # get:得到write方法需要的vals参数
  12. class WriteValueHelper(object):
  13. def __init__(self, detail_field): # 参数:表头中的One2many字段
  14. self._detail_field = detail_field
  15. self._detail_dic = {}
  16. self._bill_dic = {}
  17. def add_detail(self, detail_id, field, value):
  18. if detail_id not in self._detail_dic:
  19. self._detail_dic[detail_id] = {field: value}
  20. return
  21. self._detail_dic[detail_id][field] = value
  22. return
  23. def add_bill(self, field, value):
  24. self._bill_dic[field] = value
  25. return
  26. def get(self):
  27. detail = []
  28. for key in self._detail_dic:
  29. detail.append([1, key, self._detail_dic[key]])
  30. if detail:
  31. self._bill_dic[self._detail_field] = detail
  32. return self._bill_dic