I need to skip the section and note while creating a serial number in orderline, i made many modification,still its considering the section and notes as a line item, And its creating a serial number for section and notes.
My Python code :
from odoo import api, fields, models
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.multi
@api.depends('order_line')
def _compute_maxim_line_sequence(self):
for sale in self:
for line in sale.order_line:
if line.name:
sale.maxim_line_sequence = (
maxim(sale.mapped('order_line.sequence') or [0]) + 1)
maxim_line_sequence = fields.Integer(
string='Maxim sequence in lines',
compute='_compute_maxim_line_sequence',
store=True
)
@api.multi
def _reset_sequence(self):
for rec in self:
current_sequence = 1
for line in rec.order_line:
if line.name:
line.sequence = current_sequence
current_sequence += 1
@api.multi
def write(self, line_values):
res = super(SaleOrder, self).write(line_values)
self._reset_sequence()
return res
@api.multi
def copy(self, default=None):
return super(SaleOrder,
self.with_context(keep_line_sequence=True)).copy(default)
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
# re-defines the field to change the default
sequence = fields.Integer(
help="Gives the sequence of this line when displaying the sale order.",
default=9999,
# related='x_seq_handle',
string="Sequence"
)
# displays sequence on the order line
sequence2 = fields.Integer(
help="Shows the sequence of this line in the sale order.",
related='sequence',
string="Line Number",
readonly=True,
store=True
)
@api.model
def create(self, values):
line = super(SaleOrderLine, self).create(values)
# We do not reset the sequence if we are copying a complete sale order
if self.env.context.get('keep_line_sequence'):
line.order_id._reset_sequence()
return line
here i can't able to restrict to create serial number to only order line contains product it.
can you please help me to do this.
Hi Bharath,
I tried to follow your example but in this code (taken from module set_sequence_number) it does not work:
I wrote the line "if not line.display_type:" in all the places but I do not get it to work. I also didn't get for this other code:
I would be happy if you can show me where should the if not condition goes. I am using Odoo14.
Thank you.