如果memo_data [' items']中只有一个产品,则会创建销售订单行,但如果有两个或更多产品,则会重新输入错误:要解压缩的值过多。 这是代码:
for item in memo_data['items']:
c_id = self.env['sale.order.line'].search([('creditmemo_id','=',memo_data['creditmemo_id'])])
if not c_id:
_logger.info("THIS IS CID: %s" % memo_data['creditmemo_id'])
a_product = self.env['product.product'].search([('default_code', '=',item['sku'])])
if a_product:
_logger.info("FOUND THE PRODUCT with id: %s" %a_product.id)
pos_price = float(item['row_total'])
neg_price = pos_price - (2 * pos_price)
res12 = {
'order_id': is_exist.id,
'product_id': a_product.id,
'price_unit': neg_price,
'sequence': 10,
'product_uom_qty': float(item['qty']),
'creditmemo_id' : memo_data['creditmemo_id'],
'creditmemo_date': memo_data['created_at'],
'creditmemo_increment_id' : memo_data['increment_id'],
}
self.env['sale.order.line'].create(res12)`enter code here`
答案 0 :(得分:0)
我假设您正在尝试循环记录列表。但是内部循环尝试将memo_data更改为item:
for item in memo_data['items']:
c_id = self.env['sale.order.line'].search([('creditmemo_id','=',item['creditmemo_id'])])
if not c_id:
_logger.info("THIS IS CID: %s" % item['creditmemo_id'])
a_product = self.env['product.product'].search([('default_code', '=',item['sku'])])
if a_product:
_logger.info("FOUND THE PRODUCT with id: %s" %a_product.id)
pos_price = float(item['row_total'])
neg_price = pos_price - (2 * pos_price)
res12 = {
'order_id': is_exist.id,
'product_id': a_product.id,
'price_unit': neg_price,
'sequence': 10,
'product_uom_qty': float(item['qty']),
'creditmemo_id' : item['creditmemo_id'],
'creditmemo_date': item['created_at'],
'creditmemo_increment_id' : item['increment_id'],
}
答案 1 :(得分:0)
我认为你需要像这样处理你的词典
for field, possible_values in fields.iteritems():
print field, possible_values
python 2.7:iteritems() python 3:items()。
由于