我有向导的代码:
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)