【问题标题】:show only analytic account related to specific budget in vendor bills odoo 11 Invoicing custom module在供应商账单odoo 11发票自定​​义模块中仅显示与特定预算相关的分析帐户
【发布时间】:2021-02-15 11:45:37
【问题描述】:

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

这里是 account.invoice

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

【问题讨论】:

    标签: odoo odoo-11


    【解决方案1】:

    您可以覆盖发票行中现有的 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
    

    【讨论】:

    • 非常感谢您拯救了我的一天
    • 我能为您做什么?
    猜你喜欢
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 2020-12-23
    • 1970-01-01
    相关资源
    最近更新 更多