2
0

[13.0][fix][account_asset_management] display only accounts associated

to the current company.
This commit is contained in:
Jordi Ballester 2021-02-11 11:48:48 +01:00 committed by Rodrigo
parent 7d2a79fea4
commit 319042dc87
6 changed files with 53 additions and 13 deletions

View File

@ -34,6 +34,7 @@ class AccountAsset(models.Model):
_name = "account.asset"
_description = "Asset"
_order = "date_start desc, code, name"
_check_company_auto = True
account_move_line_ids = fields.One2many(
comodel_name="account.move.line",
@ -41,6 +42,7 @@ class AccountAsset(models.Model):
string="Entries",
readonly=True,
copy=False,
check_company=True,
)
move_line_check = fields.Boolean(
compute="_compute_move_line_check", string="Has accounting entries"
@ -98,6 +100,7 @@ class AccountAsset(models.Model):
change_default=True,
required=True,
states=READONLY_STATES,
check_company=True,
)
group_ids = fields.Many2many(
comodel_name="account.asset.group",
@ -252,6 +255,7 @@ class AccountAsset(models.Model):
string="Depreciation Lines",
copy=False,
states=READONLY_STATES,
check_company=True,
)
company_id = fields.Many2one(
comodel_name="res.company",

View File

@ -12,6 +12,7 @@ class AccountAssetGroup(models.Model):
_description = "Asset Group"
_order = "code, name"
_parent_store = True
_check_company_auto = True
name = fields.Char(string="Name", size=64, required=True, index=True)
code = fields.Char(index=True)
@ -26,11 +27,13 @@ class AccountAssetGroup(models.Model):
comodel_name="account.asset.group",
string="Parent Asset Group",
ondelete="restrict",
check_company=True,
)
child_ids = fields.One2many(
comodel_name="account.asset.group",
inverse_name="parent_id",
string="Child Asset Groups",
check_company=True,
)
@api.model

View File

@ -10,10 +10,12 @@ class AccountAssetLine(models.Model):
_name = "account.asset.line"
_description = "Asset depreciation table line"
_order = "type, line_date"
_check_company_auto = True
name = fields.Char(string="Depreciation Name", size=64, readonly=True)
asset_id = fields.Many2one(
comodel_name="account.asset", string="Asset", required=True, ondelete="cascade"
comodel_name="account.asset", string="Asset", required=True, ondelete="cascade",
check_company=True,
)
previous_id = fields.Many2one(
comodel_name="account.asset.line",
@ -42,7 +44,8 @@ class AccountAssetLine(models.Model):
line_date = fields.Date(string="Date", required=True)
line_days = fields.Integer(string="Days", readonly=True)
move_id = fields.Many2one(
comodel_name="account.move", string="Depreciation Entry", readonly=True
comodel_name="account.move", string="Depreciation Entry", readonly=True,
check_company=True,
)
move_check = fields.Boolean(
compute="_compute_move_check", string="Posted", store=True
@ -61,6 +64,12 @@ class AccountAssetLine(models.Model):
help="Set this flag for entries of previous fiscal years "
"for which Odoo has not generated accounting entries.",
)
company_id = fields.Many2one(
'res.company',
store=True,
readonly=True,
related='asset_id.company_id',
)
@api.depends("amount", "previous_id", "type")
def _compute_values(self):

View File

@ -7,6 +7,7 @@ from odoo.exceptions import UserError
class AccountAssetProfile(models.Model):
_name = "account.asset.profile"
_check_company_auto = True
_description = "Asset profile"
_order = "name"
@ -20,41 +21,48 @@ class AccountAssetProfile(models.Model):
)
account_asset_id = fields.Many2one(
comodel_name="account.account",
domain=[("deprecated", "=", False)],
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
string="Asset Account",
check_company=True,
required=True,
)
account_depreciation_id = fields.Many2one(
comodel_name="account.account",
domain=[("deprecated", "=", False)],
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
string="Depreciation Account",
check_company=True,
required=True,
)
account_expense_depreciation_id = fields.Many2one(
comodel_name="account.account",
domain=[("deprecated", "=", False)],
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
string="Depr. Expense Account",
check_company=True,
required=True,
)
account_plus_value_id = fields.Many2one(
comodel_name="account.account",
domain=[("deprecated", "=", False)],
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
check_company=True,
string="Plus-Value Account",
)
account_min_value_id = fields.Many2one(
comodel_name="account.account",
domain=[("deprecated", "=", False)],
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
check_company=True,
string="Min-Value Account",
)
account_residual_value_id = fields.Many2one(
comodel_name="account.account",
domain=[("deprecated", "=", False)],
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
check_company=True,
string="Residual Value Account",
)
journal_id = fields.Many2one(
comodel_name="account.journal",
domain=[("type", "=", "general")],
domain="[('type', '=', 'general'), ('company_id', '=', company_id)]",
string="Journal",
check_company=True,
required=True,
)
company_id = fields.Many2one(
@ -68,6 +76,7 @@ class AccountAssetProfile(models.Model):
relation="account_asset_profile_group_rel",
column1="profile_id",
column2="group_id",
check_company=True,
string="Asset Groups",
)
method = fields.Selection(

View File

@ -15,7 +15,15 @@ _logger = logging.getLogger(__name__)
class AccountAssetRemove(models.TransientModel):
_name = "account.asset.remove"
_description = "Remove Asset"
_check_company_auto = True
company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
readonly=True,
required=True,
default=lambda self: self._default_company_id(),
)
date_remove = fields.Date(
string="Asset Removal Date",
required=True,
@ -30,25 +38,25 @@ class AccountAssetRemove(models.TransientModel):
account_sale_id = fields.Many2one(
comodel_name="account.account",
string="Asset Sale Account",
domain=[("deprecated", "=", False)],
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
default=lambda self: self._default_account_sale_id(),
)
account_plus_value_id = fields.Many2one(
comodel_name="account.account",
string="Plus-Value Account",
domain=[("deprecated", "=", False)],
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
default=lambda self: self._default_account_plus_value_id(),
)
account_min_value_id = fields.Many2one(
comodel_name="account.account",
string="Min-Value Account",
domain=[("deprecated", "=", False)],
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
default=lambda self: self._default_account_min_value_id(),
)
account_residual_value_id = fields.Many2one(
comodel_name="account.account",
string="Residual Value Account",
domain=[("deprecated", "=", False)],
domain="[('deprecated', '=', False), ('company_id', '=', company_id)]",
default=lambda self: self._default_account_residual_value_id(),
)
posting_regime = fields.Selection(
@ -69,6 +77,12 @@ class AccountAssetRemove(models.TransientModel):
if self.sale_value < 0:
raise ValidationError(_("The Sale Value must be positive!"))
@api.model
def _default_company_id(self):
asset_id = self.env.context.get("active_id")
asset = self.env['account.asset'].browse(asset_id)
return asset.company_id
@api.model
def _default_sale_value(self):
return self._get_sale()["sale_value"]

View File

@ -6,6 +6,7 @@
<field name="arch" type="xml">
<form string="Remove Asset">
<group colspan="4" col="4">
<field name="company_id" groups="base.group_multi_company"/>
<field name="date_remove" />
<field name="force_date" />
<field name="sale_value" />