Search 1.9 billion lines of Odoo code on GitHub

product_supplier_info_helpers

Author: Numigi
License: no license
Branch: 11.0
Repository: Numigi/odoo-purchase-addons
Dependencies: product
Languages: Python (84, 100.0%)
Other branches: 12.0, 14.0, TA#49456, TA#50304, and qtip_20220127_1938

<h1 class="title">Product Supplier Info Helpers</h1> <p>This module adds helpers to manipulate product supplier info (supplier prices).</p> <div class="contents topic" id="table-of-contents"> <p class="topic-title first">Table of Contents</p> <ul class="simple"> <li><a class="reference internal" href="#context" id="id1">Context</a></li> <li><a class="reference internal" href="#usage" id="id2">Usage</a><ul> <li><a class="reference internal" href="#mapping-a-product-to-supplier-prices" id="id3">Mapping a Product to Supplier Prices</a></li> <li><a class="reference internal" href="#mapping-a-supplier-price-to-a-product" id="id4">Mapping a Supplier Price to a Product</a></li> </ul> </li> <li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li> </ul> </div> <a name="context"></a> <h2><a class="toc-backref" href="#id1">Context</a></h2> <p>In Odoo, a supplier price can be defined on a product template or on a variant.</p> <p>When implementing business logic related to supplier prices, it is sometimes required to map a product to its prices or the inverse.</p> <p>This is not a trivial task and can lead to subtile bugs.</p> <a name="usage"></a> <h2><a class="toc-backref" href="#id2">Usage</a></h2> <a name="mapping-a-product-to-supplier-prices"></a> <h3><a class="toc-backref" href="#id3">Mapping a Product to Supplier Prices</a></h3> <p>Mapping a product to its supplier prices is done with the function <code>get_supplier_info_from_product</code>.</p> <p>Here is an example with a purchase order line.</p> <pre> <code lang="python">from odoo.addons.product_supplier_info_helpers.helpers import get_supplier_info_from_product class PurchaseOrderLine(models.Model): _inherit = 'purchase.order.line' def some_business_logic(self): supplier_info = get_supplier_info_from_product(self.product_id) for info in supplier_info: ...</code> </pre> <a name="mapping-a-supplier-price-to-a-product"></a> <h3><a class="toc-backref" href="#id4">Mapping a Supplier Price to a Product</a></h3> <p>A use case of mapping a supplier price to a product is to trigger business logic when a price is updated.</p> <pre> <code lang="python">from odoo.addons.product_supplier_info_helpers.helpers import get_products_from_supplier_info class ProductSupplierInfo(models.Model): _inherit = 'product.supplier_info' &#64;api.multi def write(self, vals): super().write(vals) products = get_products_from_supplier_info(self) products.apply_some_business_logic() return True</code> </pre> <a name="contributors"></a> <h2><a class="toc-backref" href="#id5">Contributors</a></h2> <ul class="simple"> <li>Numigi (tm) and all its contributors (<a class="reference external" href="https://bit.ly/numigiens">https://bit.ly/numigiens</a>)</li> </ul>