[FIX] website_sale_aplicoop: align pricing and drafts
This commit is contained in:
parent
aef57a3de4
commit
a9c1f1f609
4 changed files with 258 additions and 533 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue