我有一个实体付款(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'))]"/>
您使用了基于非存储计算字段的域。您应该在日志中找到以下错误:
您可以通过将state
store
属性设置为True
或使用statesearch
属性定义搜索方法来修复此问题您可以在Odoo documentation处检查:
相关问题 更多 >
编程相关推荐