How can I add sequence in sale\.order\.line\?\ let's\ say\ I\ have\ sale\.order\.line\ 1,\ 2,\ 3\.\ later\ I\ delete\ sale\.order\.line\ 2\.\ It\ should\ start\ count\ from\ sale.order.line 4. I mean It should be in a sequence 1, 3, 4. Not 1, 2, 3.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Contabilidad
- Inventario
- PoS
- Project
- MRP
Se marcó esta pregunta
1
Responder
3193
Vistas
Hi,
You can use the following code to add sequence in the sale.order.line.
Python
from odoo import api, fields, models
class SaleOrderLine(models.Model):
"""
Inherits the sale.order.line model to add a computed field 'sequence_number'
that represents a sequential line number for each line in a sale order,
excluding optional lines like display-only types.
"""
_inherit = 'sale.order.line'
sequence_number = fields.Integer(
string='#', compute='_compute_sequence_number', help='Line Numbers')
@api.depends('sequence', 'order_id')
def _compute_sequence_number(self):
"""Computes a custom sequence number for each sale order line
in the order."""
for order in self.mapped('order_id'):
sequence_number = 1
for lines in order.order_line:
if lines.display_type:
lines.sequence_number = sequence_number
sequence_number += 0
else:
lines.sequence_number = sequence_number
sequence_number += 1
XML
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!-- Inherited sale order form view-->
<record id="view_order_form" model="ir.ui.view">
<field name="name">sale.order.view.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']//tree//field[@name='product_id']"
position="before">
<field name="sequence_number"/>
</xpath>
</field>
</record>
</odoo>
Hope it helps
¿Le interesa esta conversación? ¡Participe en ella!
Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.
InscribirsePublicaciones relacionadas | Respuestas | Vistas | Actividad | |
---|---|---|---|---|
|
1
may 25
|
5942 | ||
|
0
ene 24
|
995 | ||
|
4
ene 24
|
14210 | ||
|
0
abr 25
|
733 | ||
Duplicate section on Sales order
Resuelto
|
|
2
mar 25
|
2865 |