Skip to content

Commit c205415

Browse files
committed
[IMP] assets_management: avoid multicompany issues on records creation
1 parent 05f247b commit c205415

23 files changed

Lines changed: 535 additions & 301 deletions

assets_management/models/asset.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ class Asset(models.Model):
1111
_description = "Assets"
1212
_inherit = ["mail.thread", "mail.activity.mixin", "portal.mixin"]
1313
_order = "purchase_date desc, name asc"
14+
_check_company_auto = True
1415

1516
@api.model
1617
def get_default_company_id(self):
17-
return self.env.user.company_id
18+
return self.env.company
1819

1920
asset_accounting_info_ids = fields.One2many(
2021
"asset.accounting.info", "asset_id", string="Accounting Info"
@@ -24,6 +25,7 @@ def get_default_company_id(self):
2425
"asset.category",
2526
required=True,
2627
string="Category",
28+
check_company=True,
2729
)
2830

2931
code = fields.Char(
@@ -37,6 +39,7 @@ def get_default_company_id(self):
3739
required=True,
3840
string="Company",
3941
tracking=True,
42+
readonly=True,
4043
)
4144

4245
currency_id = fields.Many2one(
@@ -45,12 +48,17 @@ def get_default_company_id(self):
4548
string="Currency",
4649
)
4750

48-
customer_id = fields.Many2one("res.partner", string="Customer")
51+
customer_id = fields.Many2one(
52+
"res.partner",
53+
string="Customer",
54+
check_company=True,
55+
)
4956

5057
depreciation_ids = fields.One2many(
5158
"asset.depreciation",
5259
"asset_id",
5360
string="Depreciations",
61+
check_company=True,
5462
)
5563

5664
name = fields.Char(
@@ -70,7 +78,11 @@ def get_default_company_id(self):
7078
tracking=True,
7179
)
7280

73-
purchase_move_id = fields.Many2one("account.move", string="Purchase Move")
81+
purchase_move_id = fields.Many2one(
82+
"account.move",
83+
string="Purchase Move",
84+
check_company=True,
85+
)
7486

7587
sale_amount = fields.Monetary(
7688
string="Sale Value",
@@ -80,7 +92,11 @@ def get_default_company_id(self):
8092

8193
dismiss_date = fields.Date()
8294

83-
sale_move_id = fields.Many2one("account.move", string="Sale Move")
95+
sale_move_id = fields.Many2one(
96+
"account.move",
97+
string="Sale Move",
98+
check_company=True,
99+
)
84100

85101
sold = fields.Boolean(string="Sold")
86102
dismissed = fields.Boolean(string="Dismissed")
@@ -97,7 +113,11 @@ def get_default_company_id(self):
97113
string="State",
98114
)
99115

100-
supplier_id = fields.Many2one("res.partner", string="Supplier")
116+
supplier_id = fields.Many2one(
117+
"res.partner",
118+
string="Supplier",
119+
check_company=True,
120+
)
101121

102122
supplier_ref = fields.Char(string="Supplier Ref.")
103123

@@ -175,6 +195,7 @@ def onchange_category_id(self):
175195
def onchange_company_currency(self):
176196
if self.company_id:
177197
self.currency_id = self.company_id.currency_id
198+
self.category_id = False
178199

179200
@api.onchange("purchase_amount")
180201
def onchange_purchase_amount(self):

assets_management/models/asset_category.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ class AssetCategory(models.Model):
1010
_name = "asset.category"
1111
_description = "Asset Category"
1212
_order = "name"
13+
_check_company_auto = True
1314

1415
@api.model
1516
def get_default_company_id(self):
16-
return self.env.user.company_id
17+
return self.env.company
1718

1819
@api.model
1920
def get_default_type_ids(self):
@@ -46,40 +47,50 @@ def get_default_type_ids(self):
4647
"account.account",
4748
required=True,
4849
string="Asset Account",
50+
check_company=True,
4951
)
5052

5153
comment = fields.Text(
5254
string="Comment",
5355
)
5456

