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

Post Invoice with lines with mulltiple Sale lines #77028

Open
stacyharper opened this issue Sep 23, 2021 · 3 comments
Open

Post Invoice with lines with mulltiple Sale lines #77028

stacyharper opened this issue Sep 23, 2021 · 3 comments

Comments

@stacyharper
Copy link

stacyharper commented Sep 23, 2021

Impacted versions: 14.0

Steps to reproduce: Create an Invoice with one line that links multiple Sale Order Lines and try to post this invoice

Current behavior: Failure

Expected behavior: Post the Invoice

The issue come from addons/sale/models/account_move.py:15

line_ids = self.mapped('line_ids').filtered(lambda line: line.sale_line_ids.is_downpayment)

This call is_downpayment on a Many2Many fields that here links to multiple Sale Order Lines.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/stacy/sources/odoo/odoo/addons/base/controllers/rpc.py", line 69, in xmlrpc_2
    response = self._xmlrpc(service)
  File "/home/stacy/sources/odoo/odoo/addons/base/controllers/rpc.py", line 49, in _xmlrpc
    result = dispatch_rpc(service, method, params)
  File "/home/stacy/sources/odoo/odoo/http.py", line 140, in dispatch_rpc
    result = dispatch(method, params)
  File "/home/stacy/sources/odoo/odoo/service/model.py", line 41, in dispatch
    res = fn(db, uid, *params)
  File "/home/stacy/sources/odoo/odoo/service/model.py", line 168, in execute_kw
    return execute(db, uid, obj, method, *args, **kw or {})
  File "/home/stacy/sources/odoo/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/stacy/sources/odoo/odoo/service/model.py", line 175, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/stacy/sources/odoo/odoo/service/model.py", line 159, in execute_cr
    result = odoo.api.call_kw(recs, method, args, kw)
  File "/home/stacy/sources/odoo/odoo/api.py", line 396, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/home/stacy/sources/odoo/odoo/api.py", line 383, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/home/stacy/sources/odoo/local-addons/taxjar_integration_ts/models/account_move.py", line 87, in action_post
    res = super(AccountMove, self).action_post()
  File "/home/stacy/sources/odoo/addons/sale/models/account_move.py", line 15, in action_post
    line_ids = self.mapped('line_ids').filtered(lambda line: line.sale_line_ids.is_downpayment)
  File "/home/stacy/sources/odoo/odoo/models.py", line 5281, in filtered
    return self.browse([rec.id for rec in self if func(rec)])
  File "/home/stacy/sources/odoo/odoo/models.py", line 5281, in <listcomp>
    return self.browse([rec.id for rec in self if func(rec)])
  File "/home/stacy/sources/odoo/addons/sale/models/account_move.py", line 15, in <lambda>
    line_ids = self.mapped('line_ids').filtered(lambda line: line.sale_line_ids.is_downpayment)
  File "/home/stacy/sources/odoo/odoo/fields.py", line 963, in __get__
    record.ensure_one()
  File "/home/stacy/sources/odoo/odoo/models.py", line 4991, in ensure_one
    raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: sale.order.line(10731, 10732, 10733, 10734, 10735, 10736, 10737, 10738, 10739, 10740, 10741, 10742, 10743, 10744, 10745)
from /usr/local/lib/ruby/2.3.0/xmlrpc/client.rb:272:in `call'

Something that works :

diff --git a/addons/sale/models/account_move.py b/addons/sale/models/account_move.py
index b9899195b80..a32416734b6 100644
--- a/addons/sale/models/account_move.py
+++ b/addons/sale/models/account_move.py
@@ -12,7 +12,7 @@ class AccountMove(models.Model):
     def action_post(self):
         #inherit of the function from account.move to validate a new tax and the priceunit of a downpayment
         res = super(AccountMove, self).action_post()
-        line_ids = self.mapped('line_ids').filtered(lambda line: line.sale_line_ids.is_downpayment)
+        line_ids = self.mapped('line_ids').filtered(lambda line: line.sale_line_ids._is_downpayment())
         for line in line_ids:
             try:
                 line.sale_line_ids.tax_id = line.tax_ids
diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py
index 444665f4c81..39f53684c33 100644
--- a/addons/sale/models/sale.py
+++ b/addons/sale/models/sale.py
@@ -1740,6 +1740,13 @@ class SaleOrderLine(models.Model):
             )
             self.price_unit = self.env['account.tax']._fix_tax_included_price_company(self._get_display_price(product), product.taxes_id, self.tax_id, self.company_id)
 
+    def _is_downpayment(self):
+        for line in self:
+            if not line.is_downpayment:
+                return False
+
+        return True
+
     def name_get(self):
         result = []
         for so_line in self.sudo():

This check if all SaleOrderLine are downpayments but I'm not sure this is the best way to do this.

@sswapnesh
Copy link
Contributor

@stacyharper

Create an Invoice with one line that links multiple Sale Order Lines and try to post this invoice

How can you create Invoice (One Invoice Line) for multiple Sale lines through UI ?

@stacyharper
Copy link
Author

stacyharper commented Sep 24, 2021 via email

@sswapnesh
Copy link
Contributor

Added Fix #77195

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants