Conversation
update domain and compute method to take non invoice income. Already in prod, but needs to be forward ported
Summary of ChangesHello @davidwul, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request updates the income calculation and filtering mechanisms to accurately account for all forms of income, including those not originating from customer invoices. The changes ensure that both the identification of income lines and the final total income computation correctly incorporate non-invoice entries, aligning the system with comprehensive financial reporting. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request updates the income calculation for events to include non-invoice income, which is a reasonable change. However, the implementation introduces a potential bug due to missing dependencies for a stored computed field, which could lead to incorrect income totals. I've also suggested an improvement for maintainability by avoiding a hardcoded string and a minor code cleanup for better readability.
| event.income_line_ids = event.invoice_line_ids.filtered( | ||
| lambda line: line.payment_state == "paid" | ||
| and not line.contract_id | ||
| and line.move_id.move_type == "out_invoice" | ||
| lambda line: not line.contract_id | ||
| and line.account_id.user_type_id.name == "Income" | ||
| and ((line.payment_state == "paid" | ||
| and line.move_id.move_type == "out_invoice") or | ||
| (line.move_id.move_type == "entry")) | ||
| ) |
There was a problem hiding this comment.
The logic inside this filtered call introduces new dependencies on account.move.line fields (account_id, move_id.move_type). Since total_income is a stored computed field that depends on this, its @api.depends decorator needs to be updated to reflect these new dependencies. Otherwise, total_income will not be recomputed when these fields change, leading to incorrect data.
The decorator for _compute_income should be updated. A better long-term solution would be to add a proper @api.depends to _compute_income_lines itself, and then make _compute_income depend on income_line_ids.
| def _compute_income_lines(self): | ||
| for event in self: | ||
| event.income_line_ids = event.invoice_line_ids.filtered( | ||
| lambda line: line.payment_state == "paid" | ||
| and not line.contract_id | ||
| and line.move_id.move_type == "out_invoice" | ||
| lambda line: not line.contract_id | ||
| and line.account_id.user_type_id.name == "Income" | ||
| and ((line.payment_state == "paid" | ||
| and line.move_id.move_type == "out_invoice") or | ||
| (line.move_id.move_type == "entry")) | ||
| ) |
There was a problem hiding this comment.
Using a hardcoded string "Income" to identify the account type is fragile. It can break if the name is changed or translated. It's better to use an XML ID to get a reference to the record. This makes the code more robust and maintainable.
| def _compute_income_lines(self): | |
| for event in self: | |
| event.income_line_ids = event.invoice_line_ids.filtered( | |
| lambda line: line.payment_state == "paid" | |
| and not line.contract_id | |
| and line.move_id.move_type == "out_invoice" | |
| lambda line: not line.contract_id | |
| and line.account_id.user_type_id.name == "Income" | |
| and ((line.payment_state == "paid" | |
| and line.move_id.move_type == "out_invoice") or | |
| (line.move_id.move_type == "entry")) | |
| ) | |
| def _compute_income_lines(self): | |
| income_account_type = self.env.ref("account.data_account_type_income", raise_if_not_found=False) | |
| for event in self: | |
| if not income_account_type: | |
| event.income_line_ids = self.env['account.move.line'] | |
| continue | |
| event.income_line_ids = event.invoice_line_ids.filtered( | |
| lambda line: not line.contract_id | |
| and line.account_id.user_type_id == income_account_type | |
| and ((line.payment_state == "paid" | |
| and line.move_id.move_type == "out_invoice") or | |
| (line.move_id.move_type == "entry")) | |
| ) |
| event.total_income = (sum(incomes.mapped("credit") or [0]) | ||
| -sum(incomes.mapped("debit") or [0])) |
update domain and compute method to take non invoice income. Already in prod, but needs to be forward ported