تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2457 أدوات العرض

I have a project budget model(project.budget). each project budget has many lines, meaning I have a model (project.budget.line). I have added a many2one field to the invoice model(account.move): budget_id this field refers to the project budget model, and I also added a many2one field to the invoice lines model (account.move.line) which is: budget_line this field refers to the project budget line model. what I want when I select a budget using budget id in the account move filter the budget line in the account move line using on change meaning returning only the lines that belong to the project budget, but nothing is happening here is my code:

class CustomAccountingMove(models.Model):
_inherit = 'account.move'

    budget_id = fields.Many2one('project.budget', string='Project Bugdet')

    @api.onchange('budget_id')
    def onchange_budget_id(self):
        for rec in self:
            return {'domain': {'invoice_line_ids.budget_line': [
            ('id',
             'in',
             rec.mapped('budget_id.budget_line_ids.id')
             )]
        }
        }

class CustomAccountingMoveline(models.Model):
_inherit = 'account.move.line'

    budget_line = fields.Many2one('project.budget.line', string='Budget Line')


الصورة الرمزية
إهمال
الكاتب أفضل إجابة

I have set the domain in view and use parent to get the budget_id:

"budget_line" domain="[('budget_id', '=', parent.budget_id)]"/>

budget_id on the left is the inverse name used in budget_line_ids


الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يونيو 23
3127
1
يناير 23
2919
0
سبتمبر 22
2626
1
أغسطس 22
3631
0
أغسطس 22
2759