在供应商账单odoo 11发票自定​​义模块中仅显示与特定预算相关的分析帐户 [英] show only analytic account related to specific budget in vendor bills odoo 11 Invoicing custom module

查看:34
本文介绍了在供应商账单odoo 11发票自定​​义模块中仅显示与特定预算相关的分析帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Hello everyone I have added a new field to account.invoice and add that field to the vendor bills view to fetch all budget. After a specific budget selected I want to show only analytic account related to this budget in the Bill section using onchange.

这是 account.invoice

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

推荐答案

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

You can override an existing onchange method in invoice lines to change the analytic_account_id domain.

在以下示例中,域在 度量单位 更改时设置,并且仅当 budget_id 字段设置时:

In the following example the domain is set when the Unit of Measure change and only if the budget_id field is set:

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

这篇关于在供应商账单odoo 11发票自定​​义模块中仅显示与特定预算相关的分析帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