-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] account_operating_unit: Migration to 16.0
- Loading branch information
1 parent
94c70db
commit 2a84a5d
Showing
6 changed files
with
123 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
* Saran Lim. <[email protected]> | ||
* Pimolnat Suntian <[email protected]> | ||
* Hieu, Vo Minh Bao <[email protected]> | ||
* Alejandro Leonard <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,147 +9,148 @@ | |
|
||
@tagged("post_install", "-at_install") | ||
class TestAccountOperatingUnit(AccountTestInvoicingCommon): | ||
def setUp(self): | ||
super().setUp() | ||
self.res_users_model = self.env["res.users"] | ||
self.aml_model = self.env["account.move.line"] | ||
self.move_model = self.env["account.move"] | ||
self.account_model = self.env["account.account"] | ||
self.journal_model = self.env["account.journal"] | ||
self.product_model = self.env["product.product"] | ||
self.payment_model = self.env["account.payment"] | ||
self.register_payments_model = self.env["account.payment.register"] | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.res_users_model = cls.env["res.users"] | ||
cls.aml_model = cls.env["account.move.line"] | ||
cls.move_model = cls.env["account.move"] | ||
cls.account_model = cls.env["account.account"] | ||
cls.journal_model = cls.env["account.journal"] | ||
cls.product_model = cls.env["product.product"] | ||
cls.payment_model = cls.env["account.payment"] | ||
cls.register_payments_model = cls.env["account.payment.register"] | ||
|
||
# company | ||
self.company = self.env.user.company_id | ||
self.grp_acc_manager = self.env.ref("account.group_account_manager") | ||
cls.company = cls.env.user.company_id | ||
cls.grp_acc_manager = cls.env.ref("account.group_account_manager") | ||
# Main Operating Unit | ||
self.ou1 = self.env.ref("operating_unit.main_operating_unit") | ||
cls.ou1 = cls.env.ref("operating_unit.main_operating_unit") | ||
# B2B Operating Unit | ||
self.b2b = self.env.ref("operating_unit.b2b_operating_unit") | ||
cls.b2b = cls.env.ref("operating_unit.b2b_operating_unit") | ||
# B2C Operating Unit | ||
self.b2c = self.env.ref("operating_unit.b2c_operating_unit") | ||
cls.b2c = cls.env.ref("operating_unit.b2c_operating_unit") | ||
# Assign user to main company to allow to write OU | ||
self.env.user.write( | ||
cls.env.user.write( | ||
{ | ||
"company_ids": [(4, self.env.ref("base.main_company").id)], | ||
"company_ids": [(4, cls.env.ref("base.main_company").id)], | ||
"operating_unit_ids": [ | ||
(4, self.b2b.id), | ||
(4, self.b2c.id), | ||
(4, cls.b2b.id), | ||
(4, cls.b2c.id), | ||
], | ||
} | ||
) | ||
# Assign company to OU | ||
(self.ou1 + self.b2b + self.b2c).write({"company_id": self.company.id}) | ||
(cls.ou1 + cls.b2b + cls.b2c).write({"company_id": cls.company.id}) | ||
# Partner | ||
self.partner1 = self.env.ref("base.res_partner_1") | ||
cls.partner1 = cls.env.ref("base.res_partner_1") | ||
# Products | ||
self.product1 = self.env.ref("product.product_product_7") | ||
self.product2 = self.env.ref("product.product_product_9") | ||
self.product3 = self.env.ref("product.product_product_11") | ||
cls.product1 = cls.env.ref("product.product_product_7") | ||
cls.product2 = cls.env.ref("product.product_product_9") | ||
cls.product3 = cls.env.ref("product.product_product_11") | ||
|
||
# Payment methods | ||
self.payment_method_manual_in = self.env.ref( | ||
cls.payment_method_manual_in = cls.env.ref( | ||
"account.account_payment_method_manual_in" | ||
) | ||
|
||
# Create user1 | ||
self.user_id = self.res_users_model.with_context(no_reset_password=True).create( | ||
cls.user_id = cls.res_users_model.with_context(no_reset_password=True).create( | ||
{ | ||
"name": "Test Account User", | ||
"login": "user_1", | ||
"password": "demo", | ||
"email": "[email protected]", | ||
"company_id": self.company.id, | ||
"company_ids": [(4, self.company.id)], | ||
"operating_unit_ids": [(4, self.b2b.id), (4, self.b2c.id)], | ||
"groups_id": [(6, 0, [self.grp_acc_manager.id])], | ||
"company_id": cls.company.id, | ||
"company_ids": [(4, cls.company.id)], | ||
"operating_unit_ids": [(4, cls.b2b.id), (4, cls.b2c.id)], | ||
"groups_id": [(6, 0, [cls.grp_acc_manager.id])], | ||
} | ||
) | ||
# Create cash - test account | ||
user_type = self.env.ref("account.data_account_type_current_assets") | ||
self.current_asset_account_id = self.account_model.create( | ||
# user_type = cls.env.ref("account.data_account_type_current_assets") | ||
cls.current_asset_account_id = cls.account_model.create( | ||
{ | ||
"name": "Current asset - Test", | ||
"code": "test_current_asset", | ||
"user_type_id": user_type.id, | ||
"company_id": self.company.id, | ||
"code": "TEST", | ||
"account_type": "asset_current", | ||
"company_id": cls.company.id, | ||
} | ||
) | ||
# Create Inter-OU Clearing - test account | ||
user_type = self.env.ref("account.data_account_type_equity") | ||
self.inter_ou_account_id = self.account_model.create( | ||
# user_type = cls.env.ref("account.data_account_type_equity") | ||
cls.inter_ou_account_id = cls.account_model.create( | ||
{ | ||
"name": "Inter-OU Clearing", | ||
"code": "test_inter_ou", | ||
"user_type_id": user_type.id, | ||
"company_id": self.company.id, | ||
"code": "inter", | ||
# "user_type_id": user_type.id, | ||
"account_type": "equity", | ||
"company_id": cls.company.id, | ||
} | ||
) | ||
# Assign the Inter-OU Clearing account to the company | ||
self.company.inter_ou_clearing_account_id = self.inter_ou_account_id.id | ||
self.company.ou_is_self_balanced = True | ||
cls.company.inter_ou_clearing_account_id = cls.inter_ou_account_id.id | ||
cls.company.ou_is_self_balanced = True | ||
|
||
# Create user2 | ||
self.user2_id = self.res_users_model.with_context( | ||
no_reset_password=True | ||
).create( | ||
cls.user2_id = cls.res_users_model.with_context(no_reset_password=True).create( | ||
{ | ||
"name": "Test Account User", | ||
"login": "user_2", | ||
"password": "demo", | ||
"email": "[email protected]", | ||
"company_id": self.company.id, | ||
"company_ids": [(4, self.company.id)], | ||
"operating_unit_ids": [(4, self.b2c.id)], | ||
"groups_id": [(6, 0, [self.grp_acc_manager.id])], | ||
"company_id": cls.company.id, | ||
"company_ids": [(4, cls.company.id)], | ||
"operating_unit_ids": [(4, cls.b2c.id)], | ||
"groups_id": [(6, 0, [cls.grp_acc_manager.id])], | ||
} | ||
) | ||
|
||
# Create a cash account 1 | ||
user_type = self.env.ref("account.data_account_type_liquidity") | ||
self.cash1_account_id = self.account_model.create( | ||
# user_type = cls.env.ref("account.data_account_type_liquidity") | ||
cls.cash1_account_id = cls.account_model.create( | ||
{ | ||
"name": "Cash 1 - Test", | ||
"code": "test_cash_1", | ||
"user_type_id": user_type.id, | ||
"company_id": self.company.id, | ||
"code": "testcash1", | ||
# "user_type_id": user_type.id, | ||
"account_type": "asset_cash", | ||
"company_id": cls.company.id, | ||
} | ||
) | ||
|
||
# Create a journal for cash account 1, associated to the main | ||
# operating unit | ||
self.cash_journal_ou1 = self.journal_model.create( | ||
cls.cash_journal_ou1 = cls.journal_model.create( | ||
{ | ||
"name": "Cash Journal 1 - Test", | ||
"code": "cash1", | ||
"type": "cash", | ||
"company_id": self.company.id, | ||
"default_account_id": self.cash1_account_id.id, | ||
"operating_unit_id": self.ou1.id, | ||
"company_id": cls.company.id, | ||
"default_account_id": cls.cash1_account_id.id, | ||
"operating_unit_id": cls.ou1.id, | ||
} | ||
) | ||
# Create a cash account 2 | ||
user_type = self.env.ref("account.data_account_type_liquidity") | ||
self.cash2_account_id = self.account_model.create( | ||
# user_type = cls.env.ref("account.data_account_type_liquidity") | ||
cls.cash2_account_id = cls.account_model.create( | ||
{ | ||
"name": "Cash 2 - Test", | ||
"code": "cash2", | ||
"user_type_id": user_type.id, | ||
"company_id": self.company.id, | ||
"account_type": "liability_payable", | ||
"company_id": cls.company.id, | ||
} | ||
) | ||
|
||
# Create a journal for cash account 2, associated to the operating | ||
# unit B2B | ||
self.cash2_journal_b2b = self.journal_model.create( | ||
cls.cash2_journal_b2b = cls.journal_model.create( | ||
{ | ||
"name": "Cash Journal 2 - Test", | ||
"code": "test_cash_2", | ||
"code": "testcash2", | ||
"type": "cash", | ||
"company_id": self.company.id, | ||
"default_account_id": self.cash2_account_id.id, | ||
"operating_unit_id": self.b2b.id, | ||
"company_id": cls.company.id, | ||
"default_account_id": cls.cash2_account_id.id, | ||
"operating_unit_id": cls.b2b.id, | ||
} | ||
) | ||
|
||
|
@@ -161,16 +162,19 @@ def _prepare_invoice(self, operating_unit_id, name="Test Supplier Invoice"): | |
] | ||
# Prepare invoice lines | ||
lines = [] | ||
acc_type = self.env.ref("account.data_account_type_expenses") | ||
# acc_type = self.env.ref("account.data_account_type_expenses") | ||
|
||
for product, qty in line_products: | ||
line_values = { | ||
"name": product.name, | ||
"product_id": product.id, | ||
"quantity": qty, | ||
"price_unit": 50, | ||
"account_id": self.env["account.account"] | ||
.search([("user_type_id", "=", acc_type.id)], limit=1) | ||
.search([("account_type", "=", "expense")], limit=1) | ||
.id, | ||
# Adding this line so the taxes are explicitly excluded from the lines | ||
"tax_ids": [], | ||
} | ||
lines.append((0, 0, line_values)) | ||
inv_vals = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.