Skip to content

Commit

Permalink
[FIX] SavepointCase tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Oct 22, 2019
1 parent 45245a7 commit 8740709
Show file tree
Hide file tree
Showing 11 changed files with 190 additions and 168 deletions.
11 changes: 7 additions & 4 deletions analytic_contract_value/tests/test_analytic_contract_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@


class TestAnalyticSchedule(common.SavepointCase):
def setUp(cls):
super(TestAnalyticSchedule, cls).setUp()

@classmethod
def setUpClass(cls):
super(TestAnalyticSchedule, cls).setUpClass()
cls.project_project = cls.env["project.project"]
cls.project = cls.project_project.create(
{"name": "Test project", "code": "ACV0001"}
Expand Down Expand Up @@ -49,5 +51,6 @@ def setUp(cls):
}
)

def test_contarct_value(cls):
cls.assertEquals(cls.account_id.contract_value, 100000.0, "Bad value")
def test_contarct_value(self):
self.assertEquals(self.account_id.contract_value, 100000.0,
"Bad value")
16 changes: 9 additions & 7 deletions analytic_cost_revenue/tests/test_analytic_cost_revenue.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@


class TestAnalyticCostRevenue(common.SavepointCase):
def setUp(cls):
super(TestAnalyticCostRevenue, cls).setUp()

@classmethod
def setUpClass(cls):
super(TestAnalyticCostRevenue, cls).setUpClass()
cls.project_project = cls.env["project.project"]
cls.project = cls.project_project.create(
{"name": "Test project", "code": "ACV0001"}
Expand Down Expand Up @@ -78,8 +80,8 @@ def setUp(cls):
}
)

def test_cost_revenue(cls):
cls.assertEqual(cls.account_id.material_cost, 100.0)
cls.assertEqual(cls.account_id.labor_cost, 0.0)
cls.assertEqual(cls.account_id.revenue, 200.0)
cls.assertEqual(cls.account_id.gross_profit, 100.0)
def test_cost_revenue(self):
self.assertEqual(self.account_id.material_cost, 100.0)
self.assertEqual(self.account_id.labor_cost, 0.0)
self.assertEqual(self.account_id.revenue, 200.0)
self.assertEqual(self.account_id.gross_profit, 100.0)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@


class TestAnalyticCostRevenue(common.SavepointCase):
def setUp(cls):
super(TestAnalyticCostRevenue, cls).setUp()

@classmethod
def setUpClass(cls):
super(TestAnalyticCostRevenue, cls).setUpClass()
cls.project_project = cls.env["project.project"]
cls.project = cls.project_project.create(
{"name": "Test project", "code": "ACV0001"}
Expand Down Expand Up @@ -99,8 +101,8 @@ def setUp(cls):
}
)

def test_cost_revenue(cls):
cls.assertEqual(cls.account_id.material_cost_plan, -100.0)
cls.assertEqual(cls.account_id.labor_cost_plan, -0.0)
cls.assertEqual(cls.account_id.revenue_plan, 200.0)
cls.assertEqual(cls.account_id.gross_profit_plan, 100.0)
def test_cost_revenue(self):
self.assertEqual(self.account_id.material_cost_plan, -100.0)
self.assertEqual(self.account_id.labor_cost_plan, -0.0)
self.assertEqual(self.account_id.revenue_plan, 200.0)
self.assertEqual(self.account_id.gross_profit_plan, 100.0)
27 changes: 14 additions & 13 deletions analytic_resource_plan/tests/test_analytic_resource_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

class TestAnalyticResourcePlan(common.SavepointCase):

def setUp(cls):
super(TestAnalyticResourcePlan, cls).setUp()
@classmethod
def setUpClass(cls):
super(TestAnalyticResourcePlan, cls).setUpClass()
cls.project = cls.env['project.project'].create(
{'name': 'Test project',
'code': 'X0001'})
Expand Down Expand Up @@ -60,14 +61,14 @@ def _create_account(self, acc_type, name, code, company):
})
return account