5557
company_id = fields.Many2one(
56-
"res.company", default=get_default_company_id, string="Company"
58+
"res.company", default=get_default_company_id, readonly=True, string="Company"
5759
)
5860

5961
depreciation_account_id = fields.Many2one(
6062
"account.account",
6163
required=True,
6264
string="Depreciation Account",
65+
check_company=True,
6366
)
6467

6568
fund_account_id = fields.Many2one(
6669
"account.account",
6770
required=True,
6871
string="Fund Account",
72+
check_company=True,
6973
)
7074

7175
gain_account_id = fields.Many2one(
7276
"account.account",
7377
required=True,
7478
string="Capital Gain Account",
79+
check_company=True,
7580
)
7681

77-
journal_id = fields.Many2one("account.journal", required=True, string="Journal")
82+
journal_id = fields.Many2one(
83+
"account.journal",
84+
required=True,
85+
string="Journal",
86+
check_company=True,
87+
)
7888

7989
loss_account_id = fields.Many2one(
8090
"account.account",
8191
required=True,
8292
string="Capital Loss Account",
93+
check_company=True,
8394
)
8495

8596
name = fields.Char(
@@ -97,13 +108,15 @@ def get_default_type_ids(self):
97108
tag_ids = fields.Many2many(
98109
"asset.tag",
99110
string="Tag",
111+
check_company=True,
100112
)
101113

102114
type_ids = fields.One2many(
103115
"asset.category.depreciation.type",
104116
"category_id",
105117
default=get_default_type_ids,
106118
string="Depreciation Types",
119+
check_company=True,
107120
)
108121

109122
def copy(self, default=None):

assets_management/models/asset_category_depreciation_type.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
class AssetCategoryDepreciationType(models.Model):
99
_name = "asset.category.depreciation.type"
1010
_description = "Asset Category - Depreciation Type"
11+
_check_company_auto = True
1112

1213
base_coeff = fields.Float(
1314
default=1,
@@ -21,6 +22,7 @@ class AssetCategoryDepreciationType(models.Model):
2122
readonly=True,
2223
required=True,
2324
string="Category",
25+
check_company=True,
2426
)
2527

2628
company_id = fields.Many2one(
@@ -31,12 +33,14 @@ class AssetCategoryDepreciationType(models.Model):
3133
"asset.depreciation.type",
3234
required=True,
3335
string="Type",
36+
check_company=True,
3437
)
3538

3639
mode_id = fields.Many2one(
3740
"asset.depreciation.mode",
3841
required=True,
3942
string="Dep Mode",
43+
check_company=True,
4044
)
4145

4246
percentage = fields.Float(string="Depreciation %")

assets_management/models/asset_depreciation.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class AssetDepreciation(models.Model):
1111
_name = "asset.depreciation"
1212
_description = "Assets Depreciations"
13+
_check_company_auto = True
1314

1415
amount_depreciable = fields.Monetary(string="Initial Depreciable Amount")
1516

@@ -85,7 +86,11 @@ class AssetDepreciation(models.Model):
8586

8687
date_start = fields.Date(string="Date Start")
8788

88-
dismiss_move_id = fields.Many2one("account.move", string="Dismiss Move")
89+
dismiss_move_id = fields.Many2one(
90+
"account.move",
91+
string="Dismiss Move",
92+
check_company=True,
93+
)
8994

9095
first_dep_nr = fields.Integer(
9196
default=1,
@@ -103,13 +108,17 @@ class AssetDepreciation(models.Model):
103108
)
104109

105110
line_ids = fields.One2many(
106-
"asset.depreciation.line", "depreciation_id", string="Lines"
111+
"asset.depreciation.line",
112+
"depreciation_id",
113+
string="Lines",
114+
check_company=True,
107115
)
108116

109117
mode_id = fields.Many2one(
110118
"asset.depreciation.mode",
111119
required=True,
112120
string="Mode",
121+
check_company=True,
113122
)
114123

115124
percentage = fields.Float(string="Depreciation (%)")
@@ -134,7 +143,11 @@ class AssetDepreciation(models.Model):
134143
string="State",
135144
)
136145

