Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
4057 Zobrazení

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
Zrušit
Nejlepší odpověď
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
Zrušit
Nejlepší odpověď

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
Zrušit

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.

Related Posts Odpovědi Zobrazení Aktivita
1
srp 21
7151
0
úno 17
6170
1
dub 23
2676
1
čvn 22
3404
0
lis 17
3639