Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
3897 มุมมอง

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,

Please add this condition in default_warehouse Function

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

Regards

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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)

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 23
1907
2
พ.ค. 25
2874
0
ม.ค. 25
299
0
พ.ย. 24
565
1
ส.ค. 24
994