addons-cm/website_sale_aplicoop
GitHub Copilot 1d6747e703 [IMP] website_sale_aplicoop: filter and cap stock using forecasted net qty
Group orders are not confirmed until the cutoff date, so draft/sent
sale.order lines never generate stock.moves and are invisible to
virtual_available. This change makes the shop aware of that demand.

- group.order._compute_draft_sale_demand: queries sale.order.line in
  draft/sent state (mirroring sale_stock forecasted report logic) and
  returns pending demand per product.id in the product's own UoM.
- _get_products_for_group_order: delegates to new _apply_stock_filter_and_sort
  which excludes storable products whose forecasted net qty
  (virtual_available − draft demand) <= 0, unless allow_out_of_stock_order.
- _compute_stock_ribbons: reads draft_demand_by_product from ORM context
  so is_out_of_stock / is_low_stock / dynamic_ribbon_id reflect net qty.
- Controller: new _prepare_draft_stock_data helper calculates demand once
  per request, injects context, and builds product_max_qty dict. Applied
  in eskaera_shop, load_eskaera_page and load_products_ajax.
- Template: qty input gets max and data-max-qty from product_max_qty.
- JS: blocks add-to-cart if requested quantity exceeds data-max-qty.
- Fixes type check: type=='consu' → is_storable=True (Odoo 18 semantics).
- 21 new tests in test_forecasted_stock.py covering demand calculation,
  ribbon logic with context, and group order filtering.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-12 18:18:40 +02:00
..
controllers [IMP] website_sale_aplicoop: filter and cap stock using forecasted net qty 2026-06-12 18:18:40 +02:00
data [IMP] website_sale_aplicoop: render user-defined website_sale ribbon alongside stock ribbon 2026-05-29 18:11:47 +02:00
demo demo files 2026-02-27 13:43:56 +01:00
i18n Save Draft transation 2026-05-28 13:53:00 +02:00
migrations lint: fix linter warnings (log exceptions, disable attribute-string-redundant, suppress C901 where necessary) 2026-05-20 16:05:14 +02:00
models [IMP] website_sale_aplicoop: filter and cap stock using forecasted net qty 2026-06-12 18:18:40 +02:00
readme [DOC] Actualizar documentación a estándares OCA y preparar logo CriptoMart 2026-02-21 19:55:57 +01:00
security [IMP] website_sale_aplicoop: mostrar franjas de recogida en formulario group.order 2026-05-20 17:06:38 +02:00
static [IMP] website_sale_aplicoop: filter and cap stock using forecasted net qty 2026-06-12 18:18:40 +02:00
tests [IMP] website_sale_aplicoop: filter and cap stock using forecasted net qty 2026-06-12 18:18:40 +02:00
views [IMP] website_sale_aplicoop: filter and cap stock using forecasted net qty 2026-06-12 18:18:40 +02:00
.codeclimate.yml [FIX] website_sale_aplicoop: Remove redundant string= attributes and fix OCA linting warnings 2026-02-18 17:54:43 +01:00
.editorconfig Aplicoop desde el repo de kidekoop 2026-02-11 15:32:11 +01:00
.gitignore Aplicoop desde el repo de kidekoop 2026-02-11 15:32:11 +01:00
.pre-commit-config.yaml [FIX] website_sale_aplicoop: Remove redundant string= attributes and fix OCA linting warnings 2026-02-18 17:54:43 +01:00
__init__.py Aplicoop desde el repo de kidekoop 2026-02-11 15:32:11 +01:00
__manifest__.py [FIX] website_sale_aplicoop: split cart and cycle stamp in localStorage 2026-06-06 15:37:55 +02:00
CHANGELOG.md [DOC] actualizar y sincronizar documentación de todos los addons 2026-05-20 16:27:17 +02:00
LICENSE.txt Aplicoop desde el repo de kidekoop 2026-02-11 15:32:11 +01:00
README.rst [IMP] website_sale_aplicoop: disable standard website_sale cart — hide header cart, remove add-to-cart, redirect cart routes to /eskaera 2026-05-20 16:05:14 +02:00
README_DEV.md [DOC] actualizar y sincronizar documentación de todos los addons 2026-05-20 16:27:17 +02:00
setup.py [FIX] website_sale_aplicoop: Remove redundant string= attributes and fix OCA linting warnings 2026-02-18 17:54:43 +01:00

========================
Website Sale - Aplicoop
========================

.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg
   :target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
   :alt: License: AGPL-3
.. image:: https://img.shields.io/badge/Python-3.9%2B-blue
   :alt: Python: 3.9+
.. image:: https://img.shields.io/badge/Odoo-18.0-blue
   :alt: Odoo: 18.0

**Website Sale - Aplicoop** is a modern Odoo 18 module that replaces the legacy Aplicoop application with a complete solution for managing collaborative consumption group orders (*eskaera* in Basque).

Description
===========

This module replaces the legacy Aplicoop application with a modern, scalable solution for managing collaborative consumption group orders (*eskaera* in Basque) within Odoo's standard website sales framework.

Features
~~~~~~~~