def test_plan(cls):
cls.resource_plan_line.action_button_confirm()
cls.assertEqual(cls.resource_plan_line.state, 'confirm')
plan_line = cls.env['account.analytic.line.plan'].search(
[('resource_plan_id', '=', cls.resource_plan_line.id)])
cls.assertEqual(len(plan_line), 1, 'Wrong plan lines number')
cls.resource_plan_line.action_button_draft()
cls.assertEqual(cls.resource_plan_line.state, 'draft')
plan_line = cls.env['account.analytic.line.plan'].search(
[('resource_plan_id', '=', cls.resource_plan_line.id)])
cls.assertEqual(len(plan_line), 0, 'Plan line not deleted')
def test_plan(self):
self.resource_plan_line.action_button_confirm()
self.assertEqual(self.resource_plan_line.state, 'confirm')
plan_line = self.env['account.analytic.line.plan'].search(
[('resource_plan_id', '=', self.resource_plan_line.id)])
self.assertEqual(len(plan_line), 1, 'Wrong plan lines number')
self.resource_plan_line.action_button_draft()
self.assertEqual(self.resource_plan_line.state, 'draft')
plan_line = self.env['account.analytic.line.plan'].search(
[('resource_plan_id', '=', self.resource_plan_line.id)])
self.assertEqual(len(plan_line), 0, 'Plan line not deleted')
40 changes: 22 additions & 18 deletions analytic_resource_plan_mrp/tests/test_analytic_resource_plan_mrp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
class TestAnalyticResourcePlanMrp(
test_analytic_resource_plan_stock.TestAnalyticResourcePlanStock
):
def setUp(cls):
super(TestAnalyticResourcePlanMrp, cls).setUp()

@classmethod
def setUpClass(cls):
super(TestAnalyticResourcePlanMrp, cls).setUpClass()
cls.analytic_account_obj = cls.env["account.analytic.account"]
cls.analytic_resource_plan_obj = cls.env["analytic.resource.plan.line"]
cls.mrp_bom_obj = cls.env["mrp.bom"]
Expand Down Expand Up @@ -39,10 +41,10 @@ def setUp(cls):

cls.bom = cls._create_bom(cls.product_id)
cls.resource_plan_line_wbom_id = cls._create_analytic_resource_plan(
cls.product_id
)
cls.product_id)
cls.account_id.bom_id = cls.bom.id

@classmethod
def _create_bom(cls, product):
test_bom = cls.mrp_bom_obj.create(
{
Expand All @@ -62,6 +64,7 @@ def _create_bom(cls, product):
)
return test_bom

@classmethod
def _create_analytic_account(
cls, name, partner, analytic_plan_version, location
):
Expand All @@ -74,6 +77,7 @@ def _create_analytic_account(
}
)

@classmethod
def _create_analytic_resource_plan(cls, product):
return cls.analytic_resource_plan_obj.create(
{
Expand All @@ -87,40 +91,40 @@ def _create_analytic_resource_plan(cls, product):
}
)

