我有向导的代码:
class generate_stock_picking(models.TransientModel):
_name = 'generate.stock.picking'
isbns = fields.One2many('order.lines', 'order_id', 'ISBN')
production_order = fields.Many2one('bsi.print.order', 'Print Order')
company_id = fields.Many2one('res.company', 'Company',default='_default_company')
location_id = fields.Many2one('stock.location', string="Source Location")
location_dest_id = fields.Many2one('stock.location', string="Destination Location")
@api.model
def default_get(self, fields):
res = super(generate_stock_picking, self).default_get(fields)
isbns = []
if self.env.context.has_key('active_id'):
production_order = self.env.context['active_id']
order = self.env['bsi.print.order'].browse(production_order)
sp_types = self.env['stock.picking.type'].search([
('code', '=', 'incoming')
])
if len(sp_types) > 0:
for line in order.order_lines:
if line.remaining_qty > 0:
val = {
#'origin': line.name,
'isbn':line.isbn.id,
'qty': line.remaining_qty,
'picking_type_id': sp_types[0].id,
}
isbns.append([0,0,val])
res.update({'isbns':isbns,'production_order':production_order})
return res
@api.multi
def generate(self):
if self.isbns:
order_lines = []
sp_types = self.env['stock.picking.type'].search([
('code', '=', 'incoming')
])
print_order = self.env['stock.picking'].create({
'origin': self.name.id,
'state': 'draft',
'stock_picking_lines': self.production_order.id,
'picking_type_id': sp_types[0].id,
})
for line in self.isbns:
order_lines.append(self.env['bsi.print.order.lines'].create({
'print_order':print_order.id,
'isbn':line.isbn.id,
'qty':line.qty}))
prod_isbn = self.env['bsi.print.order.lines'].search([('production_order','=',self.production_order.id),
('isbn','=',line.isbn.id)])
prod_isbn.consumed_qty = line.qty
print_order.write({'order_lines':[(6,0,map(lambda x:x.id,order_lines))]})
tree_view_id = self.env.ref('stock.vpicktree').id
form_view_id = self.env.ref('stock.view_picking_form').id
self.production_order.state = 'delivered'
return {
'name': _('Stock Picking'),
'type': 'ir.actions.act_window',
'res_model': 'stock.picking',
'view_mode': 'tree,form',
'view_type': 'form',
'views': [(tree_view_id, 'tree'),(form_view_id, 'form')],
'view_id':tree_view_id,
'res_id': [print_order.id],
'domain': [('id', 'in', [print_order.id])]
}
这应该从stock.picking
bsi.print.order
但它让我觉得这个:
Traceback (most recent call last):
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 546, in _handle_exception
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 583, in dispatch
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 319, in _call_function
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\service\model.py", line 118, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 316, in checked_call
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 812, in __call__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 412, in response_wrap
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 948, in call_button
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 399, in old_api
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\bsi\wizard\generate_stock_picking.py", line 45, in generate
AttributeError: 'generate.stock.picking' object has no attribute 'name'
我需要传递name
和其他几个字段,因为stock.picking
有One2many到stock.move
。
这个向导最初被设想为只将一条模型中的线传递给另一模型。
在这种情况下,它应该将行stock.move
和行外的其他字段传递给stock.picking
。
我有这种方法可以做类似的事情(实际上它可以工作),但它不是一个向导:
@api.multi
def create_printy(self):
copy_record = self.env['stock.picking']
for record in self:
order_lines = []
for rec in record.order_lines:
order_lines.append(
(0,0,
{
'name': 'name',
'product_id': rec.isbn.id,
'product_uom': rec.isbn.uom_id.id,
'date_expected': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
'product_uom_qty': rec.qty,
'location_id': record.location_id.id,
'location_dest_id': record.location_dest_id.id,
}
))
sp_types = self.env['stock.picking.type'].search([
('code', '=', 'incoming')
])
if len(sp_types) > 0:
copy_record.create({
'origin': record.name,
'picking_type_id': sp_types[0].id,
'move_lines': order_lines,
'move_type': 'direct',
'priority': '1',
'company_id': record.company_id.id,
})
self.write({'state': 'delivered',},)
我知道的行已经如何传递它们,但我如何调整stock.picking
字段? (即:create_printy方法的copy_record)