-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] business_requirement_sale: revamp
* Refactorization * Method optimization * Tests
- Loading branch information
1 parent
a384842
commit d82deb1
Showing
18 changed files
with
367 additions
and
378 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# Copyright 2019 Tecnativa Victor M.M. Torres> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import business | ||
from . import business_requirement | ||
from . import business_requirement_deliverable | ||
from . import sale_layout_category | ||
from . import sale_order |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Copyright 2019 Tecnativa Victor M.M. Torres> | ||
# Copyright 2019 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models, _ | ||
|
||
|
||
class BusinessRequirement(models.Model): | ||
_inherit = 'business.requirement' | ||
|
||
sale_order_ids = fields.One2many( | ||
comodel_name='sale.order', | ||
inverse_name='business_requirement_id', | ||
string='Sales Orders', | ||
) | ||
sale_order_count = fields.Integer( | ||
string='Sales Orders Count', | ||
compute='_compute_sale_order_count', | ||
) | ||
|
||
@api.multi | ||
@api.depends('sale_order_ids') | ||
def _compute_sale_order_count(self): | ||
groups = self.env['sale.order'].read_group( | ||
domain=[('business_requirement_id', 'in', self.ids)], | ||
fields=['business_requirement_id'], | ||
groupby=['business_requirement_id'], | ||
) | ||
data = { | ||
x['business_requirement_id'][0]: x['business_requirement_id_count'] | ||
for x in groups | ||
} | ||
for rec in self: | ||
rec.sale_order_count = data.get(rec.id, 0) | ||
|
||
@api.multi | ||
def open_orders(self): | ||
action = self.env.ref('sale.action_quotations').read()[0] | ||
if len(self) == 1: | ||
action['context'] = { | ||
'search_default_business_requirement_id': self.id, | ||
} | ||
else: | ||
action['domain'] = [('business_requirement_id', 'in', self.ids)], | ||
return action |
13 changes: 13 additions & 0 deletions
13
business_requirement_sale/models/business_requirement_deliverable.py
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2019 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class BusinessRequirementDeliverableSection(models.Model): | ||
_inherit = 'business.requirement.deliverable.section' | ||
|
||
sale_layout_category_id = fields.Many2one( | ||
comodel_name='sale.layout_category', | ||
string='Sales Layout Category', | ||
) |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2019 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class SaleLayoutCategory(models.Model): | ||
_inherit = 'sale.layout_category' | ||
|
||
br_deliverable_section_id = fields.Many2one( | ||
comodel_name='business.requirement.deliverable.section', | ||
string="Business Requirement Deliverable Section", | ||
) |
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 |
---|---|---|
@@ -1,3 +1,2 @@ | ||
This module extends the functionality of Business Requirement | ||
and to allow you to convert into new Sale Orders. | ||
Deliverables if selected will be Order Lines on the new Order created. | ||
This module extends the functionality of Business Requirement to allow you to | ||
create from them Sales Orders, taking deliverables as sales order lines. |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_business_requirement_sale |
103 changes: 103 additions & 0 deletions
103
business_requirement_sale/tests/test_business_requirement_sale.py
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 |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo.tests import common | ||
|
||
|
||
class TestBusinessRequirementSale(common.SavepointCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.br_model = cls.env['business.requirement'] | ||
cls.brd_model = cls.env['business.requirement.deliverable'] | ||
cls.brds_model = cls.env['business.requirement.deliverable.section'] | ||
cls.product_model = cls.env['product.product'] | ||
cls.partner = cls.env['res.partner'].create({ | ||
'name': 'Test BR partner', | ||
}) | ||
cls.business_requirement = cls.br_model.create({ | ||
'name': 'Test BR', | ||
'description': 'Test BR', | ||
'partner_id': cls.partner.id, | ||
}) | ||
cls.product1 = cls.product_model.create({ | ||
'name': 'Test product BR 1', | ||
}) | ||
cls.product2 = cls.product_model.create({ | ||
'name': 'Test product BR 2', | ||
}) | ||
cls.section = cls.brds_model.create({ | ||
'name': 'Test BRD section', | ||
}) | ||
cls.deliverable1 = cls.brd_model.create({ | ||
'name': 'Test deliverable 1', | ||
'business_requirement_id': cls.business_requirement.id, | ||
'product_id': cls.product1.id, | ||
'section_id': cls.section.id, | ||
'sale_price_unit': 80, | ||
'qty': 3, | ||
}) | ||
cls.deliverable2 = cls.brd_model.create({ | ||
'name': 'Test deliverable 2', | ||
'business_requirement_id': cls.business_requirement.id, | ||
'product_id': cls.product2.id, | ||
'sale_price_unit': 20, | ||
'qty': 5, | ||
}) | ||
cls.wizard = cls.env['business.requirement.create.sale'].with_context( | ||
active_model=cls.br_model._name, | ||
active_id=cls.business_requirement.id, | ||
).create({}) | ||
|
||
def test_full_flow(self): | ||
action = self.wizard.button_create() | ||
# Sales order | ||
self.assertTrue(action['res_id']) | ||
order = self.env['sale.order'].browse(action['res_id']) | ||
self.assertEqual(order.partner_id, self.partner) | ||
self.assertEqual(len(order.order_line), 2) | ||
self.assertEqual(self.business_requirement.sale_order_count, 1) | ||
self.assertEqual( | ||
order.business_requirement_id, self.business_requirement, | ||
) | ||
action = self.business_requirement.open_orders() | ||
self.assertTrue( | ||
action['context']['search_default_business_requirement_id'], | ||
) | ||
br2 = self.business_requirement.copy() | ||
action = (self.business_requirement + br2).open_orders() | ||
self.assertTrue(action['domain']) | ||
# Line 1 | ||
line1 = order.order_line.filtered( | ||
lambda x: x.product_id == self.product1) | ||
self.assertTrue(line1) | ||
self.assertAlmostEqual(line1.product_uom_qty, 1) | ||
self.assertAlmostEqual(line1.price_unit, 240) | ||
self.assertEqual( | ||
line1.business_requirement_deliverable_id, self.deliverable1, | ||
) | ||
# Section | ||
self.assertTrue(self.section.sale_layout_category_id) | ||
self.assertTrue( | ||
self.section.sale_layout_category_id.name, self.section.name, | ||
) | ||
self.assertTrue(line1.layout_category_id) | ||
# Line 2 | ||
line2 = order.order_line.filtered( | ||
lambda x: x.product_id == self.product2) | ||
self.assertTrue(line2) | ||
self.assertAlmostEqual(line2.product_uom_qty, 1) | ||
self.assertAlmostEqual(line2.price_unit, 100) | ||
self.assertFalse(line2.layout_category_id) | ||
self.assertEqual( | ||
line2.business_requirement_deliverable_id, self.deliverable2, | ||
) | ||
|
||
def test_flow_one_line_non_totaled(self): | ||
self.wizard.deliverable_ids = [(6, 0, self.deliverable1.ids)] | ||
self.wizard.totaled_method = 'standard' | ||
action = self.wizard.button_create() | ||
self.assertTrue(action['res_id']) | ||
order = self.env['sale.order'].browse(action['res_id']) | ||
self.assertEqual(len(order.order_line), 1) | ||
self.assertAlmostEqual(order.order_line.product_uom_qty, 3) | ||
self.assertAlmostEqual(order.order_line.price_unit, 80) |
Oops, something went wrong.