我想在调用活动后从销售订单中的自定义类中创建带有产品的记录集。我将在sale.order创建一个记录,就像创建发票一样,我将在我的自定义模块中创建记录。
我所做的是:
在我的自定义类中:
class sale_func(models.Model):
_inherit = 'sale.order'
@api.multi
def _prepare_slip(self):
test.set_trace()
self.ensure_one()
slip = {
'partner_id': self.partner_id.name,
'order_date': self.date_order,
'expiration_date': self.validity_date,
}
return slip
@api.multi
def action_slip_create(self, grouped=False, final=False):
test.set_trace() # debug point
pprint(self)
inv_obj = self.env['loading.slip']
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
slips={}
pprint(slips)
slipReferences={}
test.set_trace()
for order in self:
group_key = order.id
test.set_trace()
for line in order.order_line:
if group_key not in slips:
inv_data = order._prepare_slip()
loadingslip = inv_obj.create(inv_data)
slipReferences[loadingslip] = order
slips[group_key] = loadingslip
if line.product_uom_qty > 0:
line.slip_line_create(slips[group_key].id)
if not slips:
raise UserError(_('There is no loading slip line.'))
@api.multi
def create_slip(self):
test.set_trace()
pprint(self)
sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', []))
self.action_slip_create(sale_orders)
在sale.order
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)
在sale.order.line
> /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"
我的错误是:
If Weekday(Date, vbSunday) < Weekday(Date, vbThursday) Then
ActiveWorkbook.SaveAs Filename:="C:\Users\Andrew\Downloads\Test\" & "Predictions - " & Format(Date + 7 - Weekday(Date, vbThursday), "mmmm dd") & ".xlsm"
Else
ActiveWorkbook.SaveAs Filename:="C:\Users\Andrew\Downloads\Test\" & "Predictions - " & Format(Date + 7 - Weekday(Date, vbSunday), "mmmm dd") & ".xlsm"
End If
我尝试过更新和写入方法,而不是在第196行创建,但我无法得到任何结果,它只是想出一个空字段,也没有错误。但是,当我尝试真实的东西,即write()时,我得到了这个错误。在我的代码中某处是否有任何错误,或者我正在做的事情只是一件可怕的事情。