137-
type_id = fields.Many2one("asset.depreciation.type", string="Depreciation Type")
146+
type_id = fields.Many2one(
147+
"asset.depreciation.type",
148+
string="Depreciation Type",
149+
check_company=True,
150+
)
138151

139152
zero_depreciation_until = fields.Date(string="Zero Depreciation Up To")
140153

assets_management/models/asset_depreciation_line.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ class AssetDepreciationLine(models.Model):
1010
_name = "asset.depreciation.line"
1111
_description = "Assets Depreciations Lines"
1212
_order = "date asc, name asc"
13+
_check_company_auto = True
1314

1415
amount = fields.Monetary(
1516
string="Amount",
1617
)
1718

1819
asset_accounting_info_ids = fields.One2many(
19-
"asset.accounting.info", "dep_line_id", string="Accounting Info"
20+
"asset.accounting.info",
21+
"dep_line_id",
22+
string="Accounting Info",
23+
check_company=True,
2024
)
2125

2226
asset_id = fields.Many2one(
@@ -63,7 +67,9 @@ class AssetDepreciationLine(models.Model):
6367
)
6468

6569
depreciation_line_type_id = fields.Many2one(
66-
"asset.depreciation.line.type", string="Depreciation Type"
70+
"asset.depreciation.line.type",
71+
string="Depreciation Type",
72+
check_company=True,
6773
)
6874

6975
depreciation_nr = fields.Integer(
@@ -84,7 +90,11 @@ class AssetDepreciationLine(models.Model):
8490
string="Force Dep. Num",
8591
)
8692

87-
move_id = fields.Many2one("account.move", string="Move")
93+
move_id = fields.Many2one(
94+
"account.move",
95+
string="Move",
96+
check_company=True,
97+
)
8898

8999
move_type = fields.Selection(
90100
[

assets_management/models/asset_depreciation_line_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class DepLineType(models.Model):
1414

1515
@api.model
1616
def get_default_company_id(self):
17-
return self.env.user.company_id
17+
return self.env.company
1818

1919
code = fields.Char(string="Code")
2020

assets_management/models/asset_depreciation_mode.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,23 @@ class AssetDepreciationMode(models.Model):
1010
_name = "asset.depreciation.mode"
1111
_description = "Asset Depreciation Mode"
1212
_order = "name"
13+
_check_company_auto = True
1314

1415
@api.model
1516
def get_default_company_id(self):
16-
return self.env.user.company_id
17+
return self.env.company
1718

1819
company_id = fields.Many2one(
19-
"res.company", default=get_default_company_id, string="Company"
20+
"res.company", default=get_default_company_id, readonly=True, string="Company"
2021
)
2122

2223
default = fields.Boolean(string="Default Mode")
2324

2425
line_ids = fields.One2many(
25-
"asset.depreciation.mode.line", "mode_id", string="Lines"
26+
"asset.depreciation.mode.line",
27+
"mode_id",
28+
string="Lines",
29+
check_company=True,
2630
)
2731

2832
name = fields.Char(

assets_management/models/asset_depreciation_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AssetDepreciationType(models.Model):
1313

1414
@api.model
1515
def get_default_company_id(self):
16-
return self.env.user.company_id
16+
return self.env.company
1717

1818
company_id = fields.Many2one(
1919
"res.company", default=get_default_company_id, string="Company"

assets_management/models/asset_tag.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ class AssetTag(models.Model):
1111

1212
@api.model
1313
def get_default_company_id(self):
14-
return self.env.user.company_id
14+
return self.env.company
1515

1616
company_id = fields.Many2one(
17-
"res.company", default=get_default_company_id, string="Company"
17+
"res.company", default=get_default_company_id, readonly=True, string="Company"
1818
)
1919

2020
name = fields.Char(string="Name", required=True)

0 commit comments

Comments
 (0)