2015-10-28 44 views
0

我試圖創建股票移動。這我的腳本代碼:如何創建庫存移動?

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, 空,1 ,null,7.000,1,2015-10-28 04:30:59,null,null,null,1, null,null,null,confirm,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

與顯示領域的工作模型的類定義。 –

+0

我顯示我的工作模型類。在回答 –

+0

在哪個事件你寫這個代碼(股票移動創建)?它在創建方法? –

回答

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)]) 
1

似乎採摘其中提到不包含模型location_dest_id或沒有採摘在模型中選擇。

解決方案:

  • 保持在XML應用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 
+0

我按照您的答案和錯誤相同的第一個錯誤 –

+0

請顯示'action_approved()'的代碼。 –

+0

我顯示我的代碼爲action_approved –

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 
+0

謝謝你無法找到從哪裏引發異常的特定錯誤點?這段代碼看起來不錯,但是'action_move()'對我來說還是未知數。 –

+0

不要單獨發佈答案,而是更新您的問題。 –

+0

那麼,我的情況如何解決?我真的很重要。 –