我试图创造股票走势。这是我的脚本代码:
if self.qty_abnormal > 0:
move_data = {
'product_id': self.batch_id.product_id.id,
'product_uom_qty': self.qty_abnormal,
'product_uom': self.batch_id.product_id.uom_id.id,
'name': 'Selection: %s' % self.batch_id.product_id.display_name,
'date_expected': self.selection_date,
'location_id': self.picking_id.location_dest_id.id,
'location_dest_id': self.culling_location_id.id,
'state': 'confirmed', # set to done if no approval required
'restrict_lot_id': self.batch_id.id # required by check tracking product
}
move = self.env['stock.move'].create(move_data)
move.action_confirm()
move.action_done()
然后我点击批准移动股票,查看错误。这是我的错误:
"列中的空值" location_id"违反非空约束 失败的行包含(52,null,null,2015-10-28 04:30:59.606056, null,1,null,7.000,1,2015-10-28 04:30:59,null,null,null,1, null,null,null,confirmed,null,null,2015-11-18 00:00:00,null, 选择:[090901] Kecambah Dami Mas,1,null,null,f,t,null, make_to_stock,1,5,null,56,null,null,null,2015-10-28 04:30:59.606056,null,null,none,null)。 "在评估时 U' action_approved()'
请帮帮我。
答案 0 :(得分:1)
您的模型所引用的选择似乎不包含 location_dest_id ,或者您的模型中未选择选择。
<强>解决方案:强>
required=True
,继续在模型中选择必填字段。您还应该在评估下面的代码时检查条件。
assert self.picking_id, "Picking is mandatory!!!"
assert self.picking_id.location_dest_id, "Location must be there in picking!!!!"
在stock.picking中不知道目的地位置是否是强制性的。
from openerp.exceptions import except_orm
@api.one
def action_move(self):
"""
Selection do one actions:
1. Move quantity of selection to culling location.
"""
# Get unique location of planted location
location_ids = set()
for item in self.selectionline_ids:
if item.location_id and item.qty_batch > 0: # todo do not include empty quantity location
location_ids.add(item.location_id)
if not self.picking_id or not self.culling_location_id:
raise except_orm(_('Unable to process!'),_("Exception Message!!..."))
if not self.picking_id.location_dest_id:
raise except_orm(_('Unable to process!'),_("Exception Message!!..."))
# Move quantity abnormal seed
if self.qty_abnormal > 0:
move_data = {
'product_id': self.batch_id.product_id.id,
'product_uom_qty': self.qty_abnormal,
'product_uom': self.batch_id.product_id.uom_id.id,
'name': 'Selection: %s' % self.batch_id.product_id.display_name,
'date_expected': self.selection_date,
'location_id': self.picking_id.location_dest_id.id,
'location_dest_id': self.culling_location_id.id,
'state': 'confirmed', # set to done if no approval required
'restrict_lot_id': self.batch_id.id # required by check tracking product
}
move = self.env['stock.move'].create(move_data)
move.action_confirm()
move.action_done()
return True
答案 1 :(得分:0)
这是我的班级模特。和领域
class Selection(models.Model):
"""Seed Selection"""
_name = 'estate.nursery.selection'
picking_id= fields.Many2one('stock.picking', "Picking", readonly=True)
lot_id = fields.Many2one('stock.production.lot', "Lot",required=True, ondelete="restrict", domain=[('product_id.seed','=',True)])
selectionline_ids = fields.One2many('estate.nursery.selectionline', 'selection_id', "Selection Lines")
batch_id = fields.Many2one('estate.nursery.batch', "Batch")
stage_id = fields.Many2one('estate.nursery.stage',"Stage")
selectionstage_id = fields.Many2one('estate.nursery.selectionstage',"Selection Stage",
required=True)
qty_normal = fields.Integer("Normal Seed Quantity",)
qty_abnormal = fields.Integer("Abnormal Seed Quantity",)
date_plant = fields.Date("Planted Date",required=False,readonly=True,related='batch_id.date_planted',store=True)
qty_batch = fields.Integer("DO Quantity",required=False,readonly=True,related='batch_id.qty_received',store=True)
presentage_normal = fields.Float("Persentage Normal",digits=(2,2),required=False)
presentage_abnormal = fields.Float("Persentage Abnormal",digits=(2,2), required=False)
selection_date = fields.Date("Selection Date",required=True)
selection_type = fields.Selection([('0', 'Broken'),('1', 'Normal'),('2', 'Politonne')], "Selection Type")
selec = fields.Integer(related='selectionstage_id.age_selection')
maxa = fields.Integer(related='selectionstage_id.age_limit_max')
mina = fields.Integer(related='selectionstage_id.age_limit_min')
comment = fields.Text("Additional Information")
product_id = fields.Many2one('product.product', "Product", related="lot_id.product_id")
nursery_information = fields.Selection([('draft','Draft'),
('0','untimely'),
('1','late'),('2','passed'),
('3','very late'),('4','very untimely')],
compute='dateinformation', default='draft', string="Information Time" ,
readonly=True,required=False)
nursery_lapseday = fields.Integer(string="Information Lapse of Day",
required=False,readonly=True,compute='calculatedays',multi='sums',store=True)
nursery_lapsemonth = fields.Integer(string="Information Lapse of Month",
required=False,readonly=True,compute='calculatemonth',multi='sums',store=True)
nursery_plandate = fields.Char('Planning Date',readonly=True,compute="calculateplandate",visible=True)
nursery_plandatemax = fields.Char('Planning Date max',readonly=True,compute="calculateplandatemax",visible=True)
nursery_plandatemin = fields.Char('Planning Date min',readonly=True,compute="calculateplandatemin",visible=True)
nursery_persentagen = fields.Float(digit=(2.2),compute='computepersentage')
nursery_persentagea = fields.Float(digit=(2.2),compute='computepersentage')
state = fields.Selection([
('draft', 'Draft'),
('confirmed', 'Confirmed'),
('done', 'Done')], string="State")
culling_location_id = fields.Many2one('stock.location',("Culling Location"),
domain=[('estate_location', '=', True),
('estate_location_level', '=', '3'),
('estate_location_type', '=', 'nursery'),('scrap_location', '=', True)])
答案 2 :(得分:0)
这是我的action_approve()
@api.one
def action_approved(self):
"""Approved Selection is planted Seed."""
self.action_receive()
self.state = 'done'
@api.one
def action_receive(self):
normal = self.qty_normal
abnormal = self.qty_abnormal
selectionlineids = self.selectionline_ids
for item in selectionlineids:
normal += normal
abnormal += abnormal
self.write({'qty_normal': self.qty_normal, 'qty_abnormal': self.qty_abnormal})
self.action_move()
return True
这是我的action_move():
@api.one
def action_move(self):
"""
Selection do one actions:
1. Move quantity of selection to culling location.
"""
# Get unique location of planted location
location_ids = set()
for item in self.selectionline_ids:
if item.location_id and item.qty_batch > 0: # todo do not include empty quantity location
location_ids.add(item.location_id)
# Move quantity abnormal seed
if self.qty_abnormal > 0:
move_data = {
'product_id': self.batch_id.product_id.id,
'product_uom_qty': self.qty_abnormal,
'product_uom': self.batch_id.product_id.uom_id.id,
'name': 'Selection: %s' % self.batch_id.product_id.display_name,
'date_expected': self.selection_date,
'location_id': self.picking_id.location_dest_id.id,
'location_dest_id': self.culling_location_id.id,
'state': 'confirmed', # set to done if no approval required
'restrict_lot_id': self.batch_id.id # required by check tracking product
}
move = self.env['stock.move'].create(move_data)
move.action_confirm()
move.action_done()
return True