- **Group Order Management**: Create and manage group orders (eskaera) with customizable state transitions (draft → open → closed/cancelled)
- **Weekly Activity Filtering**: Automatically filter active orders for the current week based on start/end dates and time windows
- **Flexible Scheduling**: Support for optional start/end times to define order availability windows within a day
- **Cutoff Day Support**: Define weekly cutoff days for group orders to control when purchases can be made
- **Product Association**: Link products to specific group orders through Many2many relationships
- **Partner Group Association**: Link partners (users) to groups via Many2many relationships for group-based shopping
- **i18n Support**: Full internationalization with translations for 7 languages (Spanish, French, Catalan, Basque, Galician, Italian, Portuguese)
- **OCA Compliant**: AGPL-3.0 licensed, follows OCA standards for documentation, testing, and code structure

Context / Use Cases
===================

Group orders (*eskaera*) are a business model for collaborative consumption where groups of users collectively purchase products within defined time windows. This module was created to replace the legacy Aplicoop application, providing:

**Business Value:**

- Streamlined group purchasing workflows within Odoo's standard sales framework
- Flexible scheduling to accommodate different group shopping patterns (daily, weekly, biweekly, monthly)
- Clear separation between temporary shopping carts and permanent sales orders
- Support for multiple groups with different suppliers, products, and categories

**Use Cases:**

- Cooperative grocery purchasing groups
- Bulk order consolidation for community members
- Time-limited promotional campaigns with group participation
- Multi-location organizations with shared procurement

Usage
=====

Creating a Group Order
~~~~~~~~~~~~~~~~~~~~~~

1. Go to **Website Sale > Group Orders > Create**
2. Fill in the order details:

   - **Order Name**: Descriptive name (e.g., "Weekly Vegetable Order")
   - **Start Date**: When the order opens for shopping (mandatory)
   - **End Date**: When the order closes (optional; leave empty for permanent orders)
   - **Cutoff Day**: Day of week when purchases stop (0=Monday, 6=Sunday) - mandatory
   - **Start Time**: Optional time when order becomes active (0-24 hours)
   - **End Time**: Optional time when order closes (0-24 hours)
   - **Recurrence Period**: How often the order repeats (daily, weekly, biweekly, monthly)
   - **Suppliers**: Link to product suppliers
   - **Categories**: Product categories available in this order
   - **Groups**: Which user groups can participate

3. Click **Save** and transition the order to **Open** state to allow shopping

Shopping for a Group Order
~~~~~~~~~~~~~~~~~~~~~~~~~~~

1. Navigate to the website storefront at ``/eskaera`` (group orders page)
2. View active group orders for your participating groups
3. Select an order to view available products
4. Add products to your cart (separate cart per order)
5. At checkout, confirm your order to convert items to a sales order draft
6. Proceed through standard Odoo checkout workflow

Configuration
~~~~~~~~~~~~~~

**Managing Groups**

1. Go to **Contacts > Groups** (res.partner with is_group=True)
2. Create groups for user communities
3. Add partners/users to groups via the **Members** tab

**Managing Products**

1. Products are linked to group orders via the **Group Orders** field in product settings
2. Set pricing and availability per group order
3. Assign products to categories used in group orders

**Date & Time Validation**

- ``start_date`` must be ≤ ``end_date`` (when both filled)
- ``start_time`` must be < ``end_time`` (when both filled)
- Times must be between 0-24 hours
- Empty end_date = permanent order
- Empty times = no time-based restrictions

Credits
=======

This module was developed by Criptomart in 2025 as a modernization of the Aplicoop application, integrating collaborative consumption group order management directly into Odoo's website sales framework.

The implementation follows OCA standards for:

- Code quality and testing (26 passing tests)
- Documentation structure and multilingual support
- Security and access control
- API design for extensibility

Authors
=======

* Criptomart

Funding
=======

* Elika Bilbo

Contributors
============

* `Criptomart <https://criptomart.net>`_:

  * Project lead and main development
  * Architecture and implementation

**Historical References:**

This module was inspired by the original **Aplicoop** project:

* https://sourceforge.net/projects/aplicoop/
* Original creators: Ekaitz Mendiluze, Joseba Legarreta, and other contributors

The original Aplicoop project served as a pioneering solution for collaborative consumption group orders, and this module brings its functionality to the modern Odoo platform.

Notes - Shop behaves as a simple catalog
=========================================

Starting with the recent update, this module converts the default Odoo
``/shop`` storefront into a simple product catalog (no standard ``website_sale``
shopping cart). The change is intentional for sites that use the Aplicoop
"eskaera" flow as the single shopping experience.

What the module does
---------------------

- Hides the standard header cart link and badge.
- Removes the "Add to cart" quick-add area from product listings.
- Redirects standard cart endpoints to the group-order flow (``/eskaera``):
   ``/shop/cart``, ``/shop/cart/update``, ``/shop/cart/update_json``, ``/shop/cart_quantity``.

Files involved
--------------

- ``views/website_sale_disable_cart.xml`` — templates that hide/remove cart UI
- ``controllers/website_sale.py`` — routes that redirect cart endpoints to ``/eskaera``
- ``__manifest__.py`` — includes the new view file

How to apply or revert
-----------------------

To apply the change (already applied when the module is installed/updated):

::

      docker-compose run --rm odoo odoo -d odoo -u website_sale_aplicoop --stop-after-init
      docker-compose up -d

To revert back to the standard ``website_sale`` behaviour:

1. Remove ``views/website_sale_disable_cart.xml`` from the ``data`` section in
    ``__manifest__.py``.
2. Update the module:

::

      docker-compose run --rm odoo odoo -d odoo -u website_sale_aplicoop --stop-after-init

Note: Reverting may expose standard cart UI and routes; ensure your site
content and workflows are adapted accordingly.