Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TA#72114 [16.0][MIG] hr_expense_tax_adjustment #236

Draft
wants to merge 4 commits into
base: 16.0
Choose a base branch
from
Draft

Conversation

rivo2302
Copy link
Contributor

No description provided.

expense_id = fields.Many2one(
"hr.expense", "Expense", required=True, ondelete="cascade", index=True
)
amount = fields.Float("Amount", required=True, digits=dp.get_precision("Account"))
Copy link
Contributor

Choose a reason for hiding this comment

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

@lanto-razafindrabe No need to use dp.get_precision anymore
we can use directly digits="Product Price" see here

account_id = fields.Many2one(
"account.account", "Account", required=True, ondelete="restrict"
)
tax_id = fields.Many2one("account.tax", "Tax", required=True, ondelete="restrict")
Copy link
Contributor

Choose a reason for hiding this comment

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

@lanto-razafindrabe
We need to add a new field company_id related to expense_id.company_id then add a check_company=True to the tax_id field. We can also add a domain to select only company taxes.

if self.quantity and self.unit_amount and self.tax_ids:
self._setup_tax_lines()
else:
self.tax_line_ids = self.env["hr.expense.tax"]
Copy link
Contributor

Choose a reason for hiding this comment

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

we can simply set self.tax_line_ids to False


def _setup_tax_lines(self):
"""Setup the taxes on the expense."""
self.tax_line_ids = self.env["hr.expense.tax"]
Copy link
Contributor

Choose a reason for hiding this comment

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

we dont need to initiate self.tax_line_ids

self.tax_line_ids = self.env["hr.expense.tax"]

currency = self.currency_id or self.company_id.currency_id
taxes = self.tax_ids.with_context(round=True).compute_all(
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we can use directly self.tax_ids without compute_all
self.tax_ids is computed in V16 so we don't need to call compute_all

https://github.com/odoo/odoo/blob/16.0/addons/hr_expense/models/hr_expense.py#L67
https://github.com/odoo/odoo/blob/16.0/addons/hr_expense/models/hr_expense.py#L205

)
tax_amount = sum(line.amount for line in expense.tax_line_ids)

expense.untaxed_amount = (
Copy link
Contributor

Choose a reason for hiding this comment

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

@lanto-razafindrabe @rivo2302
In V16 untaxed_amount is calculated using another method "_compute_amount_tax()"
The method "_compute_amount" is only used to calculate "total_amount"

@lanto-razafindrabe lanto-razafindrabe marked this pull request as draft February 19, 2025 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants