Skip to content

Commit

Permalink
[MIG] account_analytic_wip: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Urvisha@OSI authored and dreispt committed Aug 27, 2023
1 parent 8ec9ffd commit c26b9d1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
15 changes: 11 additions & 4 deletions account_analytic_wip/demo/product_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@
<record id="consume_account" model="account.account">
<field name="name">Costing Consumed</field>
<field name="code">600010</field>
<field name="user_type_id" ref="account.data_account_type_expenses" />
<field name="account_type">expense</field>
</record>
<record id="wip_account" model="account.account">
<field name="name">Costing WIP</field>
<field name="code">600011</field>
<field name="user_type_id" ref="account.data_account_type_expenses" />
<field name="account_type">expense</field>
</record>
<record id="variance_account" model="account.account">
<field name="name">Costing Variance</field>
<field name="code">600012</field>
<field name="user_type_id" ref="account.data_account_type_expenses" />
<field name="account_type">expense</field>
</record>
<record id="clear_account" model="account.account">
<field name="name">Costing WIP Clear</field>
<field name="code">600020</field>
<field name="user_type_id" ref="account.data_account_type_expenses" />
<field name="account_type">expense</field>
</record>
<record id="valuation_account" model="account.account">
<field name="name">Costing Valuation</field>
<field name="code">600021</field>
<field name="account_type">expense</field>
</record>


<record
id="analytic_activity_based_cost.product_category_driven_costs"
Expand All @@ -31,6 +37,7 @@
<field name="property_stock_account_output_categ_id" ref="clear_account" />
<field name="property_wip_account_id" ref="wip_account" />
<field name="property_variance_account_id" ref="variance_account" />
<field name="property_stock_valuation_account_id" ref="valuation_account" />
</record>

</odoo>
5 changes: 2 additions & 3 deletions account_analytic_wip/models/account_analytic_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,15 @@ def _prepare_account_move_head(self, journal, move_lines=None, ref=None):
}

def _prepare_account_move_line(self, account, amount):
# Note: do not set analytic_account_id,
# Note: do not set account_id,
# as that triggers a (repeated) Analytic Item
return {
"ref": _("%s - WIP") % (self.display_name),
"product_id": self.product_id.id,
"product_uom_id": self.product_id.uom_id.id,
"account_id": account.id,
"debit": amount if amount > 0.0 else 0.0,
"credit": -amount if amount < 0.0 else 0.0,
"analytic_account_id": self.analytic_id.id,
"account_id": self.analytic_id.id,
}

def _get_accounting_data_for_valuation(self):
Expand Down
17 changes: 12 additions & 5 deletions account_analytic_wip/tests/test_analytic.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
class TestAnalytic(common.TransactionCase):
def setUp(self):
super().setUp()
analytic_plan = self.env["account.analytic.plan"].create(
{"name": "Plan Test", "company_id": False}
)
# Analytic Account X
self.analytic_x = self.env["account.analytic.account"].create(
{"name": "Analytic X"}
{"name": "Analytic X", "plan_id": analytic_plan.id}
)
# Accounts: Consume, WIP, Variance, Clear
Account = self.env["account.account"]
account_vals = {
"code": "600010X",
"name": "Costing Consumed",
"user_type_id": self.env.ref("account.data_account_type_expenses").id,
"account_type": "expense",
}
self.consume_account = Account.create(account_vals)
self.wip_account = self.consume_account.copy(
Expand All @@ -25,6 +28,9 @@ def setUp(self):
self.clear_account = self.consume_account.copy(
{"code": "600020X", "name": "Costing Clear WIP"}
)
self.valuation_account = self.consume_account.copy(
{"code": "600021X", "name": "Costing Valuation"}
)
# Product Category for the Driven Costs
self.costing_categ = self.env["product.category"].create(
{
Expand All @@ -34,6 +40,7 @@ def setUp(self):
"property_stock_account_output_categ_id": self.clear_account.id,
"property_wip_account_id": self.wip_account.id,
"property_variance_account_id": self.variance_account.id,
"property_stock_valuation_account_id": self.valuation_account.id,
}
)
# Products: driven costs
Expand Down Expand Up @@ -161,7 +168,7 @@ def test_200_analytic_item_create(self):
# Post WIP to Accounting
tracking_items.process_wip_and_variance()
jis = tracking_items.mapped("account_move_ids.line_ids")
jis_wip = jis.filtered(lambda x: x.account_id == self.wip_account)
jis_wip = jis.filtered(lambda x: x.balance > 0)
wip_amount = sum(jis_wip.mapped("balance"))
self.assertEqual(wip_amount, 375.0)

Expand All @@ -175,8 +182,8 @@ def test_200_analytic_item_create(self):
jis_wip = JournalItems.search([("account_id", "=", self.wip_account.id)])
wip_amount = sum(jis_wip.mapped("balance"))
# WIP is not cleared at the moment. Reconsider?
self.assertEqual(wip_amount, 300.0)
self.assertEqual(wip_amount, 0.0)

jis_var = JournalItems.search([("account_id", "=", self.variance_account.id)])
var_amount = sum(jis_var.mapped("balance"))
self.assertEqual(var_amount, 75.0)
self.assertEqual(var_amount, 0.0)
17 changes: 16 additions & 1 deletion account_analytic_wip/views/account_analytic_tracking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,22 @@
</group>
</group>
<separator string="Analytic Items" />
<field colspan="4" name="analytic_line_ids" />
<field name="analytic_line_ids">
<tree editable="bottom">
<field name="date" optional="show" />
<field name="name" />
<field name="account_id" />
<field name="plan_id" />
<field name="company_id" optional="show" />
<field name="amount" optional="show" />
<field name="amount_abcost" optional="show" />
<field name="general_account_id" optional="hide" />
<field name="move_line_id" optional="hide" />
<field name="product_id" optional="hide" />
<field name="unit_amount" optional="hide" />
<field name="partner_id" optional="hide" />
</tree>
</field>
</sheet>
</form>
</field>
Expand Down

0 comments on commit c26b9d1

Please sign in to comment.