28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
# Part of BrowseInfo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models, _
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class StockPicking(models.Model):
|
|
_inherit = 'stock.picking'
|
|
|
|
branch_id = fields.Many2one('res.branch', string="Branch")
|
|
|
|
@api.model
|
|
def default_get(self, default_fields):
|
|
res = super(StockPicking, self).default_get(default_fields)
|
|
if self.env.user.branch_id:
|
|
res.update({
|
|
'branch_id' : self.env.user.branch_id.id or False
|
|
})
|
|
return res
|
|
|
|
@api.onchange('branch_id')
|
|
def _onchange_branch_id(self):
|
|
selected_brach = self.branch_id
|
|
if selected_brach:
|
|
user_id = self.env['res.users'].browse(self.env.uid)
|
|
user_branch = user_id.sudo().branch_id
|
|
if user_branch and user_branch.id != selected_brach.id:
|
|
raise ValidationError("Please select active branch only. Other may create the Multi branch issue. \n\ne.g: If you wish to add other branch then Switch branch from the header and set that.") |