const_model.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # -*- coding: utf-8 -*-
  2. from .query_model import QueryModel
  3. from .query_field import QueryField
  4. from .const import BILL_IGNORE_FIELDS_LIST, DETAIL_IGNORE_FIELDS_LIST
  5. def get_model_from(self, detail_field, reference_field, get_rec_name_func, get_field_info_func, get_table_func, env):
  6. model = self._name
  7. table = self._table
  8. return get_model_from2(self, model, table, detail_field, reference_field, get_rec_name_func, get_field_info_func,
  9. get_table_func, env)
  10. def get_model_from2(self, model, table, detail_field, reference_field, get_rec_name_func, get_field_info_func,
  11. get_table_func, env):
  12. query_model = QueryModel(model, table)
  13. query_model_alias = query_model.get_alias()
  14. bill_ignore_list = BILL_IGNORE_FIELDS_LIST + [detail_field] if detail_field else BILL_IGNORE_FIELDS_LIST
  15. for field, info in self.env[model]._fields.items():
  16. if field in bill_ignore_list:
  17. continue
  18. if field.startswith('__'):
  19. continue
  20. query_field = QueryField(query_model_alias, field, info, get_rec_name_func, get_field_info_func, get_table_func, env)
  21. query_model.add_field(query_field)
  22. query_model.set_related()
  23. if detail_field:
  24. detail_ignore_list = DETAIL_IGNORE_FIELDS_LIST + ['id', reference_field]
  25. detail_field = self.env[model]._fields['detail'] # 因为self不一定是当前单据,因此采用该方法获取明细相关信息
  26. detail_model = detail_field.comodel_name
  27. detail = self.env[detail_model]
  28. detail_table = detail._table
  29. query_detail_model = QueryModel(detail_model, detail_table)
  30. query_detail_model_alias = query_detail_model.get_alias()
  31. for field, info in detail._fields.items():
  32. if field in detail_ignore_list:
  33. continue
  34. if field.startswith('__'):
  35. continue
  36. query_field = QueryField(query_detail_model_alias, field, info, get_rec_name_func, get_field_info_func,
  37. get_table_func,env)
  38. query_detail_model.add_field(query_field)
  39. query_detail_model.set_related()
  40. query_model.set_right_query_model('id', query_detail_model, reference_field)
  41. return query_model