在供应商账单odoo 11发票自定​​义模块中仅显示与特定预算相关的分析帐户

问题描述

大家好,我向 account.invoice 添加了一个新字段,并将该字段添加到供应商账单视图中以获取所有预算。选择特定预算后,我只想使用 onchange 在帐单部分显示与此预算相关的分析帐户。

这是 account.invoice

enter image description here

class custom_accounting_invoice(models.Model):
    _inherit = 'account.invoice'

    creating_user_id = fields.Many2one('res.users','Project Manager',default=lambda self: self.env.user)
    email = fields.Char('Email',related='creating_user_id.login')
    budget_id = fields.Many2one('crossovered.budget',string='Budget')


    @api.onchange('budget_id')
    def onchange_analytic_account_budget(self):
        return {'domain': {'invoice_line_ids.account_analytic_id': [
            ('id','in',self.mapped('budget_id.crossovered_budget_line.analytic_account_id.id')
             )]
        }
        }

解决方法

您可以覆盖发票行中现有的 onchange 方法以更改 analytic_account_id 域。

在以下示例中,当 Unit of Measure 更改且仅当设置了 budget_id 字段时,才会设置域:

class BillsEdit(models.Model):
    _inherit = 'account.invoice.line'

    account_analytic_id = fields.Many2one('account.analytic.account',string='Budget line')

    @api.onchange('uom_id')
    def _onchange_uom_id(self):
        res = super(BillsEdit,self)._onchange_uom_id()
        account_ids = self.mapped('invoice_id.budget_id.crossovered_budget_line.analytic_account_id.id')
        new_domain = {}
        if account_ids:
            new_domain['account_analytic_id'] = [('id','in',account_ids)]
            if 'domain' in res:
                res['domain'].update(new_domain)
            else:
                res['domain'] = new_domain
        return res

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...