多个字段的域不在odoo中工作

2024-09-22 10:15:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个实体付款(pago)和一张多人现场账单(factura)。一个法案可以有三个州“creado”、“pendiente”和“pagado”。我想为manyOne字段添加一个域:对于每次付款,您只能选择“creado”和“pendiente”状态的账单。我已尝试使用以下代码,但ii不起作用

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'])] )

在payment视图中,我添加了manyOne字段

 <group>
     <field name="factura_id" domain="[('state','in',('creado','pendiente'))]"/>

Tags: nameidfieldsstringrecordcurrencytotalstate
1条回答
网友
1楼 · 发布于 2024-09-22 10:15:34

您使用了基于非存储计算字段的域。您应该在日志中找到以下错误:

Non-stored field utepda_planificacion.factura.state cannot be searched.

您可以通过将state store属性设置为True或使用state search属性定义搜索方法来修复此问题

您可以在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.

相关问题 更多 >