问题描述
我想要的很简单,但我不知道该怎么做,如果有人可以帮助我,我会很高兴 所以我有这个 One2many 树视图:
对于这个模型:
class StockInventoryDeGroupeLine(models.Model):
_name = 'stock.inventory.degroupe.line'
_order = 'sequence'
stock_inventory_id = fields.Many2one(
'stock.inventory',string='stock',)
product_id = fields.Many2one(
'product.product',string='Article',)
quantity = fields.Float(
string='Quantité',)
display_type = fields.Selection([
('line_section',"Section"),('line_emplacement',"Emplacement"),('line_note',"Note"),],default=False,help="Technical field for UX purpose.")
name = fields.Text(
string='Description',required=False,)
sequence = fields.Integer(
string='Sequence',default=10,)
location_id = fields.Many2one(
'stock.location',string='Emplacement',)
prod_lot_id = fields.Many2one(
'stock.production.lot','Lot/numéro de sérié',)
product_tracking = fields.Selection(
'Suivi',related='product_id.tracking',readonly=True)
_sql_constraints = [('unique_seq','UNIQUE(sequence)',"La sequence doit être unique"),]
@api.onchange('product_id','sequence')
def onchange_product_id(self):
for record in self:
if record.display_type == False or record.display_type == 'line_emplacement' :
if record.sequence == 10 :
record.location_id = record.stock_inventory_id.location_id
return
else :
new_sequence = record.sequence -1
while new_sequence >= 10 :
for record2 in record.stock_inventory_id.degroupee_line_ids :
if record2.sequence == new_sequence :
if record2.display_type != 'line_section':
record.location_id = record2.location_id
return
new_sequence -= 1
@api.onchange('product_id','location_id','name')
def onchange_sequence(self):
for record in self :
record.sequence += 1
当我处于编辑模式时,我想禁用按文章、批次、位置排序... 为了简单起见,我只想按顺序对其进行排序
解决方法
也许它会帮助你...
将您的序列字段放在 one2many 树视图中作为不可见..