[FIX] website_sale_aplicoop: align pricing and drafts

This commit is contained in:
snt 2026-02-27 19:39:25 +01:00
parent aef57a3de4
commit a9c1f1f609
4 changed files with 258 additions and 533 deletions

View file

@ -16,6 +16,8 @@ Coverage:
from odoo.tests import tagged
from odoo.tests.common import TransactionCase
from ..controllers.website_sale import AplicoopWebsiteSale
@tagged("post_install", "-at_install")
class TestPricingWithPricelist(TransactionCase):
@ -49,6 +51,7 @@ class TestPricingWithPricelist(TransactionCase):
"company_ids": [(6, 0, [self.company.id])],
}
)
self.partner = self.user.partner_id
# Get or create default tax group
tax_group = self.env["account.tax.group"].search(
@ -161,6 +164,9 @@ class TestPricingWithPricelist(TransactionCase):
}
)
# Controller helper
self.controller = AplicoopWebsiteSale()
# Create group order
self.group_order = self.env["group.order"].create(
{
@ -493,3 +499,52 @@ class TestPricingWithPricelist(TransactionCase):
except Exception:
# If it raises, that's also acceptable behavior
self.assertTrue(True, "Negative quantity properly rejected")
def test_pricing_helper_uses_config_pricelist_and_taxes(self):
"""Pricing helper must apply configured pricelist and include taxes for display."""
website = self.env.ref("website.default_website").sudo()
website.write(
{
"show_line_subtotals_tax_selection": "tax_included",
"company_id": self.company.id,
}
)
pricelist_discount = self.env["product.pricelist"].create(
{
"name": "Config Pricelist 10%",
"company_id": self.company.id,
"item_ids": [
(
0,
0,
{
"compute_price": "percentage",
"percent_price": 10.0,
"applied_on": "3_global",
},
)
],
}
)
self.env["ir.config_parameter"].sudo().set_param(
"website_sale_aplicoop.pricelist_id", pricelist_discount.id
)
product = self.product_with_tax # 100€ + 21%
pricing = self.controller._get_pricing_info(
product,
pricelist_discount,
quantity=1.0,
partner=self.partner,
)
# price_unit uses pricelist (10% discount)
self.assertAlmostEqual(pricing["price_unit"], 90.0, places=2)
# display price must include taxes (21% on discounted price)
self.assertAlmostEqual(pricing["price"], 108.9, places=2)
self.assertTrue(pricing.get("tax_included"))
self.assertTrue(pricing.get("has_discounted_price"))

View file

@ -16,6 +16,8 @@ from datetime import timedelta
from odoo.tests.common import TransactionCase
from ..controllers.website_sale import AplicoopWebsiteSale
class TestSaveOrderEndpoints(TransactionCase):
"""Test suite for order-saving endpoints."""
@ -94,6 +96,51 @@ class TestSaveOrderEndpoints(TransactionCase):
# Associate product with group order
self.group_order.product_ids = [(4, self.product.id)]
# Helper: controller instance for pure helpers
self.controller = AplicoopWebsiteSale()
def _build_line(self, product, qty, price):
return (
0,
0,
{"product_id": product.id, "product_uom_qty": qty, "price_unit": price},
)
def test_merge_or_replace_replaces_existing_draft(self):
"""Existing draft must be replaced (not merged) with new lines."""
# Existing draft with one line
existing = self.env["sale.order"].create(
{
"partner_id": self.member_partner.id,
"group_order_id": self.group_order.id,
"pickup_day": self.group_order.pickup_day,
"pickup_date": self.group_order.pickup_date,
"home_delivery": self.group_order.home_delivery,
"order_line": [self._build_line(self.product, 1, 10.0)],
"state": "draft",
}
)
new_lines = [self._build_line(self.product, 3, 99.0)]
result = self.controller._merge_or_replace_draft(
self.group_order,
self.user,
new_lines,
existing,
self.group_order.id,
)
self.assertEqual(result.id, existing.id, "Should reuse existing draft")
self.assertEqual(len(result.order_line), 1, "Only one line should remain")
self.assertEqual(
result.order_line[0].product_uom_qty, 3, "Quantity must be replaced"
)
self.assertEqual(
result.order_line[0].price_unit, 99.0, "Price must be replaced"
)
def test_save_eskaera_draft_creates_order_with_group_order_id(self):
"""
Test that save_eskaera_draft() creates a sale.order with group_order_id.