I Want The Code In Compute because I Test Every Step, but it doesn't work
And thank you for helping me
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Comptabilitat
- Inventari
- PoS
- Project
- MRP
This question has been flagged
Hi,
Try the following code,
class SaleOrderLine(models.Model):
""" Class for inherited model sale order line. Contains a field for line
numbers and a function for computing line numbers.
"""
_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):
"""Function to compute line numbers"""
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
Hope it helps
Hi Yuossef,
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
sl_no = fields.Integer(string="Sl. No.", compute="_compute_sl_no")
@api.depends('order_id.order_line', 'order_id.order_line.display_type', 'order_id.order_line.sequence')
def _compute_sl_no(self):
for order in self.mapped('order_id'):
index = 0
for line in order.order_line:
if not line.display_type:
index += 1
line.sl_no = index
else:
line.sl_no = False
Hope this helps.
from odoo import models, fields, api
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
sequence_number = fields.Char(string='Sequence', compute='_compute_sequence')
@api.depends('order_id', 'order_id.state')
def _compute_sequence(self):
for line in self:
if line.order_id:
sequence = line.order_id.sequence_next()
line.sequence_number = sequence
sequence_number is a computed field that generates the sequence.
order_id.sequence_next() can be used to fetch the next available sequence for the order.
Make sure you also have a sequence defined for the sale.order model or use the built-in ir.sequence model to manage sequence generation. Adjust the logic as needed based on your specific requirements.
Add a new field in so and add the automation action
i = 1
for line in record.order_line.sorted(key=lambda l: l.sequence):
if line.display_type not in ('line_section', 'line_note'):
line.write({'x_studio_so_line_number': i})
i += 1
and this code for invoce
i = 1
for line in record.invoice_line_ids.sorted(key=lambda l: l.sequence):
if line.display_type not in ('line_section', 'line_note'):
line.write({'x_studio_line': i})
i += 1
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Registrar-se| Related Posts | Respostes | Vistes | Activitat | |
|---|---|---|---|---|
|
|
1
d’oct. 24
|
2440 | ||
|
|
2
de set. 25
|
2892 | ||
|
|
1
d’ag. 25
|
2297 | ||
|
|
1
d’ag. 25
|
1232 | ||
|
|
0
de jul. 25
|
1249 |
What is "the code"?
In Advanced Properties, Compute
I mean this