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

[FIX] sale_stock: fix singleton error on invoice line with multiple sales line #163766

Conversation

amay-odoo
Copy link

The issue:
When creating an invoice from multiple sale orders, each invoice line is going to be linked to the appropriate sale order line from each sale order, which will cause a singleton traceback when trying to access the is_downpayment field

Expected behavior:
to confirm the invoice

Current Behavior:
Singleton traceback

opw-3878327

…ales line

The issue:
When creating an invoice from multiple sale orders, each invoice line is going to be linked to the appropriate sale order line from each sale order, which will cause a singleton traceback when trying to access the is_downpayment field

Expected behavior:
to confirm the invoice

Current Behavior:
Singleton traceback

opw-3878327
@robodoo
Copy link
Contributor

robodoo commented Apr 29, 2024

Pull request status dashboard.

@C3POdoo C3POdoo requested a review from a team April 29, 2024 10:48
@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Apr 29, 2024
@amay-odoo
Copy link
Author

Hello @odoo/rd-logistics , Could someone please have a look at this PR? Thanks

Copy link
Contributor

@Sehnde Sehnde left a comment

Choose a reason for hiding this comment

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

Hello,
As discussed in DM:
The code is sound but the issue doesn't appear reproducible as each sale line creates its own invoice line, based on this here:

def _prepare_invoice_line(self, **optional_values):
"""Prepare the values to create the new invoice line for a sales order line.
:param optional_values: any parameter that should be added to the returned invoice line
:rtype: dict
"""
self.ensure_one()
res = {
'display_type': self.display_type or 'product',
'sequence': self.sequence,
'name': self.name,
'product_id': self.product_id.id,
'product_uom_id': self.product_uom.id,
'quantity': self.qty_to_invoice,
'discount': self.discount,
'price_unit': self.price_unit,
'tax_ids': [Command.set(self.tax_id.ids)],
'sale_line_ids': [Command.link(self.id)],
'is_downpayment': self.is_downpayment,
}
self._set_analytic_distribution(res, **optional_values)
if optional_values:
res.update(optional_values)
if self.display_type:
res['account_id'] = False
return res

If you manage to reproduce it on a fresh DB/runbot, please update your commit and PR message with the steps to take.

@amoyaux
Copy link
Contributor

amoyaux commented May 6, 2024

@Sehnde You tried to do a return / credit note / return of return. Invoice again?

@Sehnde
Copy link
Contributor

Sehnde commented May 7, 2024

@amoyaux just did, here are my steps:

  • create 2 SOs, each SO has 3 SO lines for 1 unit of product A at $1/u, total $3 per SO
  • add a downpayment of $1 on each SO, validate
  • select both SOs on list view, create a single invoice for both, validate
  • do a full/partial return on both SOs (tried both)
  • do a full/partial credit note on the main invoice
  • do a return of return for everything that was initially returned (note: in v16 a return of return still indicate 'Receive From [partner]' even if the stock move are correctly from the stock to partner location/customer)
  • re-select both SOs to create a single invoice, validate
  • no bug

This is expected because the number of SO lines does not vary and each SO line creates a single invoice line at confirmation. Even if the total amount of invoice lines is higher due to multiple invoices, the filtered will only go through one at a time and there's only 1 SO line linked.
However, seeing as the field is a Many2Many linked to invoice_lines, we could still validate this PR to be logical. It should have been a Many2one based on how it's used, or the behavior was changed in stable and it was too late to switch the field type.

Copy link
Contributor

@Sehnde Sehnde left a comment

Choose a reason for hiding this comment

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

even if there's no bug, it is safer to use any + mapped with a Many2Many field

@amoyaux
Copy link
Contributor

amoyaux commented May 28, 2024

robodoo r+

robodoo pushed a commit that referenced this pull request May 28, 2024
…ales line

The issue:
When creating an invoice from multiple sale orders, each invoice line is going to be linked to the appropriate sale order line from each sale order, which will cause a singleton traceback when trying to access the is_downpayment field

Expected behavior:
to confirm the invoice

Current Behavior:
Singleton traceback

opw-3878327

closes #163766

Signed-off-by: Arnold Moyaux (arm) <arm@odoo.com>
@robodoo robodoo closed this May 28, 2024
6 similar comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants