Skip to content

Commit

Permalink
[ADD] tests and demos
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinDupont committed Oct 24, 2023
1 parent 5b30a55 commit e8fee6d
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
1 change: 1 addition & 0 deletions mrp_sale_grouped/demo/bom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<record model="mrp.bom" id="demo_bom_tomato_tart">
<field name="code">TOMATO_PIE</field>
<field name="product_tmpl_id" ref="mrp_sale_grouped.demo_product_template_tomato_tart"/>
<field name="product_id" ref="mrp_sale_grouped.demo_product_tomato_tart"/>
</record>

<record model="mrp.bom.line" id="demo_bom_tomato_tart_line_pie">
Expand Down
7 changes: 6 additions & 1 deletion mrp_sale_grouped/demo/product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
</record>

<record model="product.template" id="demo_product_template_tomato_tart">
<field name="name">Tomato pie</field>
<field name="name">Tomato pie - template</field>
<field name="categ_id" ref="product.product_category_all"/>
<field name="image" type="base64" file="mrp_sale_grouped/static/img/tomato_pie.png"/>
</record>

<record model="product.product" id="demo_product_tomato_tart">
<field name="name">Tomato pie</field>
<field name="categ_id" ref="product.product_category_all"/>
<field name="product_tmpl_id" ref="mrp_sale_grouped.demo_product_template_tomato_tart"/>
</record>


</odoo>
5 changes: 5 additions & 0 deletions mrp_sale_grouped/demo/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="partner_id" eval="ref('base.res_partner_4')" />
</record>

<!-- Sale for Deco Addict - with products with BoMs -->
<record model="sale.order" id="demo_sale_deco_addict">
<field name="partner_id" eval="ref('base.res_partner_2')" />
</record>

</odoo>
8 changes: 8 additions & 0 deletions mrp_sale_grouped/demo/sale_order_line.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,12 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
<field name="price_unit">4</field>
</record>

<!-- Sale line for Partner 5 - with products with BoMs -->
<record model="sale.order.line" id="demo_sale_order_line_deco_addict">
<field name="order_id" ref="mrp_sale_grouped.demo_sale_deco_addict"/>
<field name="product_id" ref="mrp_sale_grouped.demo_product_tomato_tart"/>
<field name="product_uom_qty">2</field>
<field name="price_unit">7</field>
</record>

</odoo>
25 changes: 25 additions & 0 deletions mrp_sale_grouped/tests/test_mrp_sale_grouped.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# @author: Quentin DUPONT (quentin.dupont@grap.coop)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.exceptions import Warning as UserError
from odoo.tests.common import TransactionCase


Expand All @@ -11,16 +12,28 @@ def setUp(self):
# Objects
self.mrp_sale_grouped_obj = self.env["mrp.sale.grouped"]
self.wizard_obj = self.env["sale.grouped.wizard"]
self.wizard_purchase_list_obj = self.env["bom.print.purchase.list.wizard"]
# Demo datas
self.sale_order_gemini = self.env.ref("mrp_sale_grouped.demo_sale_gemini")
self.sale_order_ready_mat = self.env.ref("mrp_sale_grouped.demo_sale_ready_mat")
self.sale_order_with_boms = self.env.ref(
"mrp_sale_grouped.demo_sale_deco_addict"
)
self.bom_pie = self.env.ref("mrp_sale_grouped.demo_bom_tomato_tart")
self.product_tmpl_pie = self.env.ref(
"mrp_sale_grouped.demo_product_template_tomato_tart"
)
# Create one sale_grouped with sales
self.mrp_sale_grouped_1 = self.mrp_sale_grouped_obj.create(
{"name": "TEST Grouped Sale"}
)
self.mrp_sale_grouped_with_boms = self.mrp_sale_grouped_obj.create(
{"name": "TEST with BoMs"}
)
# Add grouped to sales
self.sale_order_gemini.mrp_sale_grouped_id = self.mrp_sale_grouped_1
self.sale_order_ready_mat.mrp_sale_grouped_id = self.mrp_sale_grouped_1
self.sale_order_with_boms.mrp_sale_grouped_id = self.mrp_sale_grouped_with_boms

def test_01_create_grouped_check_sale_linked(self):
self.assertEqual(self.mrp_sale_grouped_1.orders_qty, 2)
Expand All @@ -46,3 +59,15 @@ def test_04_sale_grouped_report(self):
active_ids=[self.mrp_sale_grouped_1.id]
).create({})
wizard.print_sale_sum_up()

def test_05_check_wizard_production_with_boms(self):
self.wizard_purchase_list_obj.with_context(
active_ids=[self.mrp_sale_grouped_with_boms.id],
active_model="mrp.sale.grouped",
).create({})

def test_06_check_wizard_production_without_boms(self):
with self.assertRaises(UserError):
self.wizard_purchase_list_obj.with_context(
active_ids=[self.mrp_sale_grouped_1.id], active_model="mrp.sale.grouped"
).create({})
1 change: 0 additions & 1 deletion mrp_sale_grouped/wizard/bom_print_purchase_list_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class BomPrintPurchaseListWizard(models.TransientModel):
@api.model
def _default_no_origin(self):
context = self.env.context

active_model = context.get("active_model")
if active_model == "mrp.sale.grouped":
sale_grouped_active_id = context.get("active_ids", [])
Expand Down

0 comments on commit e8fee6d

Please sign in to comment.