我正在设计一个按钮,从销售订单中选择/创建一个新项目。
这是我的模块:
@api.multi
def action_create_project_project(self):
view_id = self.env.ref('project.project_project_view_form_simplified').id
context = self._context.copy()
return {
'name': 'Create project',
'view_type': 'form',
'view_mode': 'tree',
'views' : [(view_id, 'form')],
'res_model': 'project.project',
'view_id': view_id,
'type': 'ir.actions.act_window',
# 'res_id': self.id,
'target': 'new',
'context': context,
}
观点:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_order_form_inherit_sale_timesheet" model="ir.ui.view">
<field name="name">Sale Order create project</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='partner_shipping_id']" position="after">
<field name="project_project_id" invisible="1"/>
<label for="action_create_project_project" string="Create project" invisible="[('project_project_id', '!=', False)]"/>
<button type="object"
name="action_create_project_project"
class="fa fa-external-link btn btn-default o_external_button"
string="New project"
groups="base.group_user"
attrs="{'invisible': [('project_project_id', '!=', False)]}">
</button>
</xpath>
</data>
</field>
</record>
</odoo>
但我真正想要的是选择现有项目或创建新项目,当项目被选中时,我需要访问项目,获取analytic_account_id
并使用此信息填写销售订单。
请帮忙吗?
也许我可以修改project_project_id
定义,以便让它在销售订单草稿上可写(由sale_timesheet
创建,readonly标志为true)但我不知道我可以覆盖来自一个插件(想保持核心完整)......
原件:
project_project_id = fields.Many2one('project.project',
compute='_compute_project_project_id',
string='Project associated to this sale',
)
所需:
project_project_id = fields.Many2one('project.project',
'Project associated to this sale',
compute='_compute_project_project_id',
readonly=True,
states={'draft': [('readonly', False)]},
copy=False,
)
答案 0 :(得分:0)
要覆盖现有字段,只需添加所需的属性,如下所示:
project_project_id = fields.Many2one(
readonly=True,
states={'draft': [('readonly', False)]},
copy=False)
我希望这个答案可以对你有所帮助。