[FIX] sale_management: maintain template lines order on Confirm

Steps to reproduce:
- Install Sales app
- Open Sales app, Go to Configuration > Quotation Templates
- Open a template, or create an new one
- Add sections with product(s) under each, so we have a structure like:
        - Section 1
        - Product 1
        - Section 2
        - Product 2
- Go to Orders > Quotations
- Create a New Quotation
- Select the recently created/updated template in the Quotation Template field
- Click on Confirm
- U can notice how the sections are moved to the top, missing up the structure

Investigation:
- Each sale order order_line has a sequence property associated to it which defaults to 10 if not explicitly specified https://github.com/odoo/odoo/blob/55b452ac0056c7075097fa1324ef53fc5090fb7a/addons/sale/models/sale_order_line.py#L41
- On Choosing a template, the _prepare_order_line_values() method returns the needed properties for each template line https://github.com/odoo/odoo/blob/55b452ac0056c7075097fa1324ef53fc5090fb7a/addons/sale_management/models/sale_order.py#L108
- The returned object for each template is missing the sequence property, resulting in it falling back to 10 when assigning it to the sale order order_line https://github.com/odoo/odoo/blob/55b452ac0056c7075097fa1324ef53fc5090fb7a/addons/sale_management/models/sale_order.py#L117
- Now all order_line(s) has the same sequence -except for the first one which has a sequence value of -99- https://github.com/odoo/odoo/blob/55b452ac0056c7075097fa1324ef53fc5090fb7a/addons/sale_management/models/sale_order.py#L114-L115

opw-3602781

closes odoo/odoo#144700

Signed-off-by: Ali Hassan Youssef (alhy) <alhy@odoo.com>
This commit is contained in:
AH-Yussef
2023-12-11 08:29:17 +00:00
parent 52191b832f
commit 0eeee0cd53
@@ -110,4 +110,5 @@ class SaleOrderTemplateLine(models.Model):
'product_id': self.product_id.id,
'product_uom_qty': self.product_uom_qty,
'product_uom': self.product_uom_id.id,
'sequence': self.sequence,
}