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
- Boekhouding
- Voorraad
- PoS
- Project
- MRP
Deze vraag is gerapporteerd
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
Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!
Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!
Aanmelden| Gerelateerde posts | Antwoorden | Weergaven | Activiteit | |
|---|---|---|---|---|
|
|
1
okt. 24
|
2748 | ||
|
|
1
nov. 25
|
520 | ||
|
|
2
sep. 25
|
3295 | ||
|
|
1
aug. 25
|
2562 | ||
|
|
1
aug. 25
|
1554 |
What is "the code"?
In Advanced Properties, Compute
I mean this