Skip to Content
Menu
This question has been flagged
2 Replies
5954 Views

I have a pivot view of budget. I added new field named 'pivot_practical_amount' to 'crossovered_budget_lines' table on db. Which is copying value of 'amount' on 'account_analytic_line'. In the list view I see practical amount value but in pivot view it's not updating itself.


I want to copy practical_amount to pivot_practical_amount everytime I open pivot view or open budget page.


I tried that @api.depends method of new odoo api.


    class BudgetGraph(models.Model):

        _inherit = "crossovered.budget.lines"


     pivot_practical_amount = fields.Float("Practical Amount", compute="_pivot_practical_amount_compute", digits_compute=dp.get_precision('Account'), store=True)


    @api.one

    @api.depends('planned_amount', 'practical_amount')

    def _pivot_practical_amount_compute(self):

        self.pivot_practical_amount = self.practical_amount


But this time it's updating only when I edit planned_amount. 


How can I update pivot_practical_amount(crossovered_budget_lines) instantly when amount(account_analytic_line) changed?


Avatar
Discard
Best Answer

I was stuck on the same problem until I found the updated version of the budget:
\https://github.com/odoo/odoo/blob/saas-11.4/addons/account_budget/models/account_budget.py

Avatar
Discard
Author Best Answer

Hi Badr, thank you for answering.

I cannot use different version of base addon. I have to solve it without that.


I just wondering how can I trigger _pivot_practical_amount_compute() method when I open pivot view or open budget page?

By the way, your linked account_budget giving error when installing it. Key error: group_id 


EDIT:

solution is;

I applied override approach here. Didn't work anything except override.


@api.multi

    def _compute_practical_amount(self):

        for line in self:

            result = 0.0

            acc_ids = line.general_budget_id.account_ids.ids

            date_to = self.env.context.get('wizard_date_to') or line.date_to

            date_from = self.env.context.get('wizard_date_from') or line.date_from

            if line.analytic_account_id.id:

                self.env.cr.execute("""

                        SELECT SUM(amount)

                        FROM account_analytic_line

                        WHERE account_id=%s

                            AND (date between to_date(%s,'yyyy-mm-dd') AND to_date(%s,'yyyy-mm-dd'))

                            AND general_account_id=ANY(%s)""",

                                    (line.analytic_account_id.id, date_from, date_to, acc_ids,))

                result = self.env.cr.fetchone()[0] or 0.0

                line.practical_amount = result

            self.env.cr.execute("""

                    UPDATE crossovered_budget_lines 

                    SET pivot_practical_amount=%s

                    WHERE id=%s

                """, (result, self._ids[0]))




Avatar
Discard
Related Posts Replies Views Activity
2
Aug 23
8123
1
Nov 22
1742
2
Aug 22
5989
1
Feb 22
2618
1
Feb 22
4806