Many2One 领域的域在 odoo 中不起作用 [英] Domain for Many2One field not working in odoo
问题描述
我有一个实体付款 (pago) 和 Many2One 现场账单 (factura).一项法案可以有 3 个状态creado"、pendiente"和pagado".我想为 Many2One 字段添加一个域:对于每次付款,您只能选择状态为creado"和pendiente"的账单.我已尝试使用以下代码,但 ii 无法正常工作
class PlanificacionFactura(models.Model):_name = 'utepda_planificacion.factura'_rec_name = '数字'_description = 'Factura'_inherit = ['mail.thread', 'mail.activity.mixin']fecha = fields.Date(string='Fecha')monto_total = fields.Monetary(string='Monto a pagar',currency_field='currency_id')pago_acumulado = fields.Monetary(compute='_compute_pago_acumulado', string='Pago Acumulado',currency_field='currency_id')currency_id = fields.Many2one('res.currency', string='Moneda', required=True, domain=[('name', 'in', ('USD', 'DOP'))] , default=lambda self: self.env.ref("base.DOP"))pago_pendiente = fields.Monetary(compute='_compute_pago_pendiente', string='Pendiente de pago',currency_field='currency_id')状态 = fields.Selection([('creado', 'Creada'),('pendiente','Pagada parcialmente'),('宝塔','宝塔')], string='Estado', default='creado', compute='_compute_state' )@api.depends('pago_acumulado','monto_total')def_compute_state(self):自我记录:如果 record.pago_acumulado >0 和 record.pago_acumulado
在支付视图中,我添加了 Many2One 字段
<field name="factura_id" domain="[('state','in',('creado','pendiente'))]"/>
您使用了基于非存储计算域的域.您应该在日志中发现以下错误:
非存储字段 utepda_planificacion.factura.state 无法搜索.
您可以通过将 state store
属性设置为 True
或使用 state search
属性定义搜索方法来解决此问题.>
您可以查看 Odoo 文档:
<块引用>默认情况下不存储计算字段,它们会在请求时计算并返回.设置 store=True
会将它们存储在数据库中并自动启用搜索.
也可以通过设置搜索参数来启用对计算字段的搜索.该值是返回搜索域的方法名称.
I have an Entity payment (pago) with a Many2One field bill (factura). A bill could have 3 states 'creado', 'pendiente' y 'pagado'. I want to add a domain for the Many2One field: For each payment you can only select a bill in the states 'creado' y 'pendiente'. I have tried with the following code but ii is nt working
class PlanificacionFactura(models.Model):
_name = 'utepda_planificacion.factura'
_rec_name = 'numero'
_description = 'Factura'
_inherit = ['mail.thread', 'mail.activity.mixin']
fecha = fields.Date(string='Fecha')
monto_total = fields.Monetary(string='Monto a pagar', currency_field='currency_id')
pago_acumulado = fields.Monetary(compute='_compute_pago_acumulado', string='Pago Acumulado' ,currency_field='currency_id')
currency_id = fields.Many2one('res.currency', string='Moneda', required=True, domain=[('name', 'in', ('USD', 'DOP'))] , default=lambda self: self.env.ref("base.DOP"))
pago_pendiente = fields.Monetary(compute='_compute_pago_pendiente', string='Pendiente de pago', currency_field='currency_id')
state = fields.Selection([
('creado', 'Creada'),
('pendiente','Pagada parcialmente'),
('pagado','Pagada')
], string='Estado', default='creado', compute='_compute_state' )
@api.depends('pago_acumulado','monto_total')
def _compute_state(self):
for record in self:
if record.pago_acumulado > 0 and record.pago_acumulado < record.monto_total:
record.state='pendiente'
elif record.pago_acumulado == record.monto_total:
record.state = 'pagado'
else:
record.state='creado'
class PagoParcialFactura(models.Model):
_name = 'utepda_planificacion.pago_parcial'
_description = 'Permite Realizar el pago de una facura en distintos pagos'
factura_id = fields.Many2one('utepda_planificacion.factura', string='Factura', required=True, ondelete="cascade", domain=[('state','in',['creado','pendiente'])] )
In the payment view I added the Many2One field
<group>
<field name="factura_id" domain="[('state','in',('creado','pendiente'))]"/>
You used a domain based on a non-stored computed field. You should find the following error in the log:
Non-stored field utepda_planificacion.factura.state cannot be searched.
You can fix that by setting the state store
attribute to True
or by defining a search method using the state search
attribute.
You can check that at the Odoo documentation:
Computed fields are not stored by default, they are computed and returned when requested. Setting
store=True
will store them in the database and automatically enable searching.Searching on a computed field can also be enabled by setting the search parameter. The value is a method name returning a search domain.
这篇关于Many2One 领域的域在 odoo 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!