Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
4410 Lượt xem

I'm trying to set the default value of 

warehouse_ids in sale.order.line model to the value of the default_sales_order_location in the res.user modell

else it will be the value of the warehouse of the product that is selected in order line

but it doesn't work 
the code:

from odoo import models , fields,api,_
class SaleOrder(models.Model):
_inherit = 'sale.order'

class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

warehouse_ids = fields.Many2one('stock.warehouse',string="Warehouse " ,default=lambda self: self.default_warehouse())

def default_warehouse(self):
if self.env.user.default_sales_order_location:
return self.env.user.default_sales_order_location
else:
return super.product_id.warehouse_ids

class ProductTemplate(models.Model):
_inherit = 'product.template'
warehouse_ids = fields.Many2one('stock.warehouse', string="Default Warehouse location ")

class ProductProduct(models.Model):
_inherit = 'product.product'
warehouse_ids = fields.Many2one('stock.warehouse',string="Default Warehouse location ")

class ResUsers(models.Model):
_inherit = 'res.users'
default_sales_order_location=fields.Many2one('stock.warehouse',string="Default_Sale_Order_Location ")



Ảnh đại diện
Huỷ bỏ
Tác giả

1- IF THE USER HAVE DEFUALT SALES ORDER LOCATION ALL THE ITEMS IN SALES LINE WILL DELIVER FROM THAT LOCATION .

2- IF THE USER NOT HAVE DEFULAT SALES ORDER LOCATION EACH ITEM IN SALES KINE WILL GET THE DELIVER LOCATION FROM THE PRODUCT SALES LOCATION.

Câu trả lời hay nhất

Hi,

 To make the default_warehouse method work as intended, you need to adjust the logic slightly. Here's an improved version of your method:  


def default_warehouse(self):

   user = self.env.user

   if user.default_sales_order_location:

      return user.default_sales_order_location

   elif self.product_id and self.product_id.warehouse_ids:

      return self.product_id.warehouse_ids

   else:

       return None

Hope it helps

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello,


If I understand correctly the functionality that you are looking for already exists:


You need "Technical / Manage multiple warehouses" rights to be checked on your user in order to see the field that I will show.


In Settings / Users / Preference you have the option of setting up Default Warehouse for the specific user.

When that specific user creates a Sale Order this warehouse will now be used by default (with the option to change it in the SO, of course)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello Asmaa,

You can used bellow example for set default warehouse.

Please find code in comment.

I hope this will be helpful. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Ảnh đại diện
Huỷ bỏ

Code :-

class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

def _get_default_warehouse(self):
warehouse_ids = False
if self.env.user.property_warehouse_id:
warehouse_id = self.env.user.property_warehouse_id
self.write({'warehouse_ids': [4, warehouse_id.id]})
elif self.product_id.warehouse_ids:
self.write({'warehouse_ids': [4, self.product_id.warehouse_ids.id]})
return warehouse_ids

warehouse_ids = fields.Many2one('stock.warehouse',string="Warehouse", default=_get_default_warehouse)

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 23
2243
1
thg 7 25
755
2
thg 5 25
3724
0
thg 11 24
1054
1
thg 8 24
1771