Skip to Content
Menú
This question has been flagged
3 Respostes
3904 Vistes

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



Avatar
Descartar
Autor

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.

Best Answer

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

Avatar
Descartar
Best Answer

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)

Avatar
Descartar
Best Answer

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

Avatar
Descartar

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 Respostes Vistes Activitat
1
de nov. 23
1911
2
de maig 25
2876
0
de gen. 25
303
0
de nov. 24
566
1
d’ag. 24
998