Skip to content

Commit

Permalink
TA#64294 [FIX] project_wip_material: Add module to dependencies (#381)
Browse files Browse the repository at this point in the history
* TA#64294 [FIX] project_wip_material: Add module to dependencies
  • Loading branch information
majouda committed Apr 5, 2024
1 parent 5aa27ae commit d6cc66e
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 81 deletions.
9 changes: 1 addition & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,13 +30,6 @@ services:
expose:
- 5432

testcafe:
build:
context: .testcafe
dockerfile: Dockerfile
depends_on:
- odoo

volumes:
odoo-web-data:
odoo-db-data:
3 changes: 2 additions & 1 deletion project_wip_material/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

{
'name': 'Project WIP Material',
'version': '1.1.0',
'version': '1.1.1',
'author': 'Numigi',
'maintainer': 'Numigi',
'website': 'https://bit.ly/numigi-com',
'license': 'LGPL-3',
'category': 'Project',
'summary': 'WIP accounting entries from consumed products',
'depends': [
'project_task_analytic_lines',
'project_material',
'project_wip',
],
Expand Down
80 changes: 48 additions & 32 deletions project_wip_material/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -23,85 +23,101 @@ 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,
journal_id=journal_id,
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
116 changes: 80 additions & 36 deletions project_wip_material/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 4 additions & 4 deletions project_wip_material/tests/test_wip_journal_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit d6cc66e

Please sign in to comment.