diff --git a/sf_bpm_api/controllers/controllers.py b/sf_bpm_api/controllers/controllers.py index 05dbb244..aeec79b6 100644 --- a/sf_bpm_api/controllers/controllers.py +++ b/sf_bpm_api/controllers/controllers.py @@ -30,8 +30,8 @@ class Sf_Bf_Connect(http.Controller): product = request.env['product.template'].sudo().product_create(product_id, item, order_id, ret['order_number'], i) order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item) - bom = request.env['mrp.bom'].sudo().bom_create(product) - bom.sudo().bom_create_Line(product) + bom = request.env['mrp.bom'].with_user(request.env.ref("base.user_admin")).bom_create(product) + bom.with_user(request.env.ref("base.user_admin")).bom_create_Line(product) i += 1 res['factory_order_no'] = order_id.name return json.JSONEncoder().encode(res) diff --git a/sf_bpm_api/models/product_template.py b/sf_bpm_api/models/product_template.py index 0ea5a772..06a691b3 100644 --- a/sf_bpm_api/models/product_template.py +++ b/sf_bpm_api/models/product_template.py @@ -54,7 +54,7 @@ class ResMrpBom(models.Model): # 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品后再次进行创建bom def bom_create(self, product): - bom_id = self.env['mrp.bom'].sudo().create({ + bom_id = self.env['mrp.bom'].create({ 'product_tmpl_id': product.product_tmpl_id.id, 'type': 'normal', 'product_qty': 1, @@ -68,16 +68,18 @@ class ResMrpBom(models.Model): # 三、胚料的长宽高均要大于模型的长宽高; # 四、如果匹配成功多个胚料,则选取体积最小的胚料; def bom_create_Line(self, product): - embryo = self.env['product.template'].sudo().search( + embryo = self.env['product.product'].search( [('categ_id.is_embryo', '=', True), ('embryo_materials_type_id', '=', product.model_materials_type_id.id), ('embryo_long', '>', product.model_long), ('embryo_width', '>', product.model_width), - ('embryo_height', '>', product.model_height)], + ('embryo_height', '>', product.model_height) + ], limit=1, - order="volume desc" + order='volume desc' ) vals = { 'bom_id': self.id, 'product_id': embryo.id, + 'product_tmpl_id': embryo.product_tmpl_id.id, 'product_qty': 1, 'product_uom_id': 1 }