欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程语言 > python >内容正文

python

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

发布时间:2023/12/20 python 50 豆豆
生活随笔 收集整理的这篇文章主要介绍了 python实现快速创建订单_从销售订单和Od中的产品订单创建新记录 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

我想在调用事件后用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()时,我得到了这个错误。我的代码中有什么错误吗?还是我正在做一件可怕的事情。在

总结

以上是生活随笔为你收集整理的python实现快速创建订单_从销售订单和Od中的产品订单创建新记录的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。