Skip to content

Update event_compassion.py#2071

Open
davidwul wants to merge 2 commits into14.0from
davidwul-patch-1
Open

Update event_compassion.py#2071
davidwul wants to merge 2 commits into14.0from
davidwul-patch-1

Conversation

@davidwul
Copy link
Contributor

update domain and compute method to take non invoice income. Already in prod, but needs to be forward ported

update domain and compute method to take non invoice income.
Already in prod, but needs to be forward ported
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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

  • Income Line Filtering Logic: The filtering logic for _compute_income_lines has been updated to include non-invoice income entries (journal entries with move_id.move_type == "entry") in addition to paid customer invoices. A new condition ensures that only lines associated with an 'Income' account type are considered.
  • Total Income Calculation: The _compute_income method now calculates total_income by summing the 'credit' amounts and subtracting the 'debit' amounts from the income lines. This replaces the previous calculation which used price_subtotal, providing a more accurate accounting for various income types, especially non-invoice entries.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 165 to 171
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"))
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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.

Comment on lines 163 to 171
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"))
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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"))
)

Comment on lines 183 to 184
event.total_income = (sum(incomes.mapped("credit") or [0])
-sum(incomes.mapped("debit") or [0]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The or [0] is redundant here. sum() on an empty list (which mapped() returns for an empty recordset) correctly returns 0. Removing the or [0] makes the code cleaner.

            event.total_income = sum(incomes.mapped("credit")) - sum(incomes.mapped("debit"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant