我无法在sale.order.line
模型中使用.create(vals)
创建新的sale.order.line
,它一直给我这个错误:
File "c:usersenablr02documentsaddonsusm-backend-odoousm_salemodelssale_order.py", line 1056, in action_set_usm_produk_bonus
line.handle_produk_bonus(self.id)
File "c:usersenablr02documentsaddonsusm-backend-odoousm_salemodelssale_order.py", line 1288, in handle_produk_bonus
sol = self.create(values)
File "<decorator-gen-224>", line 2, in create
File "C:Program Files (x86)Odoo14serverodooapi.py", line 347, in _model_create_multi
return create(self, [arg])
File "C:Program Files (x86)Odoo14serverodooaddonssale_stockmodelssale_order.py", line 424, in create
lines.filtered(lambda line: line.state == 'sale')._action_launch_stock_rule()
File "c:usersenablr02documentsaddonsusm-backend-odooproduct_bundle_allmodelssale.py", line 61, in _action_launch_stock_rule
values = line._prepare_procurement_values(group_id=group_id)
File "c:usersenablr02documentsaddonsusm-backend-odooproduct_bundle_allmodelssale.py", line 97, in _prepare_procurement_values
+ timedelta(days=self.customer_lead or 0.0) - timedelta(days=self.order_id.company_id.security_lead)
File "C:Program Files (x86)Odoo14pythonlib_strptime.py", line 577, in _strptime_datetime
tt, fraction, gmtoff_fraction = _strptime(data_string, format)
File "C:Program Files (x86)Odoo14pythonlib_strptime.py", line 362, in _strptime
data_string[found.end():])
Exception
这是导致错误的功能:
def handle_produk_bonus(self,order_id):
prod_qty = self.product_uom_qty
# SaleOrderLine = self.env['sale.order.line']
print(order_id)
solines = self.env['sale.order.line'].search([('order_id','=',order_id)])
prod_bonus = self.env['product.product'].sudo().search([('default_code', '=', self.usm_promo_id.brg_bonus)])
if not prod_bonus:
prod_bonus = prod_bonus.create({
'name': 'Temp product name bonus',
'default_code': self.usm_promo_id.brg_bonus,
'type': 'product'
})
print("here")
if solines.filtered(lambda x: x.product_id.id == prod_bonus.id):
return
values = {
'order_id': order_id,
'name': prod_bonus.name,
'product_uom_qty': prod_qty * self.usm_promo_id.qty_bonus,
'product_uom': prod_bonus.uom_id.id,
'price_unit': 0,
'state':'draft',
'product_id':prod_bonus.id,
# 'product_template_id': prod_bonus.product_tmpl_id.id,
# 'tax_id': [(6, 0, taxes_ids)],
# 'is_delivery': True,
'order_line_type': 'bonus'
}
sol = self.create(values)
print(sol)
return
我试图复制类似的代码,在sale.order.line模型中创建新的so line,但仍然没有用。请在这件事上帮我
替换以下代码
sol = self.create(values)
至
self.env['sale.order.line'].create(values)
或
solines.new(values)