From d6cc66e92dabc03b87c27ffee1085eded1c0140d Mon Sep 17 00:00:00 2001 From: Majda EL MARIOULI Date: Thu, 28 Mar 2024 10:02:18 -0400 Subject: [PATCH] TA#64294 [FIX] project_wip_material: Add module to dependencies (#381) * TA#64294 [FIX] project_wip_material: Add module to dependencies --- docker-compose.yml | 9 +- project_wip_material/__manifest__.py | 3 +- project_wip_material/models/stock_move.py | 80 +++++++----- project_wip_material/tests/common.py | 116 ++++++++++++------ .../tests/test_wip_journal_entries.py | 8 +- 5 files changed, 135 insertions(+), 81 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 991596b0..d63f2bcd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ services: aliases: - odoo.localtest.me db: - image: postgres:9.6 + image: postgres:16.0 environment: - POSTGRES_PASSWORD=odoo - POSTGRES_USER=odoo @@ -30,13 +30,6 @@ services: expose: - 5432 - testcafe: - build: - context: .testcafe - dockerfile: Dockerfile - depends_on: - - odoo - volumes: odoo-web-data: odoo-db-data: diff --git a/project_wip_material/__manifest__.py b/project_wip_material/__manifest__.py index c9574225..51dbc70d 100644 --- a/project_wip_material/__manifest__.py +++ b/project_wip_material/__manifest__.py @@ -3,7 +3,7 @@ { 'name': 'Project WIP Material', - 'version': '1.1.0', + 'version': '1.1.1', 'author': 'Numigi', 'maintainer': 'Numigi', 'website': 'https://bit.ly/numigi-com', @@ -11,6 +11,7 @@ 'category': 'Project', 'summary': 'WIP accounting entries from consumed products', 'depends': [ + 'project_task_analytic_lines', 'project_material', 'project_wip', ], diff --git a/project_wip_material/models/stock_move.py b/project_wip_material/models/stock_move.py index 078f9ab9..1178667b 100644 --- a/project_wip_material/models/stock_move.py +++ b/project_wip_material/models/stock_move.py @@ -8,7 +8,7 @@ class StockMove(models.Model): """Generate WIP journal entries for consumption moves.""" - _inherit = 'stock.move' + _inherit = "stock.move" def _is_in(self): """Use the same valuation as incoming moves for consumption return.""" @@ -23,39 +23,46 @@ def _account_entry_move(self, qty, description, svl_id, cost): if self._is_consumption(): self._generate_consumption_account_move(qty, description, svl_id, cost) elif self._is_consumption_return(): - self._generate_consumption_return_account_move(qty, description, svl_id, cost) + self._generate_consumption_return_account_move( + qty, description, svl_id, cost + ) else: super()._account_entry_move(qty, description, svl_id, cost) - def _prepare_account_move_line(self, qty, cost, credit_account_id, - debit_account_id, description): + def _prepare_account_move_line( + self, qty, cost, credit_account_id, debit_account_id, description + ): """Add the analytic to WIP account move lines.""" move_line_vals = super()._prepare_account_move_line( - qty, cost, credit_account_id, debit_account_id, description) + qty, cost, credit_account_id, debit_account_id, description + ) if self._is_consumption() or self._is_consumption_return(): wip_account = self._get_wip_account() analytic_account = self._get_project_analytic_account() lines_with_wip_account = ( - line for line in move_line_vals - if line[2]['account_id'] == wip_account.id + line + for line in move_line_vals + if line[2]["account_id"] == wip_account.id ) for line in lines_with_wip_account: - line[2]['analytic_account_id'] = analytic_account.id - line[2]['task_id'] = self.task_id.id + line[2]["analytic_account_id"] = analytic_account.id + line[2]["task_id"] = self.task_id.id return move_line_vals def _is_consumption(self): - return self.picking_code == 'consumption' + return self.picking_code == "consumption" def _is_consumption_return(self): - return self.picking_code == 'consumption_return' + return self.picking_code == "consumption_return" def _generate_consumption_account_move(self, qty, description, svl_id, cost): self._check_project_has_wip_account() wip_account = self._get_wip_account() - journal_id, dummy, dummy, acc_valuation = self._get_accounting_data_for_valuation() + journal_id, dummy, dummy, acc_valuation = ( + self._get_accounting_data_for_valuation() + ) self.with_company(self.project_id.company_id.id)._create_account_move_line( credit_account_id=acc_valuation, debit_account_id=wip_account.id, @@ -63,45 +70,54 @@ def _generate_consumption_account_move(self, qty, description, svl_id, cost): qty=qty, description=description, svl_id=svl_id, - cost=cost) + cost=cost, + ) def _generate_consumption_return_account_move(self, qty, description, svl_id, cost): self._check_project_has_wip_account() wip_account = self._get_wip_account() - journal_id, dummy, dummy, acc_valuation = self._get_accounting_data_for_valuation() + journal_id, dummy, dummy, acc_valuation = ( + self._get_accounting_data_for_valuation() + ) self.with_company(self.project_id.company_id.id)._create_account_move_line( - credit_account_id=acc_valuation, - debit_account_id=wip_account.id, + credit_account_id=wip_account.id, + debit_account_id=acc_valuation, journal_id=journal_id, qty=qty, description=description, svl_id=svl_id, - cost=cost) + cost=cost, + ) def _check_project_has_wip_account(self): - project = self.project_id self = self.with_company(self.company_id.id) + project = self.project_id if not project.type_id: - raise ValidationError(_( - 'The transfer {picking} can not be processed because ' - 'the project {project} has no project type.' - ).format( - picking=self.picking_id.name, - project=project.display_name, - )) + raise ValidationError( + _( + "The transfer {picking} can not be processed because " + "the project {project} has no project type." + ).format( + picking=self.picking_id.name, + project=project.display_name, + ) + ) if not project.type_id.wip_account_id: - raise ValidationError(_( - 'The transfer {picking} can not be processed because ' - 'the project type {project_type} has no WIP account.' - ).format( - picking=self.picking_id.name, - project_type=project.type_id.display_name, - )) + raise ValidationError( + _( + "The transfer {picking} can not be processed because " + "the project type {project_type} has no WIP account." + ).format( + picking=self.picking_id.name, + project_type=project.type_id.display_name, + ) + ) def _get_wip_account(self): self = self.with_company(self.company_id.id) return self.project_id.type_id.wip_account_id def _get_project_analytic_account(self): + self = self.with_company(self.company_id.id) return self.project_id.analytic_account_id diff --git a/project_wip_material/tests/common.py b/project_wip_material/tests/common.py index ece899c8..42629eb9 100644 --- a/project_wip_material/tests/common.py +++ b/project_wip_material/tests/common.py @@ -11,48 +11,92 @@ def setUpClass(cls): super().setUpClass() cls.manager.groups_id |= cls.env.ref('account.group_account_manager') - cls.journal = cls.env['account.journal'].create({ - 'name': 'Stock Journal', - 'type': 'general', - 'code': 'STOCK', - 'company_id': cls.company.id, - }) + cls.journal = ( + cls.env["account.journal"] + .with_user(cls.manager) + .create( + { + "name": "Stock Journal", + "type": "general", + "code": "STOCK", + "company_id": cls.company.id, + } + ) + ) - cls.stock_account = cls.env['account.account'].create({ - 'name': 'Raw Material Stocks', - 'code': '130101', - 'user_type_id': cls.env.ref('account.data_account_type_non_current_assets').id, - 'company_id': cls.company.id, - }) + cls.stock_account = ( + cls.env["account.account"] + .with_user(cls.manager) + .create( + { + "name": "Raw Material Stocks", + "code": "130101", + "user_type_id": cls.env.ref( + "account.data_account_type_non_current_assets" + ).id, + "company_id": cls.company.id, + } + ) + ) - cls.input_account = cls.env['account.account'].create({ - 'name': 'Stock Received / Not Invoiced', - 'code': '230102', - 'user_type_id': cls.env.ref('account.data_account_type_non_current_assets').id, - 'company_id': cls.company.id, - }) + cls.input_account = ( + cls.env["account.account"] + .with_user(cls.manager) + .create( + { + "name": "Stock Received / Not Invoiced", + "code": "230102", + "user_type_id": cls.env.ref( + "account.data_account_type_non_current_assets" + ).id, + "company_id": cls.company.id, + } + ) + ) - cls.output_account = cls.env['account.account'].create({ - 'name': 'Stock Delivered / Not Invoiced', - 'code': '130102', - 'user_type_id': cls.env.ref('account.data_account_type_non_current_assets').id, - 'company_id': cls.company.id, - }) + cls.output_account = ( + cls.env["account.account"] + .with_user(cls.manager) + .create( + { + "name": "Stock Delivered / Not Invoiced", + "code": "130102", + "user_type_id": cls.env.ref( + "account.data_account_type_non_current_assets" + ).id, + "company_id": cls.company.id, + } + ) + ) - cls.wip_account = cls.env['account.account'].create({ - 'name': 'Work In Progress', - 'code': '140101', - 'user_type_id': cls.env.ref('account.data_account_type_non_current_assets').id, - 'reconcile': True, - 'company_id': cls.company.id, - }) + cls.wip_account = ( + cls.env["account.account"] + .with_user(cls.manager) + .create( + { + "name": "Work In Progress", + "code": "140101", + "user_type_id": cls.env.ref( + "account.data_account_type_non_current_assets" + ).id, + "reconcile": True, + "company_id": cls.company.id, + } + ) + ) - cls.project_type = cls.env['project.type'].create({ - 'name': 'Trailer Refurb', - 'wip_account_id': cls.wip_account.id, - }) + cls.project_type = ( + cls.env["project.type"] + .with_user(cls.manager) + .create( + { + "name": "Trailer Refurb", + "wip_account_id": cls.wip_account.id, + } + ) + ) - cls.project.type_id = cls.project_type + cls.project.with_user(cls.manager).write({"type_id": cls.project_type}) cls.product_category.write({ 'property_valuation': 'real_time', diff --git a/project_wip_material/tests/test_wip_journal_entries.py b/project_wip_material/tests/test_wip_journal_entries.py index 69bb5949..3e4448c3 100644 --- a/project_wip_material/tests/test_wip_journal_entries.py +++ b/project_wip_material/tests/test_wip_journal_entries.py @@ -39,8 +39,8 @@ def setUpClass(cls): cls.move = cls._create_material_line(initial_qty=10).move_ids cls._force_transfer_move(cls.move) cls.account_move = cls.move.account_move_ids - cls.debit_line = cls.account_move.line_ids.filtered(lambda l: l.debit) - cls.credit_line = cls.account_move.line_ids.filtered(lambda l: l.credit) + cls.debit_line = cls.account_move.line_ids.filtered(lambda line: line.debit) + cls.credit_line = cls.account_move.line_ids.filtered(lambda line: line.credit) cls.expected_value = 500 # 50 * 10 (product_a_value * initial_qty) def test_debit_account_is_wip(self): @@ -95,8 +95,8 @@ def setUpClass(cls): cls._force_transfer_move(initial_move) cls.move = cls._return_stock_move(initial_move, 10) cls.account_move = cls.move.account_move_ids - cls.debit_line = cls.account_move.line_ids.filtered(lambda l: l.debit) - cls.credit_line = cls.account_move.line_ids.filtered(lambda l: l.credit) + cls.debit_line = cls.account_move.line_ids.filtered(lambda line: line.debit) + cls.credit_line = cls.account_move.line_ids.filtered(lambda line: line.credit) cls.expected_value = 500 # 50 * 10 (product_a_value * initial_qty) def test_credit_account_is_wip(self):