机床唯一编码生成

This commit is contained in:
gqh
2022-11-23 11:00:07 +08:00
parent cc739a218e
commit 1582896ac4
4 changed files with 23 additions and 4 deletions

View File

@@ -45,7 +45,21 @@ class MachineBrand(models.Model):
class MachineTool(models.Model):
_name = 'sf.machine_tool'
_description = '机床'
MTcode = fields.Char("编码")
def get_no(self):
partner = self.env['sf.machine_tool'].sudo().search(
[('MTcode', '!=', '')],
limit=1,
order="id desc")
if not partner:
num = "%04d" % 1
else:
m = int(partner.MTcode) + 1
num = "%04d" % m
return num
MTcode = fields.Char("编码", default=get_no)
code = fields.Char('行业编码')
name = fields.Char('名称')
knife_type = fields.Selection(
@@ -148,11 +162,12 @@ class MachineTool(models.Model):
sf_secret_key = sf_sync_config['sf_secret_key']
headers = Common.get_headers(self, token, sf_secret_key)
strurl = sf_sync_config['sf_url'] + self.crea_url
objs_all = request.env['sf.machine_tool'].sudo().search([])
objs_all = self.env['sf.machine_tool'].search([('MTcode', '=', self.MTcode)])
machine_tool_list = []
if objs_all:
for item in objs_all:
val = {
'MTcode': item.MTcode,
'factory_token': token,
'id': item.id,
'name': item.name,
@@ -247,4 +262,3 @@ class CuttingToolType(models.Model):
brand_id = fields.Many2one('sf.machine.brand', string='品牌')
remark = fields.Text('备注')
active = fields.Boolean('有效', default=True)