İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
4013 Görünümler

Hello I am modifying the stock.picking view form by adding the pre-existing sale_id field, which will link the picking form to a sale order. When I add or change products in the Operations field and click save the Sale_id field is emptied and the link to the sale order is removed. I was wondering if anyone could help me locate which function in StockMove or StockPicking does this so I can override it. I am using Odoo v14.


This is my code if anyone wants to try:

from odoo import models, fields, api
from odoo.exceptions import ValidationError


class StockPickingInherit(models.Model):
_inherit = "stock.picking"


@api.onchange
('partner_id')
def onchange_partner_id(self):
return {'domain': {'sale_id': [('partner_id', 'in', self.get_partner_ids())]}}

def get_partner_ids(self):
res = []
root_id = self.partner_id
if self.partner_id.parent_id.id != False:
root_id = self.partner_id.parent_id
res.append(root_id.id)
for child_id in root_id.child_ids:
res.append(child_id.id)
return res



"id="stock_picking_form_view_inherit" model="ir.ui.view">
name="name">stock.picking.form.view.inherit
name="model">stock.picking
name="inherit_id" ref="stock.view_picking_form"/>
name="arch" type="xml">
name="origin" position="after">
name="sale_id"/>

name="product_uom_qty" position="attributes">
name="invisible">0


"

Avatar
Vazgeç
En İyi Yanıt
After creating the stock.picking record, we attempt to link it back to the sale order by adding it to the picking_ids field of the sale order (order.picking_ids += picking).

​if any(line.product_id.is_receipt_require for line in order.order_line):

​        picking_vals = {

​            'picking_type_id': order.warehouse_id.in_type_id.id,

​            'partner_id': order.partner_id.id,

​            'location_dest_id': order.warehouse_id.lot_stock_id.id,

​            'origin': order.name,

​            'sale_id': order.id,

​            'location_id' : order.partner_id.property_stock_supplier.id,

​        }

​        picking = self.env['stock.picking'].create(picking_vals)


​        for line in order.order_line:

​            if line.product_id.is_receipt_require:

​                picking_line_vals = {

​                    'picking_id': picking.id,

​                    'product_id': line.product_id.receipt_product.id,

​                    'product_uom_qty': line.product_uom_qty,

​                    'product_uom' : line.product_id.receipt_product.uom_id.id,

​                    'name': line.name,

​                    'location_id' : order.partner_id.property_stock_supplier.id,

​                    'location_dest_id' : order.warehouse_id.lot_stock_id.id,

​                }

​                self.env['stock.move'].create(picking_line_vals)

​                

​        # Update the sale order to link it with the created picking

​        order.picking_ids += picking

​          return res

​    else: ​       

​ return res


Avatar
Vazgeç
En İyi Yanıt

Hello Zan,

Please replace this code in your module. i hope your problem will be solved after adding this code. this is py file and xml file code. change in your xpath so your error will be solved.


py file code

from odoo import models, fields, api
from odoo.exceptions import ValidationError


class StockPickingInherit(models.Model)
_inherit = "stock.picking"

sale_id = fields.Char



Feel free for further assistance on contact@geminatecs.com

Thank you
Geminate Consultancy Services.

Avatar
Vazgeç

Hello Zan,

Please replace this code in your module. i hope your problem will be solved after adding this code. this is py file and xml file code. change in your xpath so your error will be solved.

py file code

from odoo import models, fields, api
from odoo.exceptions import ValidationError

class StockPickingInherit(models.Model)
_inherit = "stock.picking"

sale_id = fields.Char

// api onchange('partner_id')
// def onchange_partner_id(self):
// return {'domain': {'sale_id': [('partner_id', 'in', self.get_partner_ids())]}}
//
// def get_partner_ids(self):
// res = []
// root_id = self.partner_id
// if self.partner_id.parent_id.id != False:
// root_id = self.partner_id.parent_id
// res.append(root_id.id)
// for child_id in root_id.child_ids:
// res.append(child_id.id)
// return res

view file code

//record id="stock_picking_form_view_inherit" model="ir.ui.view"
// field name="name">stock.picking.form.view.inherit</field
// field name="model">stock.picking</field
// field name="inherit_id" ref="stock.view_picking_form"
// field name="arch" type="xml"
// xpath expr="//field[@name='origin']" position="after"
// field name="sale_id"
// xpath
//
// xpath expr="field[@name='product_uom_qty']" position="attributes"
// attribute name="invisible">True
// xpath
// field
//record

Feel free for further assistance on contact@geminatecs.com

Thank you
Geminate Consultancy Services.

İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Ağu 21
7112
0
Şub 17
6144
1
Nis 23
2646
1
Haz 22
3391
0
Kas 17
3619