Merge branch 'feature/必填字段添加红星样式' into feature/刀具物料序列号优化

This commit is contained in:
yuxianghui
2024-02-28 16:53:43 +08:00

View File

@@ -14,6 +14,7 @@ from odoo.addons.stock.models.stock_rule import ProcurementException
from odoo.addons.sf_base.commons.common import Common
from odoo.exceptions import UserError
from io import BytesIO
from odoo.exceptions import ValidationError
class StockRule(models.Model):
@@ -250,6 +251,22 @@ class ProductionLot(models.Model):
))
return lot_names
def get_tool_generate_lot_names1(self, company, product):
"""
采购时生成刀具物料序列号
"""
now = datetime.now().strftime("%Y%m%d")
last_serial = self.env['stock.lot'].search(
[('company_id', '=', company.id), ('product_id', '=', product.id), ('name', 'like', now)],
limit=1, order='id DESC')
if product.cutting_tool_model_id:
if not last_serial:
return "%s-%s%03d" % (product.cutting_tool_model_id.code[:-12], now, 1)
else:
return "%s-%s%03d" % (product.cutting_tool_model_id.code[:-12], now, int(last_serial.name[-3:]) + 1)
else:
raise ValidationError('该刀具物料产品的型号字段为空,请补充完整!!!')
@api.model
def _get_next_serial(self, company, product):
"""Return the next serial number to be attributed to the product."""
@@ -258,12 +275,13 @@ class ProductionLot(models.Model):
[('company_id', '=', company.id), ('product_id', '=', product.id)],
limit=1, order='id DESC')
if last_serial:
return self.env['stock.lot'].generate_lot_names1(product.name, last_serial.name, 2)[
1]
now = datetime.now().strftime("%Y-%m-%d")
# formatted_date = now.strftime("%Y-%m-%d")
if product.categ_id.name == '刀具':
return self.env['stock.lot'].get_tool_generate_lot_names1(company, product)
else:
return self.env['stock.lot'].generate_lot_names1(product.name, last_serial.name, 2)[1]
now = datetime.now().strftime("%Y%m%d")
if product.cutting_tool_model_id:
return "%s-%s-%03d" % (product.cutting_tool_model_id.code, now, 1)
return "%s-%s%03d" % (product.cutting_tool_model_id.code[:-12], now, 1)
return "%s-%03d" % (product.name, 1)
qr_code_image = fields.Binary(string='二维码', compute='_generate_qr_code')