Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
2
sale_automatic_workflow_stock/tests/__init__.py
Executable file
2
sale_automatic_workflow_stock/tests/__init__.py
Executable file
@@ -0,0 +1,2 @@
|
||||
from . import test_automatic_workflow
|
||||
from . import test_multicompany
|
||||
47
sale_automatic_workflow_stock/tests/common.py
Executable file
47
sale_automatic_workflow_stock/tests/common.py
Executable file
@@ -0,0 +1,47 @@
|
||||
# Copyright 2014 Camptocamp SA (author: Guewen Baconnier)
|
||||
# Copyright 2020 Camptocamp SA (author: Simone Orsi)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.addons.sale_automatic_workflow.tests.common import TestAutomaticWorkflowMixin
|
||||
|
||||
|
||||
class TestAutomaticWorkflowStockMixin(TestAutomaticWorkflowMixin):
|
||||
"""Extend to add stock related workflow."""
|
||||
|
||||
def create_sale_order(
|
||||
self, workflow, override=None, product_type="consu", extra_product_values=None
|
||||
):
|
||||
extra_product_values = extra_product_values or {}
|
||||
if product_type == "consu":
|
||||
extra_product_values["is_storable"] = True
|
||||
|
||||
# Override to create stock operations for each product
|
||||
order = super().create_sale_order(
|
||||
workflow,
|
||||
override=override,
|
||||
product_type=product_type,
|
||||
extra_product_values=extra_product_values,
|
||||
)
|
||||
# Create inventory
|
||||
for line in order.order_line:
|
||||
if line.product_id.is_storable:
|
||||
inventory = self.env["stock.quant"].create(
|
||||
{
|
||||
"product_id": line.product_id.id,
|
||||
"location_id": self.env.ref("stock.stock_location_stock").id,
|
||||
"inventory_quantity": line.product_uom_qty,
|
||||
}
|
||||
)
|
||||
inventory._apply_inventory()
|
||||
return order
|
||||
|
||||
def create_full_automatic(self, override=None):
|
||||
# Override to include default stock related values
|
||||
if not override:
|
||||
override = {}
|
||||
vals = {
|
||||
"picking_policy": "one",
|
||||
"validate_picking": True,
|
||||
}
|
||||
vals.update(override)
|
||||
return super().create_full_automatic(override=vals)
|
||||
104
sale_automatic_workflow_stock/tests/test_automatic_workflow.py
Executable file
104
sale_automatic_workflow_stock/tests/test_automatic_workflow.py
Executable file
@@ -0,0 +1,104 @@
|
||||
# Copyright 2014 Camptocamp SA (author: Guewen Baconnier)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from odoo.addons.sale_automatic_workflow.tests.common import TestCommon
|
||||
|
||||
from .common import TestAutomaticWorkflowStockMixin
|
||||
|
||||
|
||||
class TestAutomaticWorkflow(TestCommon, TestAutomaticWorkflowStockMixin):
|
||||
"""Test sale automatic workflow with stock."""
|
||||
|
||||
def test_01_full_automatic(self):
|
||||
workflow = self.create_full_automatic()
|
||||
sale = self.create_sale_order(workflow)
|
||||
self.assertEqual(sale.state, "draft")
|
||||
self.assertEqual(sale.workflow_process_id, workflow)
|
||||
self.run_job()
|
||||
self.assertEqual(sale.state, "sale")
|
||||
self.assertTrue(sale.picking_ids)
|
||||
self.assertTrue(sale.invoice_ids)
|
||||
invoice = sale.invoice_ids
|
||||
self.assertEqual(invoice.state, "posted")
|
||||
picking = sale.picking_ids
|
||||
self.run_job()
|
||||
self.assertEqual(picking.state, "done")
|
||||
|
||||
def test_02_compute_picking_policy(self):
|
||||
workflow = self.create_full_automatic()
|
||||
sale = self.create_sale_order(workflow)
|
||||
sale.workflow_process_id = workflow.id
|
||||
self.assertEqual(sale.picking_policy, "one")
|
||||
workflow2 = self.create_full_automatic(override={"picking_policy": "direct"})
|
||||
sale.workflow_process_id = workflow2.id
|
||||
self.assertEqual(sale.picking_policy, "direct")
|
||||
|
||||
def test_03_create_invoice_from_sale_order(self):
|
||||
workflow = self.create_full_automatic()
|
||||
sale = self.create_sale_order(workflow)
|
||||
line = sale.order_line[0]
|
||||
self.assertFalse(workflow.invoice_service_delivery)
|
||||
self.assertEqual(line.qty_delivered_method, "stock_move")
|
||||
self.assertEqual(line.qty_delivered, 0.0)
|
||||
# `_create_invoices` is already tested in `sale` module.
|
||||
# Make sure this addon works properly in regards to it.
|
||||
mock_path = "odoo.addons.sale.models.sale_order.SaleOrder._create_invoices"
|
||||
with mock.patch(mock_path) as mocked:
|
||||
sale._create_invoices()
|
||||
mocked.assert_called()
|
||||
self.assertEqual(line.qty_delivered, 0.0)
|
||||
|
||||
workflow.invoice_service_delivery = True
|
||||
line.qty_delivered_method = "manual"
|
||||
with mock.patch(mock_path) as mocked:
|
||||
sale._create_invoices()
|
||||
mocked.assert_called()
|
||||
self.assertEqual(line.qty_delivered, 1.0)
|
||||
sale.action_confirm()
|
||||
# Force the state to "full"
|
||||
# note : this is not needed if you have the module sale_delivery_state
|
||||
# installed but sale_automatic_workflow do not depend on it
|
||||
# so we just force it so we can check the sale.all_qty_delivered
|
||||
sale.delivery_status = "full"
|
||||
sale._compute_all_qty_delivered()
|
||||
self.assertTrue(sale.all_qty_delivered)
|
||||
|
||||
def test_04_invoice_from_picking_with_service_product(self):
|
||||
workflow = self.create_full_automatic()
|
||||
product_service = self.env["product.product"].create(
|
||||
{
|
||||
"name": "Remodeling Service",
|
||||
"categ_id": self.env.ref("product.product_category_3").id,
|
||||
"standard_price": 40.0,
|
||||
"list_price": 90.0,
|
||||
"type": "service",
|
||||
"uom_id": self.env.ref("uom.product_uom_hour").id,
|
||||
"uom_po_id": self.env.ref("uom.product_uom_hour").id,
|
||||
"description": "Example of product to invoice on order",
|
||||
"default_code": "PRE-PAID",
|
||||
"invoice_policy": "order",
|
||||
}
|
||||
)
|
||||
product_uom_hour = self.env.ref("uom.product_uom_hour")
|
||||
override = {
|
||||
"order_line": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": "Prepaid Consulting",
|
||||
"product_id": product_service.id,
|
||||
"product_uom_qty": 1,
|
||||
"product_uom": product_uom_hour.id,
|
||||
},
|
||||
)
|
||||
]
|
||||
}
|
||||
sale = self.create_sale_order(workflow, override=override)
|
||||
self.run_job()
|
||||
self.assertFalse(sale.picking_ids)
|
||||
self.assertTrue(sale.invoice_ids)
|
||||
invoice = sale.invoice_ids
|
||||
self.assertEqual(invoice.workflow_process_id, sale.workflow_process_id)
|
||||
95
sale_automatic_workflow_stock/tests/test_multicompany.py
Executable file
95
sale_automatic_workflow_stock/tests/test_multicompany.py
Executable file
@@ -0,0 +1,95 @@
|
||||
# Copyright 2017 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.tests import tagged
|
||||
|
||||
from odoo.addons.sale_automatic_workflow.tests.common import TestMultiCompanyCommon
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestMultiCompany(TestMultiCompanyCommon):
|
||||
"""Test stock related workflow with multi-company."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
"""Setup data for all test cases."""
|
||||
super().setUpClass()
|
||||
cls.auto_wkf.validate_picking = True
|
||||
|
||||
def create_auto_wkf_order(self, company, customer, product, qty):
|
||||
# We need to change to the proper company
|
||||
# to pick up correct company dependent fields
|
||||
SaleOrder = self.env["sale.order"].with_company(company)
|
||||
warehouse = self.env["stock.warehouse"].search(
|
||||
[("company_id", "=", company.id)], limit=1
|
||||
)
|
||||
|
||||
self.product_uom_unit = self.env.ref("uom.product_uom_unit")
|
||||
|
||||
order = SaleOrder.create(
|
||||
{
|
||||
"partner_id": customer.id,
|
||||
"company_id": company.id,
|
||||
"warehouse_id": warehouse.id,
|
||||
"workflow_process_id": self.auto_wkf.id,
|
||||
"order_line": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": product.name,
|
||||
"product_id": product.id,
|
||||
"price_unit": product.list_price,
|
||||
"product_uom_qty": qty,
|
||||
"product_uom": self.product_uom_unit.id,
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
return order
|
||||
|
||||
def test_sale_order_multicompany(self):
|
||||
self.env.user.company_id = self.env.ref("base.main_company")
|
||||
order_fr = self.create_auto_wkf_order(
|
||||
self.company_fr, self.customer_fr, self.product_fr, 5
|
||||
)
|
||||
order_ch = self.create_auto_wkf_order(
|
||||
self.company_ch, self.customer_ch, self.product_ch, 10
|
||||
)
|
||||
order_be = self.create_auto_wkf_order(
|
||||
self.company_be, self.customer_be, self.product_be, 10
|
||||
)
|
||||
order_fr_daughter = self.create_auto_wkf_order(
|
||||
self.company_fr_daughter,
|
||||
self.customer_fr_daughter,
|
||||
self.product_fr_daughter,
|
||||
4,
|
||||
)
|
||||
|
||||
self.assertEqual(order_fr.state, "draft")
|
||||
self.assertEqual(order_ch.state, "draft")
|
||||
self.assertEqual(order_be.state, "draft")
|
||||
self.assertEqual(order_fr_daughter.state, "draft")
|
||||
|
||||
self.env["automatic.workflow.job"].run()
|
||||
self.assertTrue(order_fr.picking_ids)
|
||||
self.assertTrue(order_ch.picking_ids)
|
||||
self.assertTrue(order_be.picking_ids)
|
||||
self.assertEqual(order_fr.picking_ids.state, "done")
|
||||
self.assertEqual(order_ch.picking_ids.state, "done")
|
||||
self.assertEqual(order_be.picking_ids.state, "done")
|
||||
invoice_fr = order_fr.invoice_ids
|
||||
invoice_ch = order_ch.invoice_ids
|
||||
invoice_be = order_be.invoice_ids
|
||||
invoice_fr_daughter = order_fr_daughter.invoice_ids
|
||||
self.assertEqual(invoice_fr.state, "posted")
|
||||
self.assertEqual(invoice_fr.journal_id.company_id, order_fr.company_id)
|
||||
self.assertEqual(invoice_ch.state, "posted")
|
||||
self.assertEqual(invoice_ch.journal_id.company_id, order_ch.company_id)
|
||||
self.assertEqual(invoice_be.state, "posted")
|
||||
self.assertEqual(invoice_be.journal_id.company_id, order_be.company_id)
|
||||
self.assertEqual(invoice_fr_daughter.state, "posted")
|
||||
self.assertEqual(
|
||||
invoice_fr_daughter.journal_id.company_id, order_fr_daughter.company_id
|
||||
)
|
||||
Reference in New Issue
Block a user