需要根据其他字段的值来删除销售订单中partner_id字段中的创建和编辑。我找到了一个类似的答案,但是没有用。
SELECT
user_organizations. "organizationId",
user_organizations. "userId",
max(user_organizations.admin) as admin,
max(user_organizations.owner) as owner,
max(user_organizations.member) member
FROM ((
SELECT
organizations.id AS "organizationId",
organizations. "ownedById" AS "userId",
NULL AS admin,
NULL AS member,
TRUE AS OWNER
FROM
organizations)
UNION (
SELECT
organizations.id AS "organizationId",
memberships. "userId",
memberships.admin,
TRUE AS member,
NULL AS OWNER
FROM
memberships
LEFT JOIN organizations ON memberships. "organizationId" = organizations.id)) AS user_organizations
group by user_organizations. "organizationId",
user_organizations. "userId"
当sale_invoice_type为现金时,应删除编辑和创建内容
答案 0 :(得分:4)
首先,两个字段的域都应如下所示
<field .... attrs=" {'invisible': [('sale_invoice_type', '!=', 'cash')]}"/>
<field .... attrs=" {'invisible': [('sale_invoice_type', '=', 'cash')]}"/>
IF该解决方案无法正常工作,因为您不应拥有相同的解决方案 您认为两次Odoo都会让一位巫师感到困惑。
但是您可以通过创建一个新字段来解决它。
在模型中定义另一个合作伙伴字段,只是一个虚拟的字段而不是它 真正的partner_id,但请确保两个字段都在write和create的末尾 将始终相等。
partner_no_create = fields.Man.......
在您的代码中,请确保这两个字段始终相等:
# I think this onchage handle the cases in Odoo views
@api.onchange('partner_id')
def set_partner_no_create(self):
if self.sale_invoice_type != 'cash':
self.partner_no_create = self.partner_id
@api.onchange('partner_no_create')
def set_partner_no_create(self):
if self.sale_invoice_type == 'cash':
self.partner_id = self.partner_no_create
使用您的XML
<field name="partner_no_create" string="partner" domain="[('customer','=',True),('sale_invoice_type','=',sale_invoice_type)]"
context="{'search_default_customer':1, 'show_address': 1,'default_sale_invoice_type':sale_invoice_type}"
attrs=" {'invisible': [('sale_invoice_type', '!=', 'cash')]}" options='{"always_reload": True, "no_create_edit": True}'/>
<field name="partner_id" domain="[('customer','=',True),('sale_invoice_type','=',sale_invoice_type)]"
context="{'search_default_customer':1, 'show_address': 1,'default_sale_invoice_type':sale_invoice_type}"
attrs="{'invisible': [('sale_invoice_type', '=', 'cash')]}" options='{"always_reload": True}'/>
但是,当记录更新或通过RPC调用创建记录时,仍然必须专门处理更多情况,您需要 覆盖创建和写入方法以处理所有情况。