تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
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
نوفمبر 23
2243
1
يوليو 25
754
2
مايو 25
3723
0
نوفمبر 24
1053
1
أغسطس 24
1770