58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
# Part of BrowseInfo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import api, fields, models, _
|
|
from odoo.exceptions import UserError
|
|
from odoo.tools.float_utils import float_compare
|
|
|
|
|
|
|
|
|
|
class AccountMove(models.Model):
|
|
_inherit = 'account.move'
|
|
|
|
@api.model
|
|
def default_get(self, default_fields):
|
|
res = super(AccountMove, self).default_get(default_fields)
|
|
branch_id = False
|
|
|
|
if self._context.get('branch_id'):
|
|
branch_id = self._context.get('branch_id')
|
|
elif self.env.user.branch_id:
|
|
branch_id = self.env.user.branch_id.id
|
|
res.update({
|
|
'branch_id' : branch_id
|
|
})
|
|
return res
|
|
|
|
branch_id = fields.Many2one('res.branch', string="Branch")
|
|
|
|
@api.onchange('branch_id')
|
|
def _onchange_branch_id(self):
|
|
selected_brach = self.branch_id
|
|
if selected_brach:
|
|
user_id = self.env.user
|
|
user_branch = user_id.sudo().branch_id
|
|
if user_branch and user_branch.id != selected_brach.id:
|
|
raise UserError("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.")
|
|
|
|
|
|
class AccountMoveLine(models.Model):
|
|
_inherit = 'account.move.line'
|
|
|
|
@api.model
|
|
def default_get(self, default_fields):
|
|
res = super(AccountMoveLine, self).default_get(default_fields)
|
|
branch_id = False
|
|
|
|
if self._context.get('branch_id'):
|
|
branch_id = self._context.get('branch_id')
|
|
elif self.env.user.branch_id:
|
|
branch_id = self.env.user.branch_id.id
|
|
|
|
if self.move_id.branch_id :
|
|
branch_id = self.move_id.branch_id.id
|
|
res.update({'branch_id' : branch_id})
|
|
return res
|
|
|
|
branch_id = fields.Many2one('res.branch', string="Branch",related="move_id.branch_id",store=True)
|