def test_resource_plan_line(cls):
cls.resource_plan_line_wbom_id.action_button_confirm()
child = cls.resource_plan_line_wbom_id.child_ids
plan_lines = cls.env["account.analytic.line.plan"].search(
def test_resource_plan_line(self):
self.resource_plan_line_wbom_id.action_button_confirm()
child = self.resource_plan_line_wbom_id.child_ids
plan_lines = self.env["account.analytic.line.plan"].search(
[("resource_plan_id", "=", child.id)]
)
cls.assertEqual(len(plan_lines), 1, "bad plan lines")
cls.assertEqual(child.state, "confirm", "child not confirm")
cls.assertEqual(child.unit_amount, 4.0, "wrong qty in child")
self.assertEqual(len(plan_lines), 1, "bad plan lines")
self.assertEqual(child.state, "confirm", "child not confirm")
self.assertEqual(child.unit_amount, 4.0, "wrong qty in child")
# test produce
wiz_id = (
cls.env["analytic.resource.plan.line.produce"]
self.env["analytic.resource.plan.line.produce"]
.with_context(
active_model="analytic.resource.plan.line",
active_ids=cls.resource_plan_line_wbom_id.id,
active_ids=self.resource_plan_line_wbom_id.id,
)
.create({})
)
move_action = wiz_id.do_produce()
move_id = safe_eval(move_action["domain"])[0][2]
move = cls.env["stock.move"].browse(move_id)[0]
cls.assertEqual(
move = self.env["stock.move"].browse(move_id)[0]
self.assertEqual(
move.product_qty, child.unit_amount, "Wrong consumed qty"
)
# test consume
wiz_id = (
cls.env["analytic.resource.plan.line.consume"]
self.env["analytic.resource.plan.line.consume"]
.with_context(
active_model="analytic.resource.plan.line",
active_ids=cls.resource_plan_line_wbom_id.id,
active_ids=self.resource_plan_line_wbom_id.id,
)
.create({})
)
wiz_id.do_consume()
cls.assertEqual(
self.assertEqual(
move.product_qty, child.unit_amount, "Wrong consumed qty"
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,43 @@
class TestAnalyticResourcePlanPurchase(
test_analytic_resource_plan_stock.TestAnalyticResourcePlanStock
):
def setUp(cls):
super(TestAnalyticResourcePlanPurchase, cls).setUp()

def test_res_purchase(cls):
cls.assertEqual(
cls.resource_plan_line.qty_available,
@classmethod
def setUpClass(cls):
super(TestAnalyticResourcePlanPurchase, cls).setUpClass()

def test_res_purchase(self):
self.assertEqual(
self.resource_plan_line.qty_available,
0.0,
"Showing qty where there is not",
)
cls.assertEqual(
cls.resource_plan_line.request_state, "none", "should no request"
self.assertEqual(
self.resource_plan_line.request_state, "none", "should no request"
)
cls.resource_plan_line.action_button_confirm()
cls.assertEqual(
cls.resource_plan_line.request_state,
self.resource_plan_line.action_button_confirm()
self.assertEqual(
self.resource_plan_line.request_state,
"draft",
"should draft request",
)
purchase_request_line = cls.resource_plan_line.purchase_request_lines[
purchase_request_line = self.resource_plan_line.purchase_request_lines[
0
]
purchase_request = purchase_request_line.request_id
purchase_request.button_to_approve()
purchase_request.button_approved()
cls.assertEqual(
cls.resource_plan_line.request_state,
self.assertEqual(
self.resource_plan_line.request_state,
"approved",
"should approved request",
)
cls.assertEqual(
cls.resource_plan_line.requested_qty, 1.0, "requested wrong qty"
self.assertEqual(
self.resource_plan_line.requested_qty, 1.0, "requested wrong qty"
)
cls.resource_plan_line.action_button_draft()
cls.assertEqual(
cls.resource_plan_line.request_state,
self.resource_plan_line.action_button_draft()
self.assertEqual(
self.resource_plan_line.request_state,
"rejected",
"should rejected request",
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,72 +11,72 @@
class TestAnalyticResourcePlanStock(
test_analytic_resource_plan.TestAnalyticResourcePlan):

def setUp(cls):
super(TestAnalyticResourcePlanStock, cls).setUp()
@classmethod
def setUpClass(cls):
super(TestAnalyticResourcePlanStock, cls).setUpClass()
cls.location = cls.env['stock.location'].create({
'name': 'ACC',
'usage': 'internal',
'parent_id': cls.env.ref('stock.stock_location_stock').id,
'analytic_account_id': cls.account_id.id})
cls.account_id.location_id = cls.location

def test_res_stock(cls):
cls.assertEqual(cls.resource_plan_line.qty_available, 0.0,
'Showing qty where there is not')
cls.resource_plan_line.action_button_confirm()
def test_res_stock(self):
self.assertEqual(self.resource_plan_line.qty_available, 0.0,
'Showing qty where there is not')
self.resource_plan_line.action_button_confirm()

picking_in = cls.env['stock.picking'].create({
'picking_type_id': cls.env.ref('stock.picking_type_in').id,
'location_id': cls.env.ref('stock.stock_location_suppliers').id,
'location_dest_id': cls.account_id.location_id.id})
move1 = cls.env['stock.move'].create({
picking_in = self.env['stock.picking'].create({
'picking_type_id': self.env.ref('stock.picking_type_in').id,
'location_id': self.env.ref('stock.stock_location_suppliers').id,
'location_dest_id': self.account_id.location_id.id})
move1 = self.env['stock.move'].create({
'name': '/',
'product_id': cls.resource_plan_line.product_id.id,
'product_id': self.resource_plan_line.product_id.id,
'product_uom_qty': 5.0,
'analytic_account_id': cls.account_id.id,
'analytic_account_id': self.account_id.id,
'picking_id': picking_in.id,
'procure_method': 'make_to_stock',
'product_uom': cls.resource_plan_line.product_id.uom_id.id,
'location_id': cls.env.ref('stock.stock_location_suppliers').id,
'location_dest_id': cls.account_id.location_id.id,
'product_uom': self.resource_plan_line.product_id.uom_id.id,
'location_id': self.env.ref('stock.stock_location_suppliers').id,
'location_dest_id': self.account_id.location_id.id,
})
picking_in.action_confirm()

cls.resource_plan_line._compute_quantities()
self.resource_plan_line._compute_quantities()
# recomputing here as no relation to the pickings in this module
# to put in the api depends
cls.assertEqual(cls.resource_plan_line.incoming_qty, 5.0,
'Bad Incoming Qty')
cls.assertEqual(cls.resource_plan_line.virtual_available, 5.0,
'Bad virtual Qty')
self.assertEqual(self.resource_plan_line.incoming_qty, 5.0,
'Bad Incoming Qty')
self.assertEqual(self.resource_plan_line.virtual_available, 5.0,
'Bad virtual Qty')
picking_in.button_validate()
cls.assertEqual(cls.resource_plan_line.qty_available, 0.0,
'Bad QTY Available')
picking_out = cls.env['stock.picking'].create({
'picking_type_id': cls.env.ref('stock.picking_type_out').id,
'location_id': cls.location.id,
'location_dest_id': cls.env.ref(
self.assertEqual(self.resource_plan_line.qty_available, 0.0,
'Bad QTY Available')
picking_out = self.env['stock.picking'].create({
'picking_type_id': self.env.ref('stock.picking_type_out').id,
'location_id': self.location.id,
'location_dest_id': self.env.ref(
'stock.stock_location_customers').id})
move1.move_line_ids.qty_done = 5.0
picking_in.action_done()

cls.env['stock.move'].create({
self.env['stock.move'].create({
'name': '/',
'product_id': cls.resource_plan_line.product_id.id,
'product_id': self.resource_plan_line.product_id.id,
'product_uom_qty': 4.0,
'procure_method': 'make_to_stock',
'analytic_account_id': cls.account_id.id,
'analytic_account_id': self.account_id.id,
'picking_id': picking_out.id,
'product_uom': cls.resource_plan_line.product_id.uom_id.id,
'location_id': cls.location.id,
'product_uom': self.resource_plan_line.product_id.uom_id.id,
'location_id': self.location.id,
'location_dest_id':
cls.env.ref('stock.stock_location_customers').id,
self.env.ref('stock.stock_location_customers').id,
})
picking_out.action_confirm()
cls.resource_plan_line._compute_quantities()
self.resource_plan_line._compute_quantities()
# recomputing here as no relation to the pickings in this module
# to put in the api depends
cls.assertEqual(cls.resource_plan_line.virtual_available, 1.0,
'Bad Virtually Qty available')
cls.assertEqual(cls.resource_plan_line.outgoing_qty, 4.0,
'Bad Outgoing Qty')
self.assertEqual(self.resource_plan_line.virtual_available, 1.0,
'Bad Virtually Qty available')
self.assertEqual(self.resource_plan_line.outgoing_qty, 4.0,
'Bad Outgoing Qty')
Loading

0 comments on commit 8740709

Please sign in to comment.