Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
2
sale_automatic_workflow/tests/__init__.py
Executable file
2
sale_automatic_workflow/tests/__init__.py
Executable file
@@ -0,0 +1,2 @@
|
||||
from . import test_automatic_workflow
|
||||
from . import test_multicompany
|
||||
194
sale_automatic_workflow/tests/common.py
Executable file
194
sale_automatic_workflow/tests/common.py
Executable file
@@ -0,0 +1,194 @@
|
||||
# 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.tests import tagged
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
|
||||
|
||||
|
||||
class TestCommon(TransactionCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
||||
|
||||
|
||||
class TestAutomaticWorkflowMixin:
|
||||
def create_sale_order(
|
||||
self, workflow, override=None, product_type="consu", extra_product_values=None
|
||||
):
|
||||
sale_obj = self.env["sale.order"]
|
||||
|
||||
partner_values = {"name": "Imperator Caius Julius Caesar Divus"}
|
||||
partner = self.env["res.partner"].create(partner_values)
|
||||
|
||||
extra_product_values = extra_product_values or {}
|
||||
product_values = {
|
||||
"name": "Bread",
|
||||
"list_price": 5,
|
||||
"type": product_type,
|
||||
**extra_product_values,
|
||||
}
|
||||
product = self.env["product.product"].create(product_values)
|
||||
self.product_uom_unit = self.env.ref("uom.product_uom_unit")
|
||||
values = {
|
||||
"partner_id": partner.id,
|
||||
"order_line": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": product.name,
|
||||
"product_id": product.id,
|
||||
"product_uom": self.product_uom_unit.id,
|
||||
"price_unit": product.list_price,
|
||||
"product_uom_qty": 1,
|
||||
},
|
||||
)
|
||||
],
|
||||
"workflow_process_id": workflow.id,
|
||||
}
|
||||
if override:
|
||||
values.update(override)
|
||||
return sale_obj.create(values)
|
||||
|
||||
def create_full_automatic(self, override=None):
|
||||
workflow_obj = self.env["sale.workflow.process"]
|
||||
values = workflow_obj.create(
|
||||
{
|
||||
"name": "Full Automatic",
|
||||
"validate_order": True,
|
||||
"create_invoice": True,
|
||||
"validate_invoice": True,
|
||||
"invoice_date_is_order_date": True,
|
||||
}
|
||||
)
|
||||
if override:
|
||||
values.update(override)
|
||||
return values
|
||||
|
||||
def run_job(self):
|
||||
self.env["automatic.workflow.job"].run()
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestMultiCompanyCommon(AccountTestInvoicingCommon):
|
||||
@classmethod
|
||||
def create_product(cls, values):
|
||||
values.update({"type": "consu", "invoice_policy": "order"})
|
||||
product_template = cls.env["product.template"].create(values)
|
||||
return product_template.product_variant_id
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls, chart_template_ref=None):
|
||||
super().setUpClass()
|
||||
cls.env = cls.env(
|
||||
context=dict(
|
||||
cls.env.context,
|
||||
tracking_disable=True,
|
||||
# Compatibility with sale_automatic_workflow_job: even if
|
||||
# the module is installed, ensure we don't delay a job.
|
||||
# Thus, we test the usual flow.
|
||||
queue_job__no_delay=True,
|
||||
)
|
||||
)
|
||||
cls.company_fr = cls.setup_other_company(
|
||||
name="French company",
|
||||
currency_id=cls.env.ref("base.EUR").id,
|
||||
country_id=cls.env.ref("base.fr").id,
|
||||
)["company"]
|
||||
|
||||
cls.company_ch = cls.setup_other_company(
|
||||
name="Swiss company",
|
||||
currency_id=cls.env.ref("base.CHF").id,
|
||||
country_id=cls.env.ref("base.ch").id,
|
||||
)["company"]
|
||||
|
||||
cls.company_be = cls.setup_other_company(
|
||||
name="Belgian company",
|
||||
currency_id=cls.env.ref("base.EUR").id,
|
||||
country_id=cls.env.ref("base.be").id,
|
||||
)["company"]
|
||||
|
||||
cls.company_fr_daughter = cls.setup_other_company(
|
||||
name="French company daughter",
|
||||
currency_id=cls.env.ref("base.EUR").id,
|
||||
country_id=cls.env.ref("base.fr").id,
|
||||
)["company"]
|
||||
|
||||
cls.env.user.company_ids |= cls.company_fr
|
||||
cls.env.user.company_ids |= cls.company_ch
|
||||
cls.env.user.company_ids |= cls.company_be
|
||||
cls.env.user.company_ids |= cls.company_fr_daughter
|
||||
|
||||
cls.env.user.company_id = cls.company_fr.id
|
||||
cls.customer_fr = (
|
||||
cls.env["res.partner"]
|
||||
.with_context(default_company_id=cls.company_fr.id)
|
||||
.create({"name": "Customer FR"})
|
||||
)
|
||||
cls.product_fr = cls.create_product({"name": "Evian bottle", "list_price": 2.0})
|
||||
|
||||
cls.env.user.company_id = cls.company_ch.id
|
||||
|
||||
cls.customer_ch = cls.env["res.partner"].create({"name": "Customer CH"})
|
||||
cls.product_ch = cls.create_product(
|
||||
{"name": "Henniez bottle", "list_price": 3.0}
|
||||
)
|
||||
|
||||
cls.env.user.company_id = cls.company_be.id
|
||||
cls.customer_be = cls.env["res.partner"].create({"name": "Customer BE"})
|
||||
cls.product_be = (
|
||||
cls.env["product.template"]
|
||||
.create(
|
||||
{
|
||||
"name": "SPA bottle",
|
||||
"list_price": 1.5,
|
||||
"type": "consu",
|
||||
"invoice_policy": "order",
|
||||
}
|
||||
)
|
||||
.product_variant_id
|
||||
)
|
||||
|
||||
cls.env.user.company_id = cls.company_fr_daughter.id
|
||||
cls.customer_fr_daughter = cls.env["res.partner"].create(
|
||||
{"name": "Customer FR Daughter"}
|
||||
)
|
||||
cls.product_fr_daughter = cls.create_product(
|
||||
{"name": "Contrex bottle", "list_price": 1.5}
|
||||
)
|
||||
|
||||
cls.auto_wkf = cls.env.ref("sale_automatic_workflow.automatic_validation")
|
||||
cls.env.user.company_id = cls.env.ref("base.main_company")
|
||||
|
||||
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)
|
||||
|
||||
self.product_uom_unit = self.env.ref("uom.product_uom_unit")
|
||||
|
||||
order = SaleOrder.create(
|
||||
{
|
||||
"partner_id": customer.id,
|
||||
"company_id": company.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
|
||||
218
sale_automatic_workflow/tests/test_automatic_workflow.py
Executable file
218
sale_automatic_workflow/tests/test_automatic_workflow.py
Executable file
@@ -0,0 +1,218 @@
|
||||
# Copyright 2014 Camptocamp SA (author: Guewen Baconnier)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from datetime import timedelta
|
||||
from unittest import mock
|
||||
|
||||
from freezegun import freeze_time
|
||||
|
||||
from odoo import fields
|
||||
from odoo.tests import tagged
|
||||
|
||||
from .common import TestAutomaticWorkflowMixin, TestCommon
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestAutomaticWorkflow(TestCommon, TestAutomaticWorkflowMixin):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.env = self.env(
|
||||
context=dict(
|
||||
self.env.context,
|
||||
tracking_disable=True,
|
||||
# Compatibility with sale_automatic_workflow_job: even if
|
||||
# the module is installed, ensure we don't delay a job.
|
||||
# Thus, we test the usual flow.
|
||||
queue_job__no_delay=True,
|
||||
)
|
||||
)
|
||||
|
||||
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.invoice_ids)
|
||||
invoice = sale.invoice_ids
|
||||
self.assertEqual(invoice.state, "posted")
|
||||
|
||||
def test_02_onchange(self):
|
||||
team_1 = self.env.ref("sales_team.crm_team_1")
|
||||
team_2 = self.env.ref("sales_team.team_sales_department")
|
||||
workflow = self.create_full_automatic(override={"team_id": team_1.id})
|
||||
sale = self.create_sale_order(workflow)
|
||||
self.assertEqual(sale.team_id, team_1)
|
||||
workflow2 = self.create_full_automatic(override={"team_id": team_2.id})
|
||||
sale.workflow_process_id = workflow2.id
|
||||
self.assertEqual(sale.team_id, team_2)
|
||||
|
||||
@freeze_time("2025-1-1")
|
||||
def test_03_date_invoice_from_sale_order(self):
|
||||
workflow = self.create_full_automatic()
|
||||
# date_order on sale.order is date + time
|
||||
# invoice_date on account.move is date only
|
||||
last_week_time = fields.Datetime.now() - timedelta(days=7)
|
||||
override = {"date_order": last_week_time}
|
||||
sale = self.create_sale_order(workflow, override=override)
|
||||
self.assertEqual(sale.date_order, last_week_time)
|
||||
self.run_job()
|
||||
self.assertTrue(sale.invoice_ids)
|
||||
invoice = sale.invoice_ids
|
||||
self.assertEqual(invoice.invoice_date, last_week_time.date())
|
||||
self.assertEqual(invoice.workflow_process_id, sale.workflow_process_id)
|
||||
|
||||
def test_04_create_invoice_from_sale_order(self):
|
||||
workflow = self.create_full_automatic()
|
||||
sale = self.create_sale_order(workflow)
|
||||
line = sale.order_line[0]
|
||||
# Make sure this addon works properly in regards to it.
|
||||
mock_path = "odoo.addons.sale.models.sale_order.SaleOrder._create_invoices"
|
||||
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)
|
||||
|
||||
def test_05_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.assertTrue(sale.invoice_ids)
|
||||
invoice = sale.invoice_ids
|
||||
self.assertEqual(invoice.workflow_process_id, sale.workflow_process_id)
|
||||
|
||||
def test_06_journal_on_invoice(self):
|
||||
sale_journal = self.env["account.journal"].search(
|
||||
[("type", "=", "sale")], limit=1
|
||||
)
|
||||
new_sale_journal = self.env["account.journal"].create(
|
||||
{"name": "TTSA", "code": "TTSA", "type": "sale"}
|
||||
)
|
||||
|
||||
workflow = self.create_full_automatic()
|
||||
sale = self.create_sale_order(workflow)
|
||||
self.run_job()
|
||||
self.assertTrue(sale.invoice_ids)
|
||||
invoice = sale.invoice_ids
|
||||
self.assertEqual(invoice.journal_id.id, sale_journal.id)
|
||||
|
||||
workflow = self.create_full_automatic(
|
||||
override={"property_journal_id": new_sale_journal.id}
|
||||
)
|
||||
sale = self.create_sale_order(workflow)
|
||||
self.run_job()
|
||||
self.assertTrue(sale.invoice_ids)
|
||||
invoice = sale.invoice_ids
|
||||
self.assertEqual(invoice.journal_id.id, new_sale_journal.id)
|
||||
|
||||
def test_no_copy(self):
|
||||
workflow = self.create_full_automatic()
|
||||
sale = self.create_sale_order(workflow)
|
||||
self.run_job()
|
||||
invoice = sale.invoice_ids
|
||||
self.assertTrue(sale.workflow_process_id)
|
||||
self.assertTrue(invoice.workflow_process_id)
|
||||
sale2 = sale.copy()
|
||||
invoice2 = invoice.copy()
|
||||
self.assertFalse(sale2.workflow_process_id)
|
||||
self.assertFalse(invoice2.workflow_process_id)
|
||||
|
||||
def test_automatic_sale_order_confirmation_mail(self):
|
||||
workflow = self.create_full_automatic()
|
||||
workflow.send_order_confirmation_mail = True
|
||||
sale = self.create_sale_order(workflow)
|
||||
previous_message_ids = sale.message_ids
|
||||
self.run_job()
|
||||
self.assertEqual(sale.state, "sale")
|
||||
new_messages = self.env["mail.message"].search(
|
||||
[
|
||||
("id", "in", sale.message_ids.ids),
|
||||
("id", "not in", previous_message_ids.ids),
|
||||
]
|
||||
)
|
||||
self.assertTrue(
|
||||
new_messages.filtered(
|
||||
lambda x: x.subtype_id == self.env.ref("mail.mt_comment")
|
||||
)
|
||||
)
|
||||
|
||||
def test_create_payment_with_invoice_currency_id(self):
|
||||
workflow = self.create_full_automatic()
|
||||
pricelist_id = self.env["product.pricelist"].create(
|
||||
{
|
||||
"name": "default_pricelist",
|
||||
"currency_id": 1,
|
||||
}
|
||||
)
|
||||
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 = {
|
||||
"pricelist_id": pricelist_id.id,
|
||||
"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.assertTrue(sale.invoice_ids)
|
||||
invoice = sale.invoice_ids
|
||||
self.assertEqual(invoice.state, "posted")
|
||||
payment_id = self.env["automatic.workflow.job"]._register_payment_invoice(
|
||||
invoice
|
||||
)
|
||||
self.assertTrue(payment_id)
|
||||
self.assertEqual(invoice.currency_id.id, payment_id.currency_id.id)
|
||||
49
sale_automatic_workflow/tests/test_multicompany.py
Executable file
49
sale_automatic_workflow/tests/test_multicompany.py
Executable file
@@ -0,0 +1,49 @@
|
||||
# Copyright 2017 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo.tests import tagged
|
||||
|
||||
from .common import TestMultiCompanyCommon
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestMultiCompany(TestMultiCompanyCommon):
|
||||
"""Class to test sale automated workflow with multi-company."""
|
||||
|
||||
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()
|
||||
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