====================================
Product Sale Price from Pricelist
====================================

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
    :target: https://odoo-community.org/page/development-status
    :alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
    :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
    :alt: License: AGPL-3

|badge1| |badge2|

This module automatically calculates and updates product sale prices based on the last purchase price and configurable pricelists.

**Key Features:**

* **Automatic Price Calculation**: Set sale prices based on last purchase price and a configured pricelist
* **Flexible Discount Handling**: Choose how to apply discounts to the cost:

  * Without discounts
  * First discount only
  * Double discount
  * Triple discount
  * Manual update

* **Tax-Aware Pricing**: Automatically includes tax calculations in pricing
* **UoM Conversion**: Handles different purchase and sale units of measure
* **Batch Updates**: Update theoretical prices for multiple products
* **Product Flags**: Mark products for price updates and track status
* **Variant Architecture**: All business logic in product.product for proper pricelist handling
* **Sales Orders Update**: Action/button to sync sale order lines (not invoiced) with current product sale price

**Table of contents**

.. contents::
   :local:

Installation
============

To install this module, you need to:

#. Ensure dependencies are installed (product, purchase, sale)
#. Update the Apps list
#. Search for "Product Sale Price from Pricelist"
#. Click Install

Configuration
=============

To configure this module, you need to:

**Global Configuration:**

#. Go to Settings → Sales → Automatic Price Configuration
#. Select the pricelist for automatic price calculation
#. Save settings

**Per Product Configuration:**

#. Go to Products → Products
#. Open a product form
#. Configure:

   * **Last purchase price**: Cost at which the product was last purchased
   * **Last purchase price calculation type**: Choose how to apply discounts

     * Without Discounts: Uses base purchase price
     * First Discount: Applies only the first discount
     * Double Discount: Applies first and second discount
     * Triple Discount: Applies first, second, and third discount
     * Manual Update: Price must be set manually

   * **Last purchase price updated**: Mark when prices need review

**Important Notes:**

* Ensure products have taxes configured (required for price calculation)
* Set calculation type to anything except "manual_update" for automatic pricing

Usage
=====

**Automatic Price Updates:**

#. Products are priced automatically when received from purchase orders
#. System updates the **last_purchase_price** field automatically
#. Sale price is calculated from the configured pricelist using the cost price
#. Taxes are automatically applied based on product tax settings

**Manual Price Updates:**

#. Go to Products → Update Theoretical Prices
#. Select products to update
#. System recalculates theoretical prices based on current settings
#. Review and apply changes

**Update Sales Orders from List Price:**

#. Go to Sales → Orders (form or list) and use **Update with List Price**
#. Only orders not invoiced/canceled are processed
#. The action copies current product sale price to normal lines (skipping notes and downpayments) and keeps discounts

**Price Calculation Flow:**

#. Purchase order is received
#. System extracts cost from purchase line (with configured discount handling)
#. Applies configured pricelist rules
#. Calculates taxes
#. Updates theoretical price
#. Optionally auto-updates sale price (list_price)

**Monitoring:**

* Use **Last purchase price updated** flag to track products needing review
* Filter products by calculation type to manage different pricing strategies
* Review **list_price_theoritical** vs **list_price** to see proposed vs actual prices

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/Criptomart/addons-cm/issues>`_.
In case of trouble, please check there if your issue has already been reported.

Credits
=======

Authors
~~~~~~~

* Criptomart

Funding
~~~~~~~

* Elika Bilbo

Contributors
~~~~~~~~~~~~

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

  * Main development and implementation
  * Architecture design for product variant handling

Other credits
~~~~~~~~~~~~~

This module integrates with the OCA product ecosystem and follows best practices for:

* Product variant architecture (business logic in product.product)
* Pricelist compatibility
* Tax-aware pricing calculations
* UoM conversions

Maintainers
~~~~~~~~~~~

This module is maintained by Criptomart.

.. image:: https://odoo-community.org/logo.png
   :alt: Odoo Community Association
   :target: https://odoo-community.org

This module is part of the `Criptomart/addons-cm <https://github.com/Criptomart/addons-cm/tree/18.0/product_sale_price_from_pricelist>`_ project on GitHub.
