python实现快速创建订单_从销售订单和Od中的产品订单创建新记录

本文档介绍如何在Odoo中通过Python自定义类`LoadingSlip`和`LoadingProduct`实现从销售订单创建加载产品记录。在`sales_order`模型中继承并定义了`_prepare_slip_line`和`slip_line_create`方法,用于生成记录。然而,在执行过程中遇到`TypeError: argument of type 'NoneType' is not iterable`的错误。作者尝试使用`update`和`write`方法但未成功,并寻求解决方案。
摘要由CSDN通过智能技术生成

我想在调用事件后用sale order自定义类中的产品创建记录集。我将在中创建一个记录销售订单和创建发票一样,我将在我的自定义模块中创建记录。在

我所做的是:

在我的自定义类中:class LoadingSlip(models.Model):

_name = 'loading.slip'

_description = 'loading information'

partner_id = fields.Char("Customer Name")

order_date = fields.Date("Order Date")

expiration_date = fields.Date("Expiration Date")

# order_line = fields.One2many('sale.order.line', 'order_id', string="Order Lines")

product_line = fields.One2many('loading.product.line', 'loading_product', string="Loading Products")

class LoadingProduct(models.Model):

_name = 'loading.product.line'

_description = "Loading Product Informations"

products_id = fields.Many2one('product.product', string='Product',

ondelete='restrict', index=True)

quantity = fields.Float(string='Quantity', default=1)

loading_product = fields.Many2one('loading.slip', string="Loading Reference", ondelete='cascade', index='True')

在销售订单

^{pr2}$

在销售订单行class sales_order(models.Model):

_inherit="sale.order.line"

@api.multi

def _prepare_slip_line(self):

test.set_trace()

self.ensure_one()

res={}

pprint(res)

res={

'products_id': self.product_id.id or False,

'quantity': self.product_uom_qty

}

pprint(res)

@api.multi

def slip_line_create(self, loading_product):

test.set_trace()

prdct_order = self.env['loading.product.line']

for line in self:

vals = line._prepare_slip_line()

prdct_order.create(vals)

我的错误是:> /home/diwap/odoo-dev/custom-addons/sales_ext_agni/models/models.py(196)slip_line_create()

195 vals = line._prepare_slip_line()

--> 196 prdct_order.create(vals)

197

ipdb> n

TypeError: "argument of type 'NoneType' is not iterable"

我尝试过update-and-write方法而不是create在第196行中,但是我没有得到任何结果,它只是出现了一个空字段,也没有错误。但是,当我尝试实际的东西,即write()时,我得到了这个错误。我的代码中有什么错误吗?还是我正在做一件可怕的事情。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值