Skip to Content
Menu
This question has been flagged
1 Reply
26 Views

I need your help with Odoo. Where I need to create a Sales order and as you know there can be many products in a purchase order. So firstly I need to enumerate the products rows like

1. Product name |  ........

2. Products name | ......

and as you know odoo don;t have this enumeration on default and the next thing I want to do with it is to print a quote but products in the quote must follow some rules like this:

This how the purchase order looks like

1. Product name |  Quantity 12

2. Products name | Quantity 0

3. Products name | Quantity 53

But when i check the quote it must look like this:

1. Product name |  Quantity 12

3. Products name | Quantity 53

2. Products name | Quantity 0


So the products with quantity 0 must be at the bottom but the number of row must not change in quote.

If there is something you can't understand about the problem ask me

Avatar
Discard
Best Answer
  1. Sales Order (form view & backend):
    • Show order lines enumerated as 1, 2, 3, ... based on the actual order in the list.
    • Even if quantity is 0, the row number must reflect its position.
  2. Quotation (report/print template):
    • Show the same rows, but:
      • Sort the products so that lines with quantity = 0 go to the bottom.
      • Row numbers stay the same as backend — not re-numbered after sorting.


How to Implement (Steps):

1. Add Row Number in Sales Order Lines:

You can do this using a computed field in a custom module :

from odoo import models, fields

class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'

    row_number = fields.Integer(string='Row #', compute='_compute_row_number', store=True)

    def _compute_row_number(self):
        for order in self.mapped('order_id'):
            for idx, line in enumerate(order.order_line, start=1):
                line.row_number = idx

This will assign row numbers based on the order they appear in the UI.


2. Customize the Quotation Report Template:

In your report template (sale.report_saleorder_document), override the line rendering part like this:

<t t-set="sorted_lines" t-value="sorted(order.order_line, key=lambda l: (l.product_uom_qty == 0, l.row_number))"/>
<t t-foreach="sorted_lines" t-as="line">
    <tr>
        <td><span t-esc="line.row_number"/></td>
        <td><span t-esc="line.name"/></td>
        <td><span t-esc="line.product_uom_qty"/></td>
        ...
    </tr>
</t>

This does:

  • Sorts by (quantity == 0, row_number): i.e., it pushes zero-qty lines to the bottom.
  • But keeps the original row_number so the index doesn't change.


IF:

  • You recompute row numbers on line changes (add proper dependencies).
  • You customize the report XML as shown.
  • You don't allow users to move lines around without triggering re-computation


Thanks  & Regards,

Email :- contact@datainteger.com

Avatar
Discard
Related Posts Replies Views Activity
3
Oct 23
2914
1
Jan 25
668
2
Jul 24
1287
0
Jul 21
2650
2
Dec 15
4615