我需要获取与其服务订单相关的订单号。每个服务订单都有许多工作订单。例如:如果服务订单号是223,则与此相关的工作台订单是223-1,223-2,223-3 ......如果SO编号为553,则工作台订单编号必须为553-1,553-2,553 -3等等。
我尝试了几种方法而且没有做到。请帮我。我使用Odoo序列来做到这一点,但它没有按我的意愿提供输出。这是我的代码:(例如:223表示工作授权号)。
class MyDepots_so(models.Model):
_name = 'my_depots_so'
so_parts_ids = fields.One2many('tiq_so_parts', 'so_p_id', string='Add Part Details', invisible='1')
so_bo_ids = fields.One2many('my_depots.so_bo',
so_work_authorization = fields.Integer("Work Authorization#")
class SO_Parts(models.Model):
_name = 'tiq_so_parts'
so_p_id = fields.Many2one('my_depots_so',string='Add Service Order Part', invisible='1')
@api.model
def create(self, vals):
sequence = self.env['ir.sequence'].next_by_code('so.benchorder') or '/'
str_sequence = str(sequence)
query = """SELECT so_work_authorization FROM my_depots_so WHERE id=%d """ % (so_p_id)
self.env.cr.execute(query)
result = self.env.cr.fetchall()
result_number = json.dumps(result, ensure_ascii=False)
strip_number = result_number.strip('\' \" [] ')
work_auth_no = str(strip_number)
work_auth_no += "-"
work_auth_no += str_sequence
答案 0 :(得分:0)
好吧,我认为你正在寻找这样的东西(我在tiq_so_parts
模型中添加了一个字段,因为你必须将子序列存储在某个地方 - 你存储 223-1 , 223-2 , 223-3 ...值?
我创建了字段part_sequence
来存储这些值 - )。
class MyDepots_so(models.Model):
_name = 'my_depots_so'
so_parts_ids = fields.One2many('tiq_so_parts', 'so_p_id', string='Add Part Details', invisible='1')
so_bo_ids = fields.One2many('my_depots.so_bo',
so_work_authorization = fields.Integer("Work Authorization#")
class SO_Parts(models.Model):
_name = 'tiq_so_parts'
so_p_id = fields.Many2one('my_depots_so',string='Add Service Order Part', invisible='1')
part_sequence = fields.Char(string='Part Sequence')
@api.model
def create(self, vals):
so_part = super(SO_Parts, self).create(vals)
so_p_id = so_part.so_p_id
main_sequence = so_p_id.so_work_authorization
part_sequence = len(so_p_id.so_parts_ids)
so_part.write({
'part_sequence': str(main_sequence) + '-' + str(part_sequence),
})
return so_part