跳至內容
選單
此問題已被標幟
3 回覆
4403 瀏覽次數

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 ")



頭像
捨棄
作者

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.

最佳答案

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

頭像
捨棄
最佳答案

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)

頭像
捨棄
最佳答案

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

頭像
捨棄

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)

相關帖文 回覆 瀏覽次數 活動
1
11月 23
2243
1
7月 25
754
2
5月 25
3723
0
11月 24
1053
1
8月 24
1770