[已解决]action context传值
-
**功能要求:**在打开的
wizard
中展示类似sale order line
里面的某一个字段的值(如果有数据的话),没有数据就添加数据保存。**问题:**第一次打开
wizard
的填写数据没有问题,但是在已经填写的情况下再次打开如何显示出已经填写过的数据。**我的做法是:**在返回的
action
中添加一个key('remark')
(不知道如何添加到self._context
的context
中去),但是不知道在里面能够取出来。试验在视图的act_window
中添加context
字段的,<field nam="context">{'default_description': context.get('remark', '**')}</field>
会报错的。注:(
self.with_context(context).env.ref('sps_project.action_project_remark').read()[0]
)这个也没作用。
如何解决?代码如下:
def show_remark(self): remark = self.remark print('remark =', remark) context = dict(self._context or {}) context['remark'] = remark print('self context ===', self._context) action = self.env.ref('sps_project.action_project_remark').read()[0] print('remark action==', action) action['remark'] = remark print('remark action222222==', action) return action
('remark =', u'dddd') ('contx==', {u'lang': u'en_US', 'remark': u'dddd', u'tz': u'Asia/Shanghai', u'uid': 1, u'project_line_ids': [[4, 17, False], [4, 18, False], [4, 19, False], [4, 20, False], [4, 21, False]]}) ('self context ===', {u'lang': u'en_US', u'tz': u'Asia/Shanghai', u'uid': 1, u'project_line_ids': [[4, 17, False], [4, 18, False], [4, 19, False], [4, 20, False], [4, 21, False]]}) ('remark action==', {'groups_id': [], 'domain': False, 'xml_id': u'sps_project.action_project_remark', 'create_date': '2018-05-31 03:02:24', 'help': False, 'res_model': u'project.remark.wizard', 'search_view_id': False, 'write_uid': (1, u'root'), 'id': 518, 'create_uid': (1, u'root'), 'display_name': u'Add Remark', '__last_update': '2018-06-04 03:52:28', 'views': [(970, u'form'), (False, u'tree')], 'src_model': False, 'usage': False, 'res_id': 0, 'view_type': u'form', 'view_id': (970, u'project.remark.wizard.form'), 'view_mode': u'tree,form', 'write_date': '2018-06-04 03:52:28', 'view_ids': [], 'name': u'Add Remark', 'multi': False, 'target': u'new', 'auto_search': True, 'type': u'ir.actions.act_window', 'search_view': u'{\'name\': \'default\', \'arch\': \'<search string="Project Remark Wizard"><field name="id" modifiers="{"readonly": true}"/></search>\', \'fields\': {\'id\': {\'change_default\': False, \'string\': u\'ID\', \'searchable\': True, \'views\': {}, \'required\': False, \'manual\': False, \'readonly\': True, \'depends\': (), \'company_dependent\': False, \'sortable\': True, \'type\': \'integer\', \'store\': True}}, \'model\': \'project.remark.wizard\', \'type\': \'search\', \'field_parent\': False}', 'filter': False, 'limit': 80, 'context': u'{}'}) ('remark action222222==', {'groups_id': [], 'domain': False, 'xml_id': u'sps_project.action_project_remark', 'create_date': '2018-05-31 03:02:24', 'help': False, 'res_model': u'project.remark.wizard', 'search_view_id': False, 'write_uid': (1, u'root'), 'id': 518, 'create_uid': (1, u'root'), 'display_name': u'Add Remark', '__last_update': '2018-06-04 03:52:28', 'views': [(970, u'form'), (False, u'tree')], 'src_model': False, 'usage': False, 'res_id': 0, 'view_type': u'form', 'view_id': (970, u'project.remark.wizard.form'), 'remark': u'dddd', 'view_mode': u'tree,form', 'write_date': '2018-06-04 03:52:28', 'view_ids': [], 'name': u'Add Remark', 'multi': False, 'target': u'new', 'auto_search': True, 'type': u'ir.actions.act_window', 'search_view': u'{\'name\': \'default\', \'arch\': \'<search string="Project Remark Wizard"><field name="id" modifiers="{"readonly": true}"/></search>\', \'fields\': {\'id\': {\'change_default\': False, \'string\': u\'ID\', \'searchable\': True, \'views\': {}, \'required\': False, \'manual\': False, \'readonly\': True, \'depends\': (), \'company_dependent\': False, \'sortable\': True, \'type\': \'integer\', \'store\': True}}, \'model\': \'project.remark.wizard\', \'type\': \'search\', \'field_parent\': False}', 'filter': False, 'limit': 80, 'context': u'{}'})
-
@siyuan 你说的对。正确的如下:
只要这个context里面的key是default_xx,xx是wizard中的字段就可以def show_remark(self): remark = self.remark context = dict(self._context or {}) context['default_remark'] = remark action = self.env.ref('sps_project.action_project_remark').read()[0] action.update(context=context) return action