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
- Księgowość
- Zapasy
- PoS
- Project
- MRP
To pytanie dostało ostrzeżenie
1
Odpowiedz
3183
Widoki
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
Podoba Ci się ta dyskusja? Dołącz do niej!
Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!
Zarejestruj sięPowiązane posty | Odpowiedzi | Widoki | Czynność | |
---|---|---|---|---|
|
1
maj 25
|
5921 | ||
|
0
sty 24
|
992 | ||
|
4
sty 24
|
14205 | ||
|
0
kwi 25
|
726 | ||
Duplicate section on Sales order
Rozwiązane
|
|
2
mar 25
|
2861 |