[FIX] sale_pdf_quote_builder: skip fmt empty SOLs
**Current behavior:** Trying to print or send a sale order quotation that contains non-saleable lines (notes or sections) will result in a ValueError. --- **Expected behavior:** The quotation should print/download or be prepared for sending. --- **Steps to reproduce:** 1. Create a new quotation with at least one note or section line 2. Click the action gear, select Print -> PDF Quote --- **Cause of the issue:** A method involved in the control flow for building a PDF from a quotation, _get_sol_form_fields_mapping(), attempts to format the sale price of all order lines involved in an order without first ensuring one exists. --- **Fix:** The fix prevents _get_sol_form_fields_mapping() from being invoked if the SOL does not have a linked doc (i.e., if the line has no associated product and thus no price). opw-3664710 closes odoo/odoo#148291 Signed-off-by: Morgane Demesmaeker <edm@odoo.com>
This commit is contained in:
@@ -57,7 +57,7 @@ class IrActionsReport(models.Model):
|
||||
footer_stream = IrBinary._record_to_stream(footer_record, 'sale_footer').read()
|
||||
self._add_pages_to_writer(writer, footer_stream)
|
||||
|
||||
form_fields = self._get_form_fields_mapping(order)
|
||||
form_fields = self._get_form_fields_mapping(order, doc_line_id_mapping)
|
||||
pdf.fill_form_fields_pdf(writer, form_fields=form_fields)
|
||||
with io.BytesIO() as _buffer:
|
||||
writer.write(_buffer)
|
||||
@@ -112,7 +112,7 @@ class IrActionsReport(models.Model):
|
||||
return ['description', 'quantity', 'uom', 'price_unit', 'discount', 'product_sale_price',
|
||||
'taxes', 'tax_excl_price', 'tax_incl_price']
|
||||
|
||||
def _get_form_fields_mapping(self, order):
|
||||
def _get_form_fields_mapping(self, order, doc_line_id_mapping=None):
|
||||
""" Dictionary mapping specific pdf fields name to Odoo fields data for a sale order.
|
||||
Override this method to add new fields to the mapping.
|
||||
|
||||
@@ -138,7 +138,8 @@ class IrActionsReport(models.Model):
|
||||
}
|
||||
|
||||
# Adding fields from each line, prefixed by the line_id to avoid conflicts
|
||||
for line in order.order_line:
|
||||
lines_with_doc_ids = set(doc_line_id_mapping.values())
|
||||
for line in order.order_line.filtered(lambda sol: sol.id in lines_with_doc_ids):
|
||||
form_fields_mapping.update(self._get_sol_form_fields_mapping(line))
|
||||
|
||||
return form_fields_mapping
|
||||
|
||||
Reference in New Issue
Block a user