odex30_standard/odex30_base/branch/models/account_move.py

46 lines
1.4 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
from odoo.exceptions import ValidationError
class AccountMove(models.Model):
_inherit = 'account.move'
branch_id = fields.Many2one('res.branch', string="Branch")
@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
@api.onchange('branch_id')
def _onchange_branch_id(self):
selected_branch = self.branch_id
if selected_branch:
user_branch = self.env.user.branch_id
if user_branch and user_branch.id != selected_branch.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'
branch_id = fields.Many2one('res.branch', string="Branch", related="move_id.branch_id", store=True)