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

[16.0][FIX] hr_expense_invoice: Incorrect data and check when creating vendor bill from expense #249

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions hr_expense_invoice/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ class AccountMove(models.Model):
"transfer journal entry",
)

@api.constrains("amount_total")
def _check_expense_ids(self):
def write(self, vals):
# Check if the amount of the invoice linked to an invoice is different
# Done here in the write instead of a Python constraint as the computed field
# amount_total is not yet updated on that moment
res = super().write(vals)
Copy link

Choose a reason for hiding this comment

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

Suggested change
res = super().write(vals)
res = super().write(vals)
if self.env.context.get("skip_account_move_synchronization"):
return res

Copy link

Choose a reason for hiding this comment

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

@pedrobaeza can you address it?

@loida-vm @edlopen please approve this PR in order to allow me to continue doing things

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed, @Shide

if self.env.context.get("skip_account_move_synchronization"):
return res
DecimalPrecision = self.env["decimal.precision"]
precision = DecimalPrecision.precision_get("Product Price")
for move in self.filtered("expense_ids"):
Expand All @@ -32,6 +37,7 @@ def _check_expense_ids(self):
"linked to this invoice."
)
)
return res

def action_view_expense(self):
self.ensure_one()
Expand Down
4 changes: 3 additions & 1 deletion hr_expense_invoice/models/hr_expense.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _prepare_invoice_values(self):
{
"product_id": self.product_id.id,
"name": self.name,
"price_unit": self.unit_amount or self.total_amount,
"price_unit": self.untaxed_amount,
"quantity": self.quantity,
"account_id": self.account_id.id,
"analytic_distribution": self.analytic_distribution,
Expand Down Expand Up @@ -126,6 +126,8 @@ def action_expense_create_invoice(self):
)
for attachment in attachments:
attachment.copy({"res_model": invoice._name, "res_id": invoice.id})
# Normalize data in the expense for avoiding mismatchings. Examples: the tax
# reported is not correct, there's more than one concept, etc...
self.write(
{
"invoice_id": invoice.id,
Expand Down
Loading