1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- # -*- coding: utf-8 -*-
- from .query_model import QueryModel
- from .query_field import QueryField
- from .const import BILL_IGNORE_FIELDS_LIST, DETAIL_IGNORE_FIELDS_LIST
- def get_model_from(self, detail_field, reference_field, get_rec_name_func, get_field_info_func, get_table_func, env):
- model = self._name
- table = self._table
- return get_model_from2(self, model, table, detail_field, reference_field, get_rec_name_func, get_field_info_func,
- get_table_func, env)
- def get_model_from2(self, model, table, detail_field, reference_field, get_rec_name_func, get_field_info_func,
- get_table_func, env):
- query_model = QueryModel(model, table)
- query_model_alias = query_model.get_alias()
- bill_ignore_list = BILL_IGNORE_FIELDS_LIST + [detail_field] if detail_field else BILL_IGNORE_FIELDS_LIST
- for field, info in self.env[model]._fields.items():
- if field in bill_ignore_list:
- continue
- if field.startswith('__'):
- continue
- query_field = QueryField(query_model_alias, field, info, get_rec_name_func, get_field_info_func, get_table_func, env)
- query_model.add_field(query_field)
- query_model.set_related()
- if detail_field:
- detail_ignore_list = DETAIL_IGNORE_FIELDS_LIST + ['id', reference_field]
- detail_field = self.env[model]._fields['detail'] # 因为self不一定是当前单据,因此采用该方法获取明细相关信息
- detail_model = detail_field.comodel_name
- detail = self.env[detail_model]
- detail_table = detail._table
- query_detail_model = QueryModel(detail_model, detail_table)
- query_detail_model_alias = query_detail_model.get_alias()
- for field, info in detail._fields.items():
- if field in detail_ignore_list:
- continue
- if field.startswith('__'):
- continue
- query_field = QueryField(query_detail_model_alias, field, info, get_rec_name_func, get_field_info_func,
- get_table_func,env)
- query_detail_model.add_field(query_field)
- query_detail_model.set_related()
- query_model.set_right_query_model('id', query_detail_model, reference_field)
- return query_model
|