Skip to Content
Menu
This question has been flagged
4322 Views

Hi, I want to create a move line in picking. But when I save or I validate my stock move, Odoo says, field 'move_lines' is incorrect (like required field). When I validate my stock move without move line it's ok and when i put line in my hand it's ok too...  I want to create line with onchange function. Tanks !

python:


# -*- coding: utf-8 -*-
from odoo import api, fields, models, _
classStockPicking(models.Model):
    _inherit ='stock.picking'
    request_id = fields.Many2one(comodel_name='maintenance.request', string="Maintenance Request")
    @api.onchange('request_id')
    defonchange_request_id(self):
        for picking inself:
            request = picking.request_id
            product = request.equipment_id.product_id
            if request and request.equipment_id and product:
                datas = {
'company_id': picking.company_id.id,
'picking_type_id': picking.picking_type_id.id,
'name': product.name,
'product_id': product.id,
'location_id': 1,
'loaction_dest_id': 1,
'product_uom': product.uom_id.id,
'product_uom_qty': 1,
'picking_id': picking.id,
'state': 'draft',
                }
          if picking.location_id:
               datas['location_id'] = picking.location_id.id
          if picking.location_dest_id:
               datas['location_dest_id'] = picking.location_dest_id.id
          picking.move_lines = ([(0, False, datas)])


xml:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
  <recordmodel="ir.ui.view"id="custom_maintenance_stock_picking_form">
    <fieldname="name">custom Maintenance Picking Form</field>
    <fieldname="model">stock.picking</field>
    <fieldname="inherit_id"ref="stock.view_picking_form"/>
    <fieldname="priority">100</field>
    <fieldname="arch"type="xml">
      <xpathexpr="//field[@name='picking_type_id']"position="after">
        <fieldname="request_id"invisible="1"/>
     </xpath>
    </field>
    </record>
</odoo
                 
Avatar
Discard
Author

It's done. I missed 'date_expected'.

Related Posts Replies Views Activity
2
Nov 24
25096
2
May 24
5519
3
Mar 24
4964
0
Mar 24
262
3
Feb 24
